| | |
| | | const homeDir = os.homedir(); |
| | | // const deployEnv = process.argv[3]; |
| | | |
| | | |
| | | const logColor = (text, color) => { |
| | | console.log(chalk[color](text)); |
| | | }; |
| | |
| | | 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); |
| | |
| | | // 复制源文件夹中的所有文件到 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 |
| | |
| | | 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 ====================== 文件路径 ====================== |
| | |
| | | |
| | | moveProjectsToBakDir, |
| | | restoreProjectDir, |
| | | |
| | | exit, |
| | | checkFileExist, |
| | | replaceFileContent |
| | | }; |