MMnode/frontend/build.bench.ts
Z User eefca88d35 feat: Moxie bench - standalone python/web harness for the fixed pipeline
- bench/ FastAPI server: fixed 9-stage pipeline parsed from the base
  workflow, serial render jobs, WS progress mirroring ComfyUI's push
  events, /api/view + ComfyUI-compatible /view, /upload/image,
  /easy-media/* aliases for the ported editor
- dual backend: self-contained mock renderer (numpy+ffmpeg, deterministic
  per prompt/seed, native + RTX-upscaled mp4 branches) and a ComfyUI
  bridge (substitutes the plan into base_workflow.json, converts to the
  /prompt API format, polls history, downloads outputs)
- timeline port: frontend/src/bench mounts the unmodified MultiTrack
  editor against a comfyAPI shim (fetchApi/toast/dialog/custom events);
  build.bench.ts emits bench/ui-dist served by the server
- packaging: PyInstaller onedir spec + Tauri2 sidecar docs
- tests: bench/tests contract suite + scripts/test_bench_pipeline.py
  e2e (API+WS+render); prebuilt bench UI committed
2026-09-28 01:42:58 +00:00

104 lines
3.0 KiB
TypeScript

/**
* Bench UI build — mirrors build.ts but outputs a standalone web app into
* ../bench/ui-dist (served by the bench FastAPI server).
*
* bun run build.bench.ts # dev build
* bun run build.bench.ts --release # minified
*/
import { $ } from "bun";
import path from "path";
import fs from "fs";
import os from "os";
const isRelease = Bun.argv.includes("--release");
const rootDir = path.resolve(import.meta.dir, "..");
const outdir = path.join(rootDir, "bench", "ui-dist");
const project_name = path.basename(rootDir);
fs.mkdirSync(outdir, { recursive: true });
function scopeTailwindThemeVariables(css: string, widgetClass: string): string {
return css.replace(/:root\s*,\s*:host\s*\{/g, `.${widgetClass}{`);
}
async function buildCSS(): Promise<string> {
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "moxie-bench-css-"));
const cssOut = path.join(tempDir, "globals.css");
const minifyFlag = isRelease ? "--minify" : "";
try {
await $`./node_modules/.bin/tailwindcss -i ./src/styles/globals.css -o ${cssOut} ${minifyFlag}`;
const widgetClass = project_name.toLowerCase();
const css = fs.readFileSync(cssOut, "utf-8");
return scopeTailwindThemeVariables(
css.replaceAll("__CUSTOM_NODE_CLASS__", widgetClass),
widgetClass,
);
} finally {
fs.rmSync(tempDir, { recursive: true, force: true });
}
}
async function build() {
const start = Date.now();
const globalCss = await buildCSS();
const result = await Bun.build({
entrypoints: ["./src/bench/main.tsx"],
outdir,
naming: {
chunk: "chunks/[name]-[hash].[ext]",
entry: "[name].[ext]",
asset: "assets/[name].[ext]",
},
splitting: true,
target: "browser",
minify: isRelease,
define: {
"process.env.NODE_ENV": isRelease ? '"production"' : '"development"',
"import.meta.env.PROJECT_NAME": `"${project_name}"`,
"__COMFY_EASY_MEDIA_GLOBAL_CSS__": JSON.stringify(globalCss),
},
css: false,
});
if (!result.success) {
for (const log of result.logs) {
console.error(log);
}
throw new Error("bench UI build failed");
}
// index.html referencing the built entry
const entryName = result.outputs
.map((o) => o.path)
.filter((p) => p.endsWith("main.js") || p.endsWith("main.js.map"))
.map((p) => path.basename(p))
.find((p) => p.endsWith(".js"));
const html = `<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Moxie Multimedia Bench</title>
<style>
html, body, #root { height: 100%; margin: 0; }
body { background: #09090b; color: #fafafa; }
</style>
</head>
<body>
<div id="root"></div>
<script type="module" src="./${entryName ?? "main.js"}"></script>
</body>
</html>
`;
fs.writeFileSync(path.join(outdir, "index.html"), html);
console.log(
`[build:bench${isRelease ? ":release" : ""}] Done in ${Date.now() - start}ms (${result.outputs.length} outputs) -> ${outdir}`,
);
}
await build();