Files
lum1104--understand-anything/understand-anything-plugin/packages/viewer/build.mjs
T
Lum1104 0c247317a0 feat(viewer): standalone dashboard viewer runnable via npx from release assets
New zero-dependency package understand-anything-viewer: a small Node
http server with the prebuilt dashboard embedded, replicating the dev
server's endpoints and security model (127.0.0.1 bind, one-time access
token on every data endpoint, graph filePath sanitisation, file-content
allowlist / 1MB cap / binary rejection, .ua with legacy
.understand-anything fallback). npm-packed and attached to each GitHub
release as understand-anything-viewer.tgz, so teammates without Claude
Code open a committed graph with:

  npx https://github.com/Egonex-AI/Understand-Anything/releases/latest/download/understand-anything-viewer.tgz <project>

No npm registry publishing involved. End-to-end tests spawn the real
server and cover the token gate, sanitisation, allowlist, traversal
guards, and both data-directory layouts.
2026-07-10 17:57:06 +08:00

30 lines
1.2 KiB
JavaScript

#!/usr/bin/env node
/**
* Build the standalone viewer: build the dashboard (and its core dependency),
* then embed the compiled frontend under this package's dist/ so the packed
* tarball is fully self-contained (no runtime dependencies).
*
* Run from anywhere inside the monorepo:
* pnpm --filter understand-anything-viewer build
*/
import { execSync } from "node:child_process";
import { cpSync, rmSync, existsSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
const here = dirname(fileURLToPath(import.meta.url));
const dashboardDist = join(here, "..", "dashboard", "dist");
const viewerDist = join(here, "dist");
execSync("pnpm --filter @understand-anything/core build", { stdio: "inherit", cwd: here });
execSync("pnpm --filter @understand-anything/dashboard build", { stdio: "inherit", cwd: here });
if (!existsSync(dashboardDist)) {
console.error(`Error: dashboard build output not found at ${dashboardDist}`);
process.exit(1);
}
rmSync(viewerDist, { recursive: true, force: true });
cpSync(dashboardDist, viewerDist, { recursive: true });
console.log(`Embedded dashboard build into ${viewerDist}`);