import { spawn } from "bun";
// Ensure dist/ has the HTML shell
await Bun.write(
"./dist/index.html",
`
Dungeon Crawl — Ranged / Melee
`
);
// Start build watcher
const builder = spawn(["bun", "build", "src/main.ts", "--outdir", "dist", "--target", "browser", "--watch"], {
stdout: "inherit",
stderr: "inherit",
});
// Start dev server
const port = 3000;
const server = Bun.serve({
port,
async fetch(req) {
const url = new URL(req.url);
let path = url.pathname === "/" ? "/index.html" : url.pathname;
const file = Bun.file("./dist" + path);
return new Response(file);
},
});
console.log(`\n Dev server: http://localhost:${port}`);
console.log(` Watching: src/\n`);
// Graceful shutdown
process.on("SIGINT", () => {
builder.kill();
server.stop();
process.exit(0);
});