Files

24 lines
1.3 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// build:console 的第二步:把 vite-plugin-singlefile 产出的单文件
// 原样拷到可部署位置。绝不改动产物内容——以后改页面只改 src 再构建。
// 目标就是 GET /console 现读的文件 cloud/console.html
// (cloud/server.py 与 console.html 同目录、每次请求现读),
// 不再拷到仓库里不存在的 cloud/console-redesign/console-react.html,
// 也不再靠手工拷兜底:npm run build:console 一次跑通即产物就位。
import { copyFileSync } from "node:fs";
import { createHash, timingSafeEqual } from "node:crypto";
import { readFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
const src = join(root, "dist", "index.html");
const dest = join(root, "..", "console.html");
copyFileSync(src, dest);
const srcBuf = readFileSync(src);
const destBuf = readFileSync(dest);
if (srcBuf.length !== destBuf.length || !timingSafeEqual(srcBuf, destBuf)) {
throw new Error("copy-build: dest 与 dist/index.html 内容不一致,构建失败");
}
console.log(`console.html ${destBuf.length} bytes sha256=${createHash("sha256").update(destBuf).digest("hex")}`);
console.log(`built: ${src} -> ${dest}`);