|
@@ -9,27 +9,58 @@ const timestamp = `${now.getFullYear()}${String(now.getMonth() + 1).padStart(2,
|
|
|
// 自定义文字
|
|
// 自定义文字
|
|
|
const customText = '教师端';
|
|
const customText = '教师端';
|
|
|
|
|
|
|
|
-// 新的文件夹名称
|
|
|
|
|
-const newDistName = `dist_${timestamp}_${customText}`;
|
|
|
|
|
|
|
+// 定义路径和文件名
|
|
|
const distPath = path.join(__dirname, '../dist');
|
|
const distPath = path.join(__dirname, '../dist');
|
|
|
-const newDistPath = path.join(__dirname, `../${newDistName}`);
|
|
|
|
|
-const zipFileName = `${newDistName}.zip`;
|
|
|
|
|
|
|
+const originalZipName = 'dist.zip';
|
|
|
|
|
+const renamedZipName = `dist_${timestamp}_${customText}.zip`;
|
|
|
|
|
|
|
|
-// 重命名 dist 文件夹
|
|
|
|
|
-if (fs.existsSync(distPath)) {
|
|
|
|
|
- fs.renameSync(distPath, newDistPath);
|
|
|
|
|
- console.log(`📁 文件夹已重命名为: ${newDistName}`);
|
|
|
|
|
|
|
+// 等待 dist 文件夹存在
|
|
|
|
|
+function waitForDistFolder() {
|
|
|
|
|
+ return new Promise((resolve) => {
|
|
|
|
|
+ const checkDistExists = () => {
|
|
|
|
|
+ if (fs.existsSync(distPath)) {
|
|
|
|
|
+ console.log('📁 检测到 dist 文件夹');
|
|
|
|
|
+ resolve(true);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ console.log('⏳ 未检测到 dist 文件夹,5秒后重新检测...');
|
|
|
|
|
+ setTimeout(checkDistExists, 5000);
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ checkDistExists();
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// 使用 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);
|
|
|
|
|
|
|
+// 主函数
|
|
|
|
|
+async function main() {
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 等待 dist 文件夹出现
|
|
|
|
|
+ await waitForDistFolder();
|
|
|
|
|
+
|
|
|
|
|
+ // 使用 bestzip 打包 dist 文件夹为原始名称的 zip 文件
|
|
|
|
|
+ execSync(`npx bestzip "${originalZipName}" "dist"`, {
|
|
|
|
|
+ cwd: path.join(__dirname, '..'),
|
|
|
|
|
+ stdio: 'inherit'
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // 重命名 zip 文件
|
|
|
|
|
+ fs.renameSync(originalZipName, renamedZipName);
|
|
|
|
|
+
|
|
|
|
|
+ // 获取并打印文件详细信息
|
|
|
|
|
+ const stats = fs.statSync(renamedZipName);
|
|
|
|
|
+ console.log(`✅ 成功创建压缩包: ${renamedZipName}`);
|
|
|
|
|
+ console.log(`📄 文件详细信息:`);
|
|
|
|
|
+ console.log(` 大小: ${stats.size} 字节`);
|
|
|
|
|
+ console.log(` 创建时间: ${stats.birthtime.toLocaleString()}`);
|
|
|
|
|
+ console.log(` 修改时间: ${stats.mtime.toLocaleString()}`);
|
|
|
|
|
+
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ // 清理可能生成的临时文件
|
|
|
|
|
+ if (fs.existsSync(originalZipName)) {
|
|
|
|
|
+ fs.unlinkSync(originalZipName);
|
|
|
|
|
+ }
|
|
|
|
|
+ console.error('❌ 压缩失败:', error.message);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+// 启动主函数
|
|
|
|
|
+main();
|