Files
sweet/cli.ts
T
2021-05-08 02:07:24 +02:00

28 lines
764 B
TypeScript

import { join, toFileUrl } from "https://deno.land/std@0.95.0/path/mod.ts";
import { walk } from "https://deno.land/std@0.95.0/fs/walk.ts";
const files = [];
const pagesDir = join(Deno.cwd(), "./pages");
const pagesUrl = new URL(pagesDir, "file:///");
for await (
const entry of walk(pagesDir, {
includeDirs: false,
includeFiles: true,
exts: ["tsx", "jsx"],
})
) {
if (entry.isFile) {
const file = toFileUrl(entry.path).href.substring(pagesUrl.href.length);
files.push(file);
}
}
const output = `import { setup } from "../server.ts";
${files.map((file, i) => `import * as $${i} from "./pages${file}";`).join("\n")}
setup([${files.map((_, i) => `$${i}`).join(", ")}], import.meta.url);
`;
Deno.writeTextFile("./server.ts", output);