From 7e8891f70660a38d66d470a4f036f571103d4829 Mon Sep 17 00:00:00 2001 From: Joshua Date: Sun, 18 Sep 2022 15:07:21 +0200 Subject: [PATCH] Redo Route generation, use Pika for unique import --- scripts/routes.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/routes.ts b/scripts/routes.ts index 684ff7c..c02c78d 100644 --- a/scripts/routes.ts +++ b/scripts/routes.ts @@ -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 { 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 ")} ]