feat: cli launcher npx kandev (#39)

* feat: cli launcher

* feat: improved debug
This commit is contained in:
Carlos Florêncio
2026-01-18 20:42:03 +00:00
committed by GitHub
parent 16b3fb5b92
commit bc6a5f28d9
29 changed files with 1682 additions and 33 deletions
+34
View File
@@ -0,0 +1,34 @@
import kill from "tree-kill";
export type ChildLike = { pid?: number | undefined };
export function createProcessSupervisor(): {
children: ChildLike[];
shutdown: (reason: string) => Promise<void>;
attachSignalHandlers: () => void;
} {
let shuttingDown = false;
const children: ChildLike[] = [];
const shutdown = async (reason: string) => {
if (shuttingDown) return;
shuttingDown = true;
console.log(`[kandev] shutting down (${reason})...`);
await Promise.all(
children
.filter((child) => child.pid)
.map((child) => new Promise<void>((resolve) => kill(child.pid as number, "SIGTERM", () => resolve()))),
);
};
const onSignal = (signal: NodeJS.Signals) => {
void shutdown(`signal ${signal}`).then(() => process.exit(0));
};
const attachSignalHandlers = () => {
process.on("SIGINT", onSignal);
process.on("SIGTERM", onSignal);
};
return { children, shutdown, attachSignalHandlers };
}