// Entry point (also used by the compiled binary): // job-board [serve] [--host ] [--port ] 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] [--host ] [--port ] | job-board scrape\n --host address to listen on (default 127.0.0.1; 0.0.0.0 = all interfaces)\n --port port to listen on (default 3000)"; 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 === "--host" || arg.startsWith("--host=")) { const value = arg.startsWith("--host=") ? arg.slice("--host=".length) : args[++i]; if (!value || value.startsWith("-")) fail(`Invalid host "${value ?? ""}".`); process.env.JOB_BOARD_HOST = value; // read by server.ts; overrides the 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}".`); }