This commit is contained in:
Luca Casonato
2021-05-08 02:07:24 +02:00
parent f05c2e3a68
commit 6ecdf2ed73
17 changed files with 284 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
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);