chore: improve manifest generator (#125)

Make the manifest generator output nicer:
 - routes are sorted
 - manifest is sent through `deno fmt`
This commit is contained in:
Luca Casonato
2022-03-08 00:24:10 +01:00
committed by GitHub
parent 73fd41be31
commit e57e9c48f1
6 changed files with 69 additions and 57 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
// DO NOT EDIT. This file is generated by `fresh`.
// This file SHOULD be checked into source version control.
// To update this file, run `fresh routes`.
// To update this file, run `fresh manifest`.
import * as $0 from "./routes/index.tsx";
import * as $$0 from "./islands/Counter.tsx";
+1
View File
@@ -1,5 +1,6 @@
// std
export {
extname,
join,
resolve,
toFileUrl,
+28 -17
View File
@@ -1,4 +1,5 @@
import { join, resolve, toFileUrl, walk } from "./deps.ts";
import { extname, join, resolve, toFileUrl, walk } from "./deps.ts";
import { error } from "./error.ts";
const help = `fresh manifest
@@ -67,26 +68,23 @@ export async function manifest(directory: string) {
throw err;
}
}
routes.sort();
const islands = [];
try {
const islandsDir = join(directory, "./islands");
const islandsUrl = toFileUrl(islandsDir);
// TODO(lucacasonato): remove the extranious Deno.readDir when
// https://github.com/denoland/deno_std/issues/1310 is fixed.
for await (const _ of Deno.readDir(islandsDir)) {
// do nothing
}
const islandsFolder = walk(islandsDir, {
includeDirs: false,
includeFiles: true,
exts: ["tsx", "jsx", "ts", "js"],
});
for await (const entry of islandsFolder) {
if (entry.isFile) {
const file = toFileUrl(entry.path).href.substring(
islandsUrl.href.length,
for await (const entry of Deno.readDir(islandsDir)) {
if (entry.isDirectory) {
error(
`Found subdirectory '${entry.name}' in islands/. The islands/ folder must not contain any subdirectories.`,
);
}
if (entry.isFile) {
const ext = extname(entry.name);
if (![".tsx", ".jsx", ".ts", ".js"].includes(ext)) continue;
const path = join(islandsDir, entry.name);
const file = toFileUrl(path).href.substring(islandsUrl.href.length);
islands.push(file);
}
}
@@ -97,10 +95,11 @@ export async function manifest(directory: string) {
throw err;
}
}
islands.sort();
const output = `// DO NOT EDIT. This file is generated by \`fresh\`.
// This file SHOULD be checked into source version control.
// To update this file, run \`fresh routes\`.
// To update this file, run \`fresh manifest\`.
${
routes.map((file, i) => `import * as $${i} from "./routes${file}";`).join(
@@ -133,5 +132,17 @@ export default manifest;
const manifestPath = join(directory, "./fresh.gen.ts");
await Deno.writeTextFile(manifestPath, output);
console.log("Manifest generated and written to", manifestPath);
const proc = Deno.run({
cmd: [Deno.execPath(), "fmt", manifestPath],
stdin: "null",
stdout: "null",
stderr: "null",
});
await proc.status();
proc.close();
console.log(
`%cThe manifest has been generated for ${routes.length} routes and ${islands.length} islands.`,
"color: blue; font-weight: bold",
);
}
+33 -33
View File
@@ -1,43 +1,43 @@
// DO NOT EDIT. This file is generated by `fresh`.
// This file SHOULD be checked into source version control.
// To update this file, run `fresh routes`.
// To update this file, run `fresh manifest`.
import * as $0 from "./routes/index.tsx";
import * as $1 from "./routes/params.tsx";
import * as $2 from "./routes/static.tsx";
import * as $3 from "./routes/intercept_args.tsx";
import * as $4 from "./routes/_render.ts";
import * as $5 from "./routes/props/[id].tsx";
import * as $6 from "./routes/failure.ts";
import * as $7 from "./routes/_middleware.ts";
import * as $8 from "./routes/books/[id].tsx";
import * as $9 from "./routes/wildcard.tsx";
import * as $10 from "./routes/api/get_only.ts";
import * as $11 from "./routes/_500.tsx";
import * as $12 from "./routes/intercept.tsx";
import * as $13 from "./routes/_404.tsx";
import * as $14 from "./routes/[name].tsx";
import * as $15 from "./routes/_app.tsx";
import * as $0 from "./routes/[name].tsx";
import * as $1 from "./routes/_404.tsx";
import * as $2 from "./routes/_500.tsx";
import * as $3 from "./routes/_app.tsx";
import * as $4 from "./routes/_middleware.ts";
import * as $5 from "./routes/_render.ts";
import * as $6 from "./routes/api/get_only.ts";
import * as $7 from "./routes/books/[id].tsx";
import * as $8 from "./routes/failure.ts";
import * as $9 from "./routes/index.tsx";
import * as $10 from "./routes/intercept.tsx";
import * as $11 from "./routes/intercept_args.tsx";
import * as $12 from "./routes/params.tsx";
import * as $13 from "./routes/props/[id].tsx";
import * as $14 from "./routes/static.tsx";
import * as $15 from "./routes/wildcard.tsx";
import * as $$0 from "./islands/Test.tsx";
const manifest = {
routes: {
"./routes/index.tsx": $0,
"./routes/params.tsx": $1,
"./routes/static.tsx": $2,
"./routes/intercept_args.tsx": $3,
"./routes/_render.ts": $4,
"./routes/props/[id].tsx": $5,
"./routes/failure.ts": $6,
"./routes/_middleware.ts": $7,
"./routes/books/[id].tsx": $8,
"./routes/wildcard.tsx": $9,
"./routes/api/get_only.ts": $10,
"./routes/_500.tsx": $11,
"./routes/intercept.tsx": $12,
"./routes/_404.tsx": $13,
"./routes/[name].tsx": $14,
"./routes/_app.tsx": $15,
"./routes/[name].tsx": $0,
"./routes/_404.tsx": $1,
"./routes/_500.tsx": $2,
"./routes/_app.tsx": $3,
"./routes/_middleware.ts": $4,
"./routes/_render.ts": $5,
"./routes/api/get_only.ts": $6,
"./routes/books/[id].tsx": $7,
"./routes/failure.ts": $8,
"./routes/index.tsx": $9,
"./routes/intercept.tsx": $10,
"./routes/intercept_args.tsx": $11,
"./routes/params.tsx": $12,
"./routes/props/[id].tsx": $13,
"./routes/static.tsx": $14,
"./routes/wildcard.tsx": $15,
},
islands: {
"./islands/Test.tsx": $$0,
+1 -1
View File
@@ -1,6 +1,6 @@
// DO NOT EDIT. This file is generated by `fresh`.
// This file SHOULD be checked into source version control.
// To update this file, run `fresh routes`.
// To update this file, run `fresh manifest`.
import * as $0 from "./routes/index.tsx";
+5 -5
View File
@@ -1,18 +1,18 @@
// DO NOT EDIT. This file is generated by `fresh`.
// This file SHOULD be checked into source version control.
// To update this file, run `fresh routes`.
// To update this file, run `fresh manifest`.
import * as $0 from "./routes/_render.ts";
import * as $1 from "./routes/gfm.css.ts";
import * as $2 from "./routes/docs/[...slug].tsx";
import * as $1 from "./routes/docs/[...slug].tsx";
import * as $2 from "./routes/gfm.css.ts";
import * as $3 from "./routes/index.tsx";
import * as $$0 from "./islands/Counter.tsx";
const manifest = {
routes: {
"./routes/_render.ts": $0,
"./routes/gfm.css.ts": $1,
"./routes/docs/[...slug].tsx": $2,
"./routes/docs/[...slug].tsx": $1,
"./routes/gfm.css.ts": $2,
"./routes/index.tsx": $3,
},
islands: {