const { execSync } = require('child_process'); const fs = require('fs'); const path = require('path'); // 获取当前时间戳 const now = new Date(); const timestamp = `${now.getFullYear()}${String(now.getMonth() + 1).padStart(2, '0')}${String(now.getDate()).padStart(2, '0')}_${String(now.getHours()).padStart(2, '0')}${String(now.getMinutes()).padStart(2, '0')}${String(now.getSeconds()).padStart(2, '0')}`; // 自定义文字 const customText = '后台端'; // 新的文件夹名称 const newDistName = `dist_${timestamp}_${customText}`; const distPath = path.join(__dirname, '../dist'); const newDistPath = path.join(__dirname, `../${newDistName}`); const zipFileName = `${newDistName}.zip`; // 重命名 dist 文件夹 if (fs.existsSync(distPath)) { fs.renameSync(distPath, newDistPath); console.log(`📁 文件夹已重命名为: ${newDistName}`); } // 使用 bestzip 打包为 zip 文件 try { execSync(`npx bestzip "${zipFileName}" "${newDistName}"`, { cwd: path.join(__dirname, '..'), stdio: 'inherit' }); fs.rmdirSync(newDistPath, { recursive: true }); console.log(`✅ 成功创建压缩包: ${zipFileName}`); } catch (error) { fs.rmdirSync(newDistPath, { recursive: true }); console.error('❌ 压缩失败:', error.message); }