Update scripts/release.ts
Release package / release (pull_request) Failing after 5m12s

This commit is contained in:
2026-03-31 06:56:37 +00:00
parent 8753db3b37
commit 817a58ebe4
+40 -7
View File
@@ -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);
}