Commit 81d7535b authored by 前端-许佳敏's avatar 前端-许佳敏

chore: 优化构建,加入初始化脚本,避免初始化时缺少文件

parent 2b3c0332
......@@ -35,7 +35,7 @@
"build:v2scm": "cross-env PRO_ENV=v2scm yarn build",
"build:v2-demo": "cross-env PRO_ENV=v2-demo yarn build",
"build:v2Test": "cross-env SITE_ID=1 BACK_GATEWAY=http://lx-pre-gateway.shushangyun.com USE_ROUTE_CONFIG=false SOCKET_URL=ws://lx-pre-gateway.shushangyun.com yarn build",
"postinstall": "umi generate tmp",
"postinstall": "node ./scripts/init && umi generate tmp",
"prettier": "prettier --write '**/*.{js,jsx,tsx,ts,less,md,json}'",
"test": "umi-test",
"test:coverage": "umi-test --coverage",
......@@ -81,6 +81,7 @@
"antd-dayjs-webpack-plugin": "^1.0.6",
"antd-img-crop": "^3.12.0",
"babel-plugin-lodash": "^3.3.4",
"babel-plugin-yapi-import": "1.0.4",
"bignumber.js": "^9.0.1",
"bizcharts": "^4.1.10",
"braft-editor": "^2.3.9",
......
const fs = require('fs');
const path = require('path');
/**
* 用于新项目启动时缺少必要文件, 做的初始化脚本
*/
const cwd = process.cwd();
async function init() {
try {
await ensureFile(cwdPath('config/base.config.json'), '{}');
await ensureFile(cwdPath('config/router.config.json'), '[]');
await ensureFile(cwdPath('yapi_hashmaps.json'), '{}');
} catch (error) {
console.log(error);
process.exit(1);
}
}
/**
* 判断文件是否存在,如果不存在则创建,并写入对应初始值
*/
async function ensureFile(pathFile, defaultData) {
return new Promise((resolve, reject) => {
fs.open(pathFile, 'wx', function(err) {
if (err) {
if (err.code === 'EEXIST') {
resolve()
}
reject(err)
return ;
}
fs.writeFile(pathFile, defaultData, function(err) {
if (err) {
console.error(`初始化${pathFile}失败`);
reject(err);
}
console.log(`初始化${pathFile}成功`);
resolve(defaultData);
});
return;
});
});
}
function cwdPath(filePath) {
return path.resolve(cwd, filePath);
}
init();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment