Skip to content

Commit 4bf32f5

Browse files
committed
chore: add deno task server helper (build + run with --browser)
- add scripts/server.ts that builds mailbrus-server (debug) and starts it with --browser, cleaning up on SIGINT/SIGTERM - wire it as `deno task server` in deno.json
1 parent cb6d591 commit 4bf32f5

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

deno.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"dev": "vite dev",
66
"build": "vite build",
77
"preview": "vite preview",
8+
"server": "deno run --allow-read --allow-write --allow-run --allow-env --allow-net scripts/server.ts",
89
"e2e:generate": "deno run -A e2e/fixtures/generate.ts",
910
"test:e2e": "node_modules/.bin/playwright test --config=e2e/playwright.config.ts --project=chromium",
1011
"e2e:ui": "node_modules/.bin/playwright test --config=e2e/playwright.config.ts --ui",

scripts/server.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env -S deno run --allow-read --allow-write --allow-run --allow-env --allow-net
2+
/**
3+
* Build and start mailbrus-server with --browser for local development.
4+
*
5+
* deno task server
6+
*
7+
* Builds the server binary (debug), starts it with --browser, and opens
8+
* the default web browser. Ctrl-C stops the server cleanly.
9+
*/
10+
11+
const ROOT = new URL("..", import.meta.url).pathname.replace(/\/$/, "");
12+
const SERVER_BIN = `${ROOT}/target/debug/mailbrus-server`;
13+
14+
function log(msg: string) {
15+
console.log(`[server] ${msg}`);
16+
}
17+
18+
async function build(): Promise<boolean> {
19+
log("building mailbrus-server (debug)…");
20+
const { success } = await new Deno.Command("cargo", {
21+
args: ["build", "-p", "mailbrus-server"],
22+
cwd: ROOT,
23+
stdout: "inherit",
24+
stderr: "inherit",
25+
}).output();
26+
return success;
27+
}
28+
29+
function start(proc: Deno.ChildProcess) {
30+
proc.status.then((s) => {
31+
log(`server exited with code ${s.code}`);
32+
Deno.exit(s.code ?? 1);
33+
}).catch(() => {});
34+
}
35+
36+
if (!await build()) {
37+
log("build failed");
38+
Deno.exit(1);
39+
}
40+
41+
log("starting server with --browser");
42+
const child = new Deno.Command(SERVER_BIN, {
43+
args: ["--browser"],
44+
cwd: ROOT,
45+
stdout: "inherit",
46+
stderr: "inherit",
47+
}).spawn();
48+
49+
start(child);
50+
51+
const stop = () => {
52+
log("shutting down…");
53+
try { child.kill("SIGTERM"); } catch { /* already gone */ }
54+
};
55+
Deno.addSignalListener("SIGINT", stop);
56+
Deno.addSignalListener("SIGTERM", stop);
57+
58+
await child.status;

0 commit comments

Comments
 (0)