yangyin
2024-07-15 f0f4eda13c9a1f19ff95dd0f25cc89b13f5b5f39
scripts/helper.js
@@ -18,6 +18,7 @@
const homeDir = os.homedir();
// const deployEnv = process.argv[3];
const logColor = (text, color) => {
   console.log(chalk[color](text));
};
@@ -30,18 +31,6 @@
   logColor(text, 'green');
};
/**
 * 检查文件是否存在
 * @param {*} file
 * @param {*} fileText
 */
const checkFileExist = (file, fileText) => {
   // 验证源文件夹是否存在
   if (!fs.existsSync(file)) {
      console.error(chalk.red(`${fileText} "${file}" 不存在!`));
      process.exit(1); // 退出脚本
   }
};
const checkCustomerDirExist = (customer) => {
   const customerDir = path.join(customerListDir, customer);
@@ -132,7 +121,18 @@
   // 复制源文件夹中的所有文件到 public 文件夹
   fs.copySync(customerDir, publicDir, { filter });
}
/**
 * 检查文件是否存在
 * @param {*} file
 * @param {*} fileText
 */
const checkFileExist = (file, fileText = '') => {
   // 验证源文件夹是否存在
   if (!fs.existsSync(file)) {
      console.error(chalk.red(`${fileText ? fileText + ' ' : ''}"${file}" 不存在!`));
      exit(); // 退出脚本
   }
};
/**
 * 上传文件到服务器
 * @param {*} command
@@ -228,6 +228,20 @@
   logSuccess(`🎉🎉🎉【${customerList.join(',')}】项目已成功部署!🎉🎉🎉`);
};
/**
 * 退出脚本
 */
const exit = () => {
   process.exit(1); // 退出脚本
};
const replaceFileContent = (path, callback) => {
   const data = fs.readFileSync(path, 'utf8');
   if (!data) return;
   const newData = callback(data);
   fs.writeFileSync(path, newData, 'utf8');
};
module.exports = {
   customerList,
   //#region ====================== 文件路径 ======================
@@ -252,4 +266,8 @@
   moveProjectsToBakDir,
   restoreProjectDir,
   exit,
   checkFileExist,
   replaceFileContent
};