12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- const path = require('path');
- const {isNullES} = require('js-fast-way');
- const fs = require('fs');
- const buildName = process.argv[2]
- const local = process.argv[3]
- const currentDirectory = process.cwd();
- console.log(`----------------------------`)
- console.log(`正在处理编译打包前的准备...`)
- console.log(`更新版本更新信息...`)
- const versionPath = path.join(currentDirectory, '/public/version.json');
- const versionContent = fs.readFileSync(versionPath, 'utf8');
- const versionJson = JSON.parse(versionContent);
- versionJson.value = dateFormat(new Date());
- fs.writeFileSync(versionPath, JSON.stringify(versionJson, null, 2));
- console.log(`----------------------------`)
- console.log(`正在删除上次打包相关的文件...`)
- const distZipPath = path.join(currentDirectory, `/zip/${buildName}`);
- if(fs.existsSync(distZipPath)) {
- fs.unlinkSync(distZipPath);
- }
- console.log(`获取当前的配置文件...`)
- const indexJsonPath = path.join(currentDirectory, 'src/config/index.json');
- const indexJsonContent = fs.readFileSync(indexJsonPath, 'utf8');
- console.log(`检测上次打包异常中断的缓存文件是否存在...`)
- const cacheFilePath = path.join(currentDirectory, 'scripts/cache.json');
- if(!fs.existsSync(cacheFilePath)) {
-
- console.log(`创建配置缓存文件...`)
- const cacheJsonPath = path.join(currentDirectory, 'scripts/cache.json');
- fs.writeFileSync(cacheJsonPath, indexJsonContent, 'utf8');
- }
- const indexJson = JSON.parse(indexJsonContent);
- indexJson.version = dateFormat(new Date());
- indexJson.target = "http://127.0.0.1:8090";
- if (isNullES(local) || local === 'undefined') {
- indexJson.socket = "wss://measure.hczcxx.cn/websocket";
- indexJson.localModel = false;
- } else {
- indexJson.socket = "";
- indexJson.localModel = true;
- }
- indexJson.smsPhone = "";
- indexJson.vite = {};
- console.log(`修改配置文件为生产环境的配置...`)
- fs.writeFileSync(indexJsonPath, JSON.stringify(indexJson, null, 2));
- function dateFormat(date) {
- let format = 'yyyyMMddhhmmss';
- let o = {
- "M+": date.getMonth() + 1,
- "d+": date.getDate(),
- "h+": date.getHours(),
- "m+": date.getMinutes(),
- "s+": date.getSeconds(),
- "q+": Math.floor((date.getMonth() + 3) / 3),
- "S": date.getMilliseconds()
- }
- if (/(y+)/.test(format)) {
- format = format.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
- }
- for (let k in o) {
- if (new RegExp("(" + k + ")").test(format)) {
- format = format.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
- }
- }
- return format;
- }
|