crootfast
Version:
大前端工程化命令行脚手架
71 lines (58 loc) • 2.18 kB
JavaScript
const { getPathFromRoot, getPathFromDirname } = require("../utils/toolPath");
const { runProcessTimeout } = require("../utils/process");
const { replaceTagsInFile } = require("../utils/toolFile");
async function commandCreateMethod(name, options) {
uploadStoreState();
const templatePath = getPathFromDirname("../../template/apps/react18");
const tagertPath = getPathFromRoot(`./${name}`);
await runProcessTimeout(`cp -r ${templatePath} ${tagertPath}`); // 创建项目到当前进程的根目录的路径中。
// 更新nginx配置的文件名称。
await runProcessTimeout(`mv ${tagertPath}/container/nginx/confs/product.conf ${tagertPath}/container/nginx/confs/${name}.conf`);
await replaceTagsInFile(getPathFromRoot(`${tagertPath}/container/nginx/confs/${name}.conf`), [{
tag: "<%productname%>",
value: name
}, {
tag: "<%port%>",
value: "16001"
}]);
await replaceTagsInFile(getPathFromRoot(`${tagertPath}/container/shell/buildUpload.sh`), [{
tag: "<%productname%>",
value: name
},
// {
// tag: "<%http%>",
// value: getConfigInfo("proxyTable.http")
// }
]);
await replaceTagsInFile(getPathFromRoot(`${tagertPath}/m.config.js`), [{
tag: "<%productname%>",
value: name
}]);
console.log('templatePath', templatePath, name, options);
};
async function commandCreateServiceMethod(name, options) {
uploadStoreState();
const templatePath = getPathFromDirname("../../templateService/express");
const tagertPath = getPathFromRoot(`./${name}`);
await runProcessTimeout(`cp -r ${templatePath} ${tagertPath}`); // 创建项目到当前进程的根目录的路径中。
console.log('template service path: ', templatePath, name, options);
};
// 创建状态
function uploadStoreState() {
const { setGlobal } = require("../stores");
setGlobal("env", "prod");
setGlobal("cwd", process.cwd());
process.argv.slice(2).forEach(it => {
const [key, value] = it.split('=');
const _key = key.replace(/-/g, '');
if (!_key) {
return;
}
setGlobal(_key, value);
});
}
module.exports = {
commandCreateMethod,
commandCreateServiceMethod,
uploadStoreState
}