Skip to content

Commit 424a0b7

Browse files
committed
chore: improve routes tree printing
1 parent 845d419 commit 424a0b7

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

packages/pranx/src/cmd/build.ts

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
PageModule,
1313
SERVER_MANIFEST,
1414
ServerEntryModule,
15+
ServerManifestRoute,
1516
} from "../../types/index.js";
1617
import { bundle_browser } from "../build/bundle/browser.js";
1718
import { bundle_server } from "../build/bundle/server.js";
@@ -283,13 +284,19 @@ params returned by getStaticPaths: ${JSON.stringify(static_path.params)}`);
283284

284285
const BUILD_TIME = measureTime("build_measure_time");
285286

287+
printRoutesTreeForUser(site_manifest.routes);
288+
289+
logger.success(`Project builded in ${BUILD_TIME} ms\n`);
290+
}
291+
292+
export function printRoutesTreeForUser(input_routes: ServerManifestRoute[]) {
286293
// Loggin Routes
287294
logger.log(kleur.bold().blue().underline("Routes"));
288295

289-
function buildTree(routes: typeof site_manifest.routes) {
296+
function buildTree(routes: ServerManifestRoute[]) {
290297
const tree: any = {};
291298
for (const route of routes) {
292-
const parts = route.path.split("/").filter(Boolean);
299+
const parts = route.path === "/" ? [] : route.path.split("/").filter(Boolean);
293300
let node = tree;
294301
for (const part of parts) {
295302
node.children = node.children || {};
@@ -301,11 +308,20 @@ params returned by getStaticPaths: ${JSON.stringify(static_path.params)}`);
301308
return tree;
302309
}
303310

304-
logger.log(`${kleur.white(".")}`);
305311
function printTree(node: any, prefix = "", isLast = true) {
306312
if (node.route) {
307313
const icon = node.route.rendering_kind === "static" ? "●" : kleur.yellow("λ");
308-
logger.log(`${prefix}${isLast ? "└-" : "├-"} ${icon} ${kleur.white(node.route.path)}`);
314+
let extra = "";
315+
if (
316+
node.route.rendering_kind === "static" &&
317+
node.route.static_generated_routes &&
318+
node.route.static_generated_routes.length > 0
319+
) {
320+
extra = ` (${kleur.cyan(`${node.route.static_generated_routes.length}`)})`;
321+
}
322+
logger.log(
323+
`${prefix}${isLast ? "└-" : "├-"} ${icon} ${kleur.white(node.route.path)}${extra}`
324+
);
309325
}
310326
if (node.children) {
311327
const keys = Object.keys(node.children);
@@ -315,16 +331,12 @@ params returned by getStaticPaths: ${JSON.stringify(static_path.params)}`);
315331
}
316332
}
317333

318-
const tree = buildTree(site_manifest.routes);
334+
const tree = buildTree(input_routes);
319335

320-
if (tree.children) {
321-
const keys = Object.keys(tree.children);
322-
keys.forEach((key, idx) => {
323-
printTree(tree.children[key], "", idx === keys.length - 1);
324-
});
325-
}
336+
logger.log(".");
337+
printTree(tree, "", true);
326338

327-
logger.log(`\n● Static Page \n${kleur.yellow("λ")} Server-side Page\n`);
328-
329-
logger.success(`Project builded in ${BUILD_TIME} ms\n`);
339+
logger.log(`\n${kleur.yellow("λ")} Server-side Page`);
340+
logger.log("● Static Page");
341+
logger.log(`${kleur.cyan("(#)")} Count of Static Generated Routes\n`);
330342
}

0 commit comments

Comments
 (0)