* Default `$D compare --serve` path: ensure the persistent daemon is up, * publish the board, open the browser to its URL, then exit. The daemon * survives. * * Stderr lines (in order): * - "DAEMON_STARTED port=N version=V" (or "DAEMON_ATTACHED port=N ..." * if a daemon was already runn
(opts: { html: string; title?: string })
| 336 | * line keeps port-only consumers from breaking outright.) |
| 337 | */ |
| 338 | async function publishToDaemon(opts: { html: string; title?: string }): Promise<void> { |
| 339 | if (!opts.html) { |
| 340 | console.error("--html is required (compare --serve provides --output as the html)"); |
| 341 | process.exit(1); |
| 342 | } |
| 343 | const ensured = await ensureDaemon({}); |
| 344 | console.error( |
| 345 | `${ensured.spawned ? "DAEMON_STARTED" : "DAEMON_ATTACHED"} port=${ensured.port} version=${ensured.version}`, |
| 346 | ); |
| 347 | const result = await publishBoard({ |
| 348 | port: ensured.port, |
| 349 | html: opts.html, |
| 350 | title: opts.title, |
| 351 | }); |
| 352 | console.error(`BOARD_PUBLISHED: ${result.url}`); |
| 353 | console.error(`BOARD_URL: ${result.url}`); |
| 354 | // Legacy alias so anything still grepping `SERVE_STARTED: port=` gets the |
| 355 | // port. The full back-compat story requires the caller to ALSO learn the |
| 356 | // per-board path; see publishToDaemon docstring above. |
| 357 | console.error(`SERVE_STARTED: port=${ensured.port} html=${opts.html}`); |
| 358 | console.log(JSON.stringify({ id: result.id, url: result.url, sourceDir: result.sourceDir }, null, 2)); |
| 359 | openBrowser(result.url); |
| 360 | // Short-lived publisher process exits; daemon keeps serving. |
| 361 | } |
| 362 | |
| 363 | /** Open a URL in the default browser. Stays cross-platform with serve.ts. */ |
| 364 | function openBrowser(url: string): void { |
no test coverage detected