diff --git a/scripts/routes.ts b/scripts/routes.ts index c02c78d..3efee1b 100644 --- a/scripts/routes.ts +++ b/scripts/routes.ts @@ -1,7 +1,7 @@ import { join, relative, ensureFileSync, wait, S3 } from "../deps.ts"; import Pika from "../utils/instances/pika.ts"; -const ROUTES_FILE = "routes.generated.ts"; +const ROUTES_FILE = "routes.ts"; const S3inner = wait({ text: `Generating ${ROUTES_FILE}...`, @@ -39,7 +39,7 @@ async function readDir(dir: URL): Promise { ).replace(/(\.ts)|(\.js)|(\/index(\.ts|\.js))/, "") .replace(/[\\/]+/g, '/') - const filePath = `./${relativePath}`; + const filePath = `../${relativePath}`; const replaced = route.replace("/../src/routes", "") let finalRoute = replaced; if (replaced.includes('index') && !replaced.startsWith("/index")) @@ -62,15 +62,15 @@ async function readDir(dir: URL): Promise { function createFile(routes: PageRoute[]): string { let string = - `// This File is Autogenerated by scripts/routes.ts + `// This File is generated by scripts/routes.ts // Do not edit this File manually // run \`vr routes\` to regenerate this File -import PageRoute from "../utils/types/PageRoute.ts" +import PageRoute from "../../utils/types/PageRoute.ts" ${routes.map((route) => ( `import ${route.name} from "${route.path.replace(/[\\/]+/g, '/')}";`).replace('./../src', ".")).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 ")} +const routes: PageRoute[] = [\n ${routes.map((route) => (`{ route: "${route.route}", method: ${route.name}.method, handler: ${route.name}.handler, domains: ${route.name}.domains || undefined }`)).join(",\n ")} ] @@ -87,14 +87,14 @@ async function write(folderwithroutes: string | URL, file: string | URL) { const routes = await readDir(folderwithroutes) const content = createFile(routes) - await Deno.writeTextFile(`./src/${file}`, content) + await Deno.writeTextFile(`./src/generated/${file}`, content) } if (import.meta.main) { try { - ensureFileSync(`./src/${ROUTES_FILE}`) + ensureFileSync(`./src/generated/${ROUTES_FILE}`) await write('../src/routes', ROUTES_FILE) } catch (error) { console.error(error) diff --git a/scripts/s3.ts b/scripts/s3.ts index cbe2a70..ed003d5 100644 --- a/scripts/s3.ts +++ b/scripts/s3.ts @@ -1,5 +1,5 @@ import { string } from "https://raw.githubusercontent.com/soremwar/deno_types/b5a146610e2c97c1612371fcf610b541f950ee73/prop-types/v15.7.2/prop-types.d.ts"; -import { S3, S3Bucket } from "../deps.ts"; +import { ensureFileSync, S3, S3Bucket } from "../deps.ts"; import { wait } from "../deps.ts" const S3inner = wait({ @@ -44,7 +44,7 @@ for await (const obj of list) { function createFile(files: S3File[]) { let string = - `// This File is Autogenerated by scripts/routes.ts + `// This File is generated by scripts/s3.ts // Do not edit this File manually // run \`vr s3\` to regenerate this File @@ -69,7 +69,8 @@ async function write(files: S3File[], file: string | URL) { if (import.meta.main) { try { - await write(Files, `s3.generated.ts`) + ensureFileSync(`./src/generated/s3.ts`) + await write(Files, `generated/s3.ts`) } catch (error) { console.error(error) S3inner.fail()