// esbuild build for @hive/agent. Outputs: // // dist/app.js bundled ES module (entrypoint = src/app.js, // pulls in @hive/shared + marked) // dist/agent.css bundled stylesheet (entrypoint = src/agent.css, // @import "@hive/shared/base.css" + terminal.css // get inlined here) // dist/stats.js bundled stats page (entrypoint = src/stats.js, // pulls in chart.js/auto) // dist/{index,stats,screen}.html copies of src/*.html (esbuild // doesn't process HTML; the bundled siblings are // referenced by name) // // The in-container Rust binary serves `dist/` via tower_http::ServeDir, // with the per-agent `hyperhive.frontend.extraFiles` layered on top. import { build } from 'esbuild'; import { mkdirSync, copyFileSync, rmSync } from 'node:fs'; import { dirname, resolve } from 'node:path'; import { fileURLToPath } from 'node:url'; const here = dirname(fileURLToPath(import.meta.url)); const src = (p) => resolve(here, 'src', p); const dist = (p) => resolve(here, 'dist', p); rmSync(dist(''), { recursive: true, force: true }); mkdirSync(dist(''), { recursive: true }); // Two JS entries: the main app + the stats page. Both bundle their // own deps so each page can be loaded independently. await build({ entryPoints: [src('app.js'), src('stats.js')], outdir: dist(''), bundle: true, format: 'esm', platform: 'browser', target: ['es2022'], sourcemap: true, logLevel: 'info', }); // Bundle the CSS — the @import lines pull in shared/base.css and // shared/terminal.css from the @hive/shared workspace dep. await build({ entryPoints: [src('agent.css')], outfile: dist('agent.css'), bundle: true, loader: { '.css': 'css' }, logLevel: 'info', }); for (const html of ['index.html', 'stats.html', 'screen.html']) { copyFileSync(src(html), dist(html)); } console.log('agent build ok →', dist(''));