1import { spawn } from "node:child_process";
2import { createRequire } from "node:module";
3import { dirname, join } from "node:path";
4import { buildComponents } from "./build-components.ts";
5
6const watcher = await buildComponents(true);
7const require = createRequire(import.meta.url);
8const reader = join(
9 dirname(require.resolve("ts-docs-fresh/package.json")),
10 "dist/cli.js",
11);
12const child = spawn(process.execPath, [reader, "dev", ".", "--port", "4326"], {
13 stdio: "inherit",
14});
15let closing = false;
16async function close() {
17 if (closing) return;
18 closing = true;
19 child.kill("SIGTERM");
20 await watcher?.dispose();
21}
22process.once("SIGINT", () => void close());
23process.once("SIGTERM", () => void close());
24child.once("exit", (code) => {
25 void close().then(() => {
26 process.exitCode = code ?? 0;
27 });
28});