From 817a58ebe402082b4ef6a9ea554dc51bf59dde06 Mon Sep 17 00:00:00 2001 From: TakahashiNguyen Date: Tue, 31 Mar 2026 06:56:37 +0000 Subject: [PATCH] Update scripts/release.ts --- scripts/release.ts | 47 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/scripts/release.ts b/scripts/release.ts index 3aecb0b..2e10ce1 100644 --- a/scripts/release.ts +++ b/scripts/release.ts @@ -1,4 +1,5 @@ import { execSync } from "node:child_process"; +import fs from "node:fs"; const version = process.argv[2]; if (!version) { @@ -6,14 +7,46 @@ if (!version) { process.exit(1); } -const zipPath = "release.zip"; +const zipPath = `release-v${version}.zip`; // Thêm version vào tên file cho dễ quản lý -console.log(`📦 Đang nén file cho version: ${version}...`); +console.log(`📦 Đang chuẩn bị đóng gói App Router Standalone cho version: ${version}...`); -execSync(`cd out && zip -r ../${zipPath} .`, { - stdio: "inherit", -}); +// Kiểm tra xem đã build chưa +if (!fs.existsSync(".next/standalone")) { + console.error("❌ Thư mục .next/standalone không tồn tại. Hãy chạy 'pnpm build' trước!"); + process.exit(1); +} -console.log(`✅ Đã tạo file zip: ${zipPath}`); +/** + * Với Next.js Standalone, ta cần: + * 1. Nội dung trong .next/standalone (copy ra ngoài hoặc nén trực tiếp) + * 2. .next/static (phải nằm trong .next/static của gói release) + * 3. public (phải nằm trong public của gói release) + */ -execSync("pnpm format"); +try { + // Tạo thư mục tạm để cấu trúc lại file trước khi nén + execSync("rm -rf temp_release && mkdir -p temp_release"); + + console.log("🚚 Đang sao chép các file standalone..."); + execSync("cp -r .next/standalone/. temp_release/"); + + console.log("🚚 Đang sao chép static và public..."); + execSync("mkdir -p temp_release/.next/static"); + execSync("cp -r .next/static/. temp_release/.next/static/"); + execSync("cp -r public temp_release/ 2>/dev/null || : "); // Bỏ qua nếu không có thư mục public + + console.log("🗜️ Đang nén thành file zip..."); + // Di chuyển vào temp_release để nén các file bên trong nó + execSync(`cd temp_release && zip -r ../${zipPath} .`, { stdio: "inherit" }); + + // Xóa thư mục tạm + execSync("rm -rf temp_release"); + + console.log(`✅ Đã tạo file thành công: ${zipPath}`); + + execSync("pnpm format"); +} catch (error) { + console.error("❌ Có lỗi xảy ra trong quá trình nén:", error.message); + process.exit(1); +} \ No newline at end of file