Files
buuh/packages/bankai/cli.js
T
Bendik Aagaard LynghaugandClaude Fable 5 7e08b585ac feat(bankai): bankai v10 — the isomorphic compiler & server on Vite 8
One command, zero config, and only the client ever bundles: v8 server
code is plain ESM that Node runs as-authored, so there is no server
build to rot (the lesson of v9).

- start: Vite middleware mode + HMR with per-request streaming SSR via
  ssrLoadModule; a virtual client entry generates the browser glue so
  the user writes exactly one isomorphic module (plan decision D5).
- build: client bundle via Vite 8/Rolldown, manifest-derived route
  assets in dist/bankai.json, service worker built with the precache
  list injected (choo-service-worker convention, manifest edition),
  brotli+gzip precompression of every text asset.
- serve: immutable caching + precompressed negotiation for hashed
  assets, 103 Early Hints (res.writeEarlyHints) with the route's assets
  before every page, streaming SSR, and a window.initialState tail with
  script-breakout-safe serialization and choo internals filtered out.
- inspect: raw/gzip/brotli size report.

Integration tests drive the real counter example through build and
serve, asserting the 103 interim response at the HTTP level.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014NgfSjHE11oFpoSnLVKLXd
2026-09-08 19:32:37 +02:00

60 lines
2.1 KiB
JavaScript

#!/usr/bin/env node
// bankai <command> [entry] [options]
//
// bankai start <entry> dev server: Vite + HMR + streaming SSR
// bankai build <entry> production build (client bundle, manifest,
// service worker, precompression)
// bankai serve production server for a built app: static
// assets + 103 Early Hints + streaming SSR
// bankai inspect size report for the built output
//
// options: --port <n> --out <dir> --title <text>
import { parseArgs } from 'node:util'
const { values, positionals } = parseArgs({
allowPositionals: true,
options: {
port: { type: 'string' },
out: { type: 'string', default: 'dist' },
title: { type: 'string', default: 'choo' }
}
})
const [command, entry] = positionals
const port = values.port ? Number(values.port) : 8080
try {
if (command === 'start') {
requireEntry(entry)
const { default: dev } = await import('./lib/dev.js')
const { origin } = await dev({ entry, port, title: values.title })
console.log(`bankai: dev server streaming on ${origin}`)
} else if (command === 'build') {
requireEntry(entry)
const { default: build } = await import('./lib/build.js')
const { outDir, compressed } = await build({ entry, outDir: values.out, title: values.title })
console.log(`bankai: built to ${outDir} (${compressed} asset(s) precompressed) — bankai serve to run it`)
} else if (command === 'serve') {
const { default: serve } = await import('./lib/serve.js')
const { origin } = await serve({ outDir: values.out, port })
console.log(`bankai: production server on ${origin}`)
} else if (command === 'inspect') {
const { default: inspect } = await import('./lib/inspect.js')
await inspect({ outDir: values.out })
} else {
console.log('usage: bankai <start|build|serve|inspect> [entry] [--port n] [--out dir] [--title text]')
process.exit(command ? 1 : 0)
}
} catch (err) {
console.error('bankai:', err.message)
process.exit(1)
}
function requireEntry (value) {
if (!value) {
console.error('bankai: an entry module is required, e.g. bankai start app.js')
process.exit(1)
}
}