// deno-lint-ignore no-import-prefix import { serveDir } from "jsr:@std/http@1.0.21/file-server"; type Addr = { hostname: string; port: number; }; function alertListening(addr: Addr) { console.log(`Listening on http://${addr.hostname}:${addr.port}/`); } async function buildDocs() { console.log("building docs"); await new Deno.Command("deno", { args: ["task", "build"], cwd: "docs", }).output(); console.log("done"); } async function watchAndBuildDocs() { let changeOccurred = true; let running = false; setInterval(async () => { if (!changeOccurred || running) { return; } running = true; await buildDocs(); changeOccurred = false; running = false; }, 250); const watcher = Deno.watchFs(["docs/src"]); for await (const _ of watcher) { changeOccurred = true; } } function serveDist(addr: Addr) { Deno.serve({ port: addr.port, hostname: addr.hostname, onListen: (_) => alertListening(addr), }, (req: Request) => { return serveDir(req, { quiet: true, showIndex: true }); }); } if (import.meta.main) { await buildDocs(); watchAndBuildDocs(); serveDist({ hostname: "0.0.0.0", port: 8180, }); }