Redo Route generation, use Pika for unique import

This commit is contained in:
Joshua 2022-09-18 15:07:21 +02:00
parent 1c1ec2f6bc
commit 7e8891f706

View file

@ -1,4 +1,6 @@
import { join, relative, ensureFileSync, wait, S3 } from "../deps.ts";
import Pika from "../utils/instances/pika.ts";
const ROUTES_FILE = "routes.generated.ts";
const S3inner = wait({
@ -7,6 +9,7 @@ const S3inner = wait({
})
interface PageRoute {
name: string;
path: string;
route: string;
}
@ -47,6 +50,7 @@ async function readDir(dir: URL): Promise<PageRoute[]> {
S3inner.text = `Added ${finalRoute}`
routes.push({
name: Pika.gen("route"),
route: finalRoute,
path: filePath,
});
@ -63,10 +67,10 @@ function createFile(routes: PageRoute[]): string {
// run \`vr routes\` to regenerate this File
import PageRoute from "../utils/types/PageRoute.ts"
${routes.map((route, index) => (
`import { method as method_${index}, handler as handler_${index} } from "${route.path.replace(/[\\/]+/g, '/')}";`).replace('./../src', ".")).join("\n")}
${routes.map((route) => (
`import ${route.name} from "${route.path.replace(/[\\/]+/g, '/')}";`).replace('./../src', ".")).join("\n")}
const routes: PageRoute[] = [\n ${routes.map((route, index) => (`{ method: method_${index}, handler: handler_${index}, route: "${route.route}" }`)).join(",\n ")}
const routes: PageRoute[] = [\n ${routes.map((route) => (`{ method: ${route.name}.method, handler: ${route.name}.handler, domains: ${route.name}.domains || undefined, route: "${route.route}" }`)).join(",\n ")}
]