-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdev.ts
More file actions
37 lines (32 loc) · 907 Bytes
/
dev.ts
File metadata and controls
37 lines (32 loc) · 907 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* Dev script - replaces concurrently + wait-on.
* Starts the Bun dev server, waits for it to be ready, then launches Electron.
* Kills both processes on exit.
*/
const server = Bun.spawn(["bun", "--hot", "src/index.ts"], {
stdio: ["inherit", "inherit", "inherit"],
env: { ...Bun.env },
});
const url = "http://localhost:3000";
const maxAttempts = 60;
for (let i = 0; i < maxAttempts; i++) {
try {
await fetch(url);
break;
} catch {
if (i === maxAttempts - 1) {
console.error(`Server did not start within ${maxAttempts} seconds`);
server.kill();
process.exit(1);
}
await Bun.sleep(1000);
}
}
const electron = Bun.spawn(["bunx", "electron", "."], {
stdio: ["inherit", "inherit", "inherit"],
env: { ...Bun.env, BUN_DEV_SERVER_URL: url },
});
// When Electron closes, kill the server and exit
const exitCode = await electron.exited;
server.kill();
process.exit(exitCode);