feat(HAI-071): add Bun single-binary compile support for CLI

- Create build script (packages/cli/build.ts) using Bun.build compile target
- Update asset resolution in dashboard server for bundled context
- Add npm scripts to wire up the build process
- Add build-exe tests to verify compiled binary output
- Fix pre-existing build errors in engine and core packages
- Document build and compile workflow in README
This commit is contained in:
Dustin Byrne
2026-03-26 00:32:57 -04:00
parent 96bacb5d65
commit fbecff7255
7 changed files with 230 additions and 6 deletions

View File

@@ -21,11 +21,22 @@ export function createServer(store: TaskStore, options?: ServerOptions): ReturnT
app.use(express.json());
// Serve built React app
const clientDir = existsSync(join(__dirname, "..", "dist", "client"))
? join(__dirname, "..", "dist", "client")
: existsSync(join(__dirname, "..", "client"))
? join(__dirname, "..", "client")
: join(__dirname, "..", "public");
// Resolution order:
// 1. HAI_CLIENT_DIR env override (explicit)
// 2. Next to process.execPath (bun-compiled binary: dist/hai + dist/client/)
// 3. __dirname/../dist/client (running from src/ via tsx/ts-node)
// 4. __dirname/../client (running from dist/ after tsc)
// 5. __dirname/../public (fallback for dev)
const execDir = dirname(process.execPath);
const clientDir = process.env.HAI_CLIENT_DIR
? process.env.HAI_CLIENT_DIR
: existsSync(join(execDir, "client", "index.html"))
? join(execDir, "client")
: existsSync(join(__dirname, "..", "dist", "client"))
? join(__dirname, "..", "dist", "client")
: existsSync(join(__dirname, "..", "client"))
? join(__dirname, "..", "client")
: join(__dirname, "..", "public");
app.use(express.static(clientDir));