From e47aadccb1dc4d9f3b4f6e5cb725d22c543d4f5c Mon Sep 17 00:00:00 2001 From: Joshua Date: Wed, 14 Sep 2022 23:27:01 +0200 Subject: [PATCH] fix formatting in script generator --- scripts/routes.ts | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/scripts/routes.ts b/scripts/routes.ts index da654c7..8f3c1b8 100644 --- a/scripts/routes.ts +++ b/scripts/routes.ts @@ -1,9 +1,7 @@ import { join, relative, ensureFileSync } from "../deps.ts"; const ROUTES_FILE = "routes.generated.ts"; -// const ROUTES_PATH = "../src" -// An object that links a file to a route -// api/auth/token/index.ts -> /api/auth/token + interface PageRoute { path: string; route: string; @@ -30,7 +28,7 @@ async function readDir(dir: URL): Promise { const route = "/" + relativePath.replaceAll( /\[(.*?)\]/g, - ":$1", + "{$1}", ).replace(/(\.ts)|(\.js)|(\/index(\.ts|\.js))/, "") .replace(/[\\/]+/g, '/') @@ -54,23 +52,17 @@ async function readDir(dir: URL): Promise { function createFile(routes: PageRoute[]): string { - let string = `// This File is Autogenerated by scripts/routes.ts + let string = + `// This File is Autogenerated by scripts/routes.ts // Do not edit this File manually // run \`vr routes\` to regenerate this File -${routes.map((route, index) => (`import { method as method_${index}, handler as handler_${index} } from "${route.path.replace(/[\\/]+/g, '/')}";`).replace('./../src', ".")).join("\n")} +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")} -interface PageRoute { - method: string | string[] - handler: void | any - route: string -} - -const routes: PageRoute[] = [ - ${routes.map((route, index) => ( - `{ method: method_${index}, handler: handler_${index}, route: "${route.route}"}` - )).join(",\n ")} - ] +const routes: PageRoute[] = [\n ${routes.map((route, index) => (`{ method: method_${index}, handler: handler_${index}, route: "${route.route}" }`)).join(",\n ")} +] export default routes