aboutsummaryrefslogtreecommitdiffhomepage
path: root/nuldoc-src/commands/serve.ts
blob: b66ad2d1e1535407b732a7c416337564f8b1931c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { join } from "std/path/mod.ts";
import { serveDir } from "std/http/file_server.ts";
import { serve } from "std/http/server.ts";
import { Config } from "../config.ts";

export function runServeCommand(config: Config) {
  const rootDir = join(Deno.cwd(), config.locations.destDir);
  serve(async (req) => {
    const pathname = new URL(req.url).pathname;
    if (!pathname.endsWith("css") && !pathname.endsWith("svg")) {
      const p = Deno.run({
        cmd: ["./nuldoc", "build"],
      });
      await p.status();
      console.log("rebuild");
    }
    return serveDir(req, {
      fsRoot: rootDir,
      showIndex: true,
    });
  });
}