#!/usr/bin/env node /** 把 panel.css + panel.template.js 合成 dist/client.js(客户端半片)。 */ import fs from "node:fs" import { homedir } from "node:os" import { join, dirname } from "node:path" import { fileURLToPath } from "node:url" const here = dirname(fileURLToPath(import.meta.url)) const root = join(here, "..") const css = fs.readFileSync(join(root, "src/panel/panel.css"), "utf8") let tpl = fs.readFileSync(join(root, "src/panel/panel.template.js"), "utf8") if (!tpl.includes("__CSS_JSON__")) { console.error("模板里没有 __CSS_JSON__ 占位,拒绝生成") process.exit(1) } tpl = tpl.replace("__CSS_JSON__", JSON.stringify(css)) fs.mkdirSync(join(root, "dist"), { recursive: true }) fs.writeFileSync(join(root, "dist/client.js"), tpl) const kb = (fs.statSync(join(root, "dist/client.js")).size / 1024).toFixed(1) console.log("built dist/client.js " + kb + " KB (css " + css.split("\n").length + " 行)")