wujingjing
2025-04-14 77b15609b62c9bcd80fcdfd65f134a06252920b9
scripts/helper.js
@@ -3,6 +3,7 @@
const os = require('os');
const path = require('path');
const chalk = require('chalk');
require('dotenv').config({ path: '.env.local' });
// 获取当前脚本所在的目录
const scriptDir = __dirname;
@@ -10,18 +11,19 @@
const argv2 = process.argv[2];
const customerList = argv2?.split(' ') ?? '';
const publicDir = path.join(rootDir, 'public');
const distDir = path.join(rootDir, 'dist');
const distDir = process.env.VITE_OUTPUT_DIR || path.join(rootDir, 'dist');
const customerListDir = path.join(rootDir, 'customer_list');
const customerProjectListDir = path.join(rootDir, 'src', 'views', 'project');
const firstCustomerName = customerList[0]?.split(':')[0];
/** 公共文件夹,所有客户文件夹共享文件 */
const commonDir = path.join(customerListDir, 'common');
 const item = customerList[0];
const item = customerList[0];
const customerSplit = item?.split(':');
const deployEnv = customerSplit?.[1];
// 是否为生产环境
const isPro = deployEnv==='pro';
const isPro = deployEnv === 'pro';
// const deployEnv = process.argv[3];
const logColor = (text, color) => {
@@ -72,7 +74,7 @@
 */
const checkCustomer = (command, customer = firstCustomerName) => {
   if (!customer) {
      console.error(chalk.red(`请正确使用命令 “${command} [customer]” `));
      console.error(chalk.red(`请正确使用命令 "${command} [customer]"`));
      exit(); // 退出脚本
   }
@@ -238,7 +240,7 @@
      checkFileExist(deployJSON, '配置文件');
      // 读取 JSON 文件
      const config = await fs.readJson(deployJSON).catch((err) => {
         console.error(`读取配置文件“${deployJSON}”出错:`, err);
         console.error(`读取配置文件"${deployJSON}"出错:`, err);
         exit();
      });
@@ -293,7 +295,7 @@
               }
            }
         } catch (error) {
            console.error(`读取“${customerFolder}”失败`, error);
            console.error(`读取"${customerFolder}"失败`, error);
         }
         try {
@@ -323,7 +325,7 @@
/**
 * 切换分支
 */
const changeBranch = () =>{
const changeBranch = () => {
   return;
   if (isPro) {
      try {
@@ -334,7 +336,7 @@
         execSync('git checkout test', { stdio: 'inherit' });
      } catch (error) {}
   }
}
};
module.exports = {
   isPro,
@@ -368,5 +370,5 @@
   updateImportGlob,
   restoreImportGlob,
   deployEnv,
   changeBranch
   changeBranch,
};