From 29bcdc6c1bad2240d404de9dca2463e46fdc1e93 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Fri, 17 Mar 2023 02:10:54 +0900 Subject: refactor: split command.ts --- nuldoc-src/commands/serve.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 nuldoc-src/commands/serve.ts (limited to 'nuldoc-src/commands/serve.ts') diff --git a/nuldoc-src/commands/serve.ts b/nuldoc-src/commands/serve.ts new file mode 100644 index 0000000..b66ad2d --- /dev/null +++ b/nuldoc-src/commands/serve.ts @@ -0,0 +1,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, + }); + }); +} -- cgit v1.2.3-70-g09d2