wujingjing
2024-12-11 2144fb07b53812f565b2801f99e69cee9b28cab3
scripts/helper.js
@@ -15,9 +15,13 @@
const customerProjectListDir = path.join(rootDir, 'src', 'views', 'project');
const firstCustomerName = customerList[0]?.split(':')[0];
/** 公共文件夹,所有客户文件夹共享文件 */
const commonDir = path.join(customerListDir,'common')
const commonDir = path.join(customerListDir, 'common');
const homeDir = os.homedir();
const item = customerList[0];
const customerSplit = item?.split(':');
const deployEnv = customerSplit?.[1];
// 是否为生产环境
const isPro = deployEnv === 'pro';
// const deployEnv = process.argv[3];
const logColor = (text, color) => {
@@ -30,6 +34,10 @@
const logSuccess = (text) => {
   logColor(text, 'green');
};
const logWarn = (text) => {
   logColor(text, 'yellow');
};
/**
@@ -185,6 +193,23 @@
   return format;
};
const copyAmisEditor = () => {
   // 复制amis-editor 到 public文件夹中
   const amisEditorPath = path.join(rootDir, 'wi.amis', 'amis-editor');
   const targetPath = path.join(publicDir, 'amis-editor');
   const isExist = fs.pathExistsSync(amisEditorPath);
   if (!isExist) {
      logWarn(`amis-editor(路径:${amisEditorPath} 不存在!`);
   } else {
      const isExist = fs.pathExistsSync(targetPath);
      if (!isExist) {
         fs.mkdirSync(targetPath);
      }
      const res = fs.copySync(amisEditorPath, targetPath);
      res ?? logSuccess('========= 已集成 amis-editor =========');
   }
};
/**
 * 复制文件到 public 文件夹中
 * (只能复制一个客户文件配置)
@@ -211,7 +236,8 @@
   const customerDir = path.join(customerListDir, firstCustomerName);
   // 复制源文件夹中的所有文件到 public 文件夹
   fs.copySync(customerDir, publicDir, { filter });
   fs.copySync(commonDir,publicDir);
   fs.copySync(commonDir, publicDir);
   copyAmisEditor();
}
/**
@@ -312,7 +338,23 @@
   logSuccess(`${formatDate(new Date(), 'HH:MM:SS')} > 🎉🎉🎉【${customerList.join(',')}】项目已成功部署!🎉🎉🎉`);
};
/**
 * 切换分支
 */
const changeBranch = () => {
   if (isPro) {
      try {
         execSync('git checkout master', { stdio: 'inherit' });
      } catch (error) {}
   } else {
      try {
         execSync('git checkout test', { stdio: 'inherit' });
      } catch (error) {}
   }
};
module.exports = {
   isPro,
   firstCustomerName,
   exit,
   customerList,
@@ -336,9 +378,12 @@
   //#region ====================== 打印 ======================
   logError,
   logSuccess,
   logWarn,
   //#endregion
   formatDate,
   updateImportGlob,
   restoreImportGlob,
   deployEnv,
   changeBranch,
};