import { cpSync, existsSync, mkdirSync, rmSync } from "node:fs"; import { spawnSync } from "node:child_process"; import { join } from "node:path"; const root = process.cwd(); const distDir = join(root, "dist"); const clientDir = join(distDir, "client"); const outputDir = join(root, "out"); const vinextBin = join(root, "node_modules", ".bin", process.platform === "win32" ? "vinext.cmd" : "vinext"); rmSync(distDir, { recursive: true, force: true }); rmSync(outputDir, { recursive: true, force: true }); const result = spawnSync(vinextBin, ["build"], { cwd: root, stdio: "inherit", shell: process.platform === "win32", }); const builtIndex = join(clientDir, "index.html"); if (!existsSync(builtIndex)) { console.error("\n本地构建失败:没有生成 dist/client/index.html。\n"); process.exit(result.status || 1); } mkdirSync(outputDir, { recursive: true }); cpSync(clientDir, outputDir, { recursive: true }); console.log("\n部署成品已生成:out/\n"); // vinext 1.0 beta can hit a Windows libuv assertion after a successful export. // The fresh artifact check above is the source of truth for this browser-only site. process.exit(0);