于添 il y a 4 mois
Parent
commit
e12347b40d
3 fichiers modifiés avec 53 ajouts et 21 suppressions
  1. 3 2
      package.json
  2. 50 19
      scripts/build-zip.cjs
  3. 0 0
      stats.html

+ 3 - 2
package.json

@@ -11,8 +11,8 @@
 		"dev": "vite --mode development --host 0.0.0.0",
 		"dev245": "vite --mode development245 --host 0.0.0.0",
 		"preview": "vite preview",
-		"build": "vite build --mode production && node scripts/build-zip.cjs",
-		"build245": "vite build --mode production245 && node scripts/build-zip.cjs",
+		"build": "shx rm -rf dist && vite build --mode production && node scripts/build-zip.cjs",
+		"build245": "shx rm -rf dist && vite build --mode production245 && node scripts/build-zip.cjs",
 		"prod": "vite  --mode production && node scripts/build-zip.cjs"
 	},
 	"dependencies": {
@@ -96,6 +96,7 @@
 		"postcss": "8.4.21",
 		"prettier": "2.8.7",
 		"rollup-plugin-visualizer": "5.8.3",
+		"shx": "^0.4.0",
 		"tailwindcss": "3.2.7",
 		"typescript": "4.9.5",
 		"unplugin-auto-import": "0.15.2",

+ 50 - 19
scripts/build-zip.cjs

@@ -9,27 +9,58 @@ const timestamp = `${now.getFullYear()}${String(now.getMonth() + 1).padStart(2,
 // 自定义文字
 const customText = '教师端';
 
-// 新的文件夹名称
-const newDistName = `dist_${timestamp}_${customText}`;
+// 定义路径和文件名
 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();

Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
stats.html


Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff