fix formatting in script generator
This commit is contained in:
parent
6a5b4422b2
commit
e47aadccb1
1 changed files with 9 additions and 17 deletions
|
@ -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<PageRoute[]> {
|
|||
|
||||
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<PageRoute[]> {
|
|||
|
||||
|
||||
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
|
||||
|
|
Loading…
Add table
Reference in a new issue