// Dev orchestrator: starts ng serve (UI hot reload), waits for it, then runs // `electrobun dev --watch` (relaunches the app when bun-side code changes). const DEV_SERVER_URL = "http://localhost:4200"; const ui = Bun.spawn(["bun", "run", "--cwd", "ui", "start"], { stdout: "inherit", stderr: "inherit", }); async function waitForServer(url: string, timeoutMs = 90_000): Promise { const deadline = Date.now() + timeoutMs; while (Date.now() < deadline) { try { await fetch(url, { method: "HEAD" }); return; } catch { await Bun.sleep(300); } } throw new Error(`Dev server at ${url} did not come up in ${timeoutMs}ms`); } console.log(`Waiting for Angular dev server at ${DEV_SERVER_URL} ...`); await waitForServer(DEV_SERVER_URL); console.log("Angular dev server is up, launching Electrobun ..."); const app = Bun.spawn(["bunx", "electrobun", "dev", "--watch"], { stdout: "inherit", stderr: "inherit", env: { ...process.env, DEV_SERVER_URL }, }); function shutdown() { ui.kill(); app.kill(); process.exit(0); } process.on("SIGINT", shutdown); process.on("SIGTERM", shutdown); await app.exited; shutdown();