-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod.ts
More file actions
27 lines (24 loc) · 795 Bytes
/
mod.ts
File metadata and controls
27 lines (24 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { serve } from "https://deno.land/std@0.192.0/http/server.ts";
import { serveDir } from "https://deno.land/std@0.192.0/http/file_server.ts";
export type Route = {
[key: string]: string | Route;
};
export async function generate(route: Route, basePath = "pub") {
let bp = basePath;
bp = bp.endsWith("/") ? bp : (bp + "/");
await Deno.mkdir(bp, { recursive: true });
const keys = Object.keys(route);
for (const key of keys) {
const value = route[key];
const p = bp + key;
if (typeof value === "string") {
await Deno.writeTextFile(p, value);
continue;
}
await generate(value, p);
}
}
export async function dev(route: Route, basePath = "pub") {
await generate(route, basePath);
await serve((req) => serveDir(req, { fsRoot: basePath }));
}