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";
|
import { join, relative, ensureFileSync } from "../deps.ts";
|
||||||
|
|
||||||
const ROUTES_FILE = "routes.generated.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 {
|
interface PageRoute {
|
||||||
path: string;
|
path: string;
|
||||||
route: string;
|
route: string;
|
||||||
|
@ -30,7 +28,7 @@ async function readDir(dir: URL): Promise<PageRoute[]> {
|
||||||
|
|
||||||
const route = "/" + relativePath.replaceAll(
|
const route = "/" + relativePath.replaceAll(
|
||||||
/\[(.*?)\]/g,
|
/\[(.*?)\]/g,
|
||||||
":$1",
|
"{$1}",
|
||||||
).replace(/(\.ts)|(\.js)|(\/index(\.ts|\.js))/, "")
|
).replace(/(\.ts)|(\.js)|(\/index(\.ts|\.js))/, "")
|
||||||
.replace(/[\\/]+/g, '/')
|
.replace(/[\\/]+/g, '/')
|
||||||
|
|
||||||
|
@ -54,23 +52,17 @@ async function readDir(dir: URL): Promise<PageRoute[]> {
|
||||||
|
|
||||||
|
|
||||||
function createFile(routes: PageRoute[]): string {
|
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
|
// Do not edit this File manually
|
||||||
// run \`vr routes\` to regenerate this File
|
// 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 {
|
const routes: PageRoute[] = [\n ${routes.map((route, index) => (`{ method: method_${index}, handler: handler_${index}, route: "${route.route}" }`)).join(",\n ")}
|
||||||
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 ")}
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
export default routes
|
export default routes
|
||||||
|
|
Loading…
Add table
Reference in a new issue