* STATIC: serve the bundled SPA (` /dist`, a sibling of this file's `dist-cli`) * plus the file bridge from a Node HTTP server on an ephemeral port, then open * the browser. No Vite, no source.
(resolvedFile?: string, allowRoot?: string)
| 46 | * the browser. No Vite, no source. |
| 47 | */ |
| 48 | async function openStatic(resolvedFile?: string, allowRoot?: string): Promise<void> { |
| 49 | const here = path.dirname(fileURLToPath(import.meta.url)); |
| 50 | const spaRoot = path.resolve(here, "..", "dist"); |
| 51 | if (!tryAccess(path.join(spaRoot, "index.html"))) { |
| 52 | process.stderr.write(`Built SPA not found at ${spaRoot}. This package is missing its bundled assets.\n`); |
| 53 | process.exit(1); |
| 54 | } |
| 55 | |
| 56 | const allowedRoots = [allowRoot ?? process.cwd()]; |
| 57 | const { port } = await startStaticServer({ spaRoot, allowedRoots }); |
| 58 | const url = resolvedFile |
| 59 | ? `http://localhost:${port}/?file=${encodeURIComponent(resolvedFile)}` |
| 60 | : `http://localhost:${port}/`; |
| 61 | |
| 62 | process.stdout.write(`\nfh-workflow running at ${url}\n`); |
| 63 | if (resolvedFile) process.stdout.write(`Bound to ${resolvedFile}\n`); |
| 64 | process.stdout.write("Press Ctrl+C to stop.\n\n"); |
| 65 | openInBrowser(url); |
| 66 | |
| 67 | // The listening server keeps the event loop alive; block until Ctrl+C. |
| 68 | await new Promise<never>(() => {}); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * DEV: spawn Vite as a child process (NOT via createServer in-process — Vite's |
no test coverage detected