Add single-binary build and --port flag

bun build --compile bundles the app and Bun runtime into bin/job-board
(plus linux-x64/arm64 targets). New src/main.ts entry: serve (default)
or 'scrape' once, with --port/-p overriding PORT. A compiled binary
stores its database in data/ next to the executable.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-12 21:37:34 +02:00
co-authored by Claude Opus 5.5
parent ad2fa2b775
commit beac32469c
5 changed files with 94 additions and 6 deletions
+41
View File
@@ -0,0 +1,41 @@
// Entry point (also used by the compiled binary):
// job-board [serve] [--port <n>] start the web server (scrapes every 24h)
// job-board scrape run all scrapers once and exit (exit code 1 if any failed)
export {};
const USAGE = "Usage: job-board [serve] [--port <n>] | job-board scrape";
function fail(message: string): never {
console.error(`${message}\n${USAGE}`);
process.exit(2);
}
const args = process.argv.slice(2);
let command: string | undefined;
for (let i = 0; i < args.length; i++) {
const arg = args[i]!;
if (arg === "--port" || arg === "-p" || arg.startsWith("--port=")) {
const value = arg.startsWith("--port=") ? arg.slice("--port=".length) : args[++i];
const port = Number(value);
if (!Number.isInteger(port) || port < 1 || port > 65535) fail(`Invalid port "${value ?? ""}".`);
process.env.PORT = String(port); // read by server.ts; overrides the PORT env var
} else if (arg === "--help" || arg === "-h") {
console.log(USAGE);
process.exit(0);
} else if (!command && !arg.startsWith("-")) {
command = arg;
} else {
fail(`Unknown argument "${arg}".`);
}
}
if (command === "scrape") {
const { runAllScrapers } = await import("./scrape");
const results = await runAllScrapers();
process.exit(results.some((r) => r.error) ? 1 : 0);
} else if (command === undefined || command === "serve") {
await import("./server");
} else {
fail(`Unknown command "${command}".`);
}