diff --git a/.gitignore b/.gitignore index 3c8054b..cb48fcb 100644 --- a/.gitignore +++ b/.gitignore @@ -62,3 +62,7 @@ exports/ # 排障时临时下载的截图,通常带有客户名称与业务数据,不得入库 /downloads/ + +# Vue 控制台的 Vite 中间产物;最终单文件产物在 src/packaging/generated/ 并提交 +/.webui-dist/ +/web/dist/ diff --git a/README.md b/README.md index 7d78336..ac8a7f8 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,8 @@ hose-use version | `HOSE_AIPRO_LICENSE_FILE` | AI PRO 凭证文件路径(默认 `~/.config/hose-use/aipro-license.token`,0600) | | `HOSE_AIPRO_LICENSE_PRIVATE_KEY` / `HOSE_AIPRO_LICENSE_PRIVATE_FILE` | 仅签发方使用,客户端运行不需要 | +AI PRO 常驻服务启动后,浏览器打开 `http://127.0.0.1:8889/report` 即为本地 Web 控制台(Vue 单页、资源全内嵌、不依赖 CDN)。前端源码在 `web/`,构建产物由 `bun run web:build` 生成并内嵌进二进制。 + --- ### CLI 常用命令速查 (`hose-use`) diff --git a/package.json b/package.json index f06e3b4..d4a8bb4 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,8 @@ "openapi:bundle": "bun run scripts/generate/bundle-openapi.ts", "openapi:generate-raw": "bun run scripts/generate/generate-raw-openapi.ts", "openapi:all": "bun run scripts/generate/generate-raw-openapi.ts && bun run scripts/generate/bundle-openapi.ts", + "web:dev": "bun --cwd web run dev", + "web:build": "node scripts/build/build-webui.mjs", "build:binary": "node scripts/build/build-binary.mjs", "build:plugin": "node scripts/build/build-plugin.mjs", "package:plugin": "node scripts/build/package-plugin.mjs", diff --git a/scripts/build/build-webui.mjs b/scripts/build/build-webui.mjs new file mode 100644 index 0000000..53b024d --- /dev/null +++ b/scripts/build/build-webui.mjs @@ -0,0 +1,52 @@ +#!/usr/bin/env node +/** + * 构建 web/ 下的 Vue 控制台,并把 JS/CSS 内联成单个 HTML 供二进制内嵌。 + * + * 前置:bun install --cwd web(仅开发机需要;生成物随 git 提交,CI 不需要) + * 用法:bun run web:build + */ +import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs"; +import { dirname, join, resolve } from "node:path"; +import { execFileSync } from "node:child_process"; + +const root = resolve(import.meta.dirname, "../.."); +const webDir = join(root, "web"); +const outDir = join(root, ".webui-dist"); +// 后缀用 .txt 而非 .html:Bun 对 .html 的 text import 会推断成 HTMLBundle, +// 导致 tsc 报错;内容仍是完整 HTML,由 HTTP 层按 text/html 返回。 +const target = join(root, "src", "packaging", "generated", "webui.txt"); + +if (!existsSync(join(webDir, "node_modules"))) { + console.error("[build:webui] web/ 依赖未安装,请先执行: bun install --cwd web"); + process.exit(1); +} + +console.log("[build:webui] building Vue app..."); +execFileSync("bun", ["run", "build"], { cwd: webDir, stdio: "inherit" }); + +const indexPath = join(outDir, "index.html"); +if (!existsSync(indexPath)) { + console.error(`[build:webui] 找不到构建产物: ${indexPath}`); + process.exit(1); +} + +let html = readFileSync(indexPath, "utf8"); +const files = readdirSync(outDir); + +for (const file of files.filter((name) => name.endsWith(".css"))) { + const css = readFileSync(join(outDir, file), "utf8"); + html = html.replace(/]+href="[^"]*\.css"[^>]*>/g, () => ``); +} + +for (const file of files.filter((name) => name.endsWith(".js"))) { + const js = readFileSync(join(outDir, file), "utf8").replaceAll("", "<\\/script>"); + html = html.replace(/`); +} + +if (/ + + +
+ + +