-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdev.ts
More file actions
46 lines (38 loc) · 1.2 KB
/
dev.ts
File metadata and controls
46 lines (38 loc) · 1.2 KB
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
38
39
40
41
42
43
44
45
46
/**
* 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 host = "127.0.0.1";
const port = Number(Bun.env.OPENGUI_VITE_PORT || 5173);
const url = `http://${host}:${port}`;
const build = Bun.spawnSync(["bun", "scripts/build-electron.ts"], {
stdio: ["inherit", "inherit", "inherit"],
});
if (!build.success) process.exit(build.exitCode);
const server = Bun.spawn(["vp", "dev", "--host", host, "--port", String(port)], {
stdio: ["inherit", "inherit", "inherit"],
env: { ...Bun.env, OPENGUI_SKIP_WEB_BACKEND: "1" },
});
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(["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);