Skip to content

Commit cd6d270

Browse files
committed
feat: add simple routes logger
1 parent 84b5188 commit cd6d270

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

packages/pranx/src/cmd/build.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { filePathToRoutingPath } from "@/build/filepath-to-routing-path";
22
import { get_user_pranx_config, load_user_pranx_config } from "@/config/index";
3+
import { log_routes_simple } from "@/log/log-routes-simple.js";
34
import { logger } from "@/log/logger.js";
45
import { measureTime } from "@/utils/time-perf";
56
import fse from "fs-extra";
@@ -24,7 +25,6 @@ import {
2425
SITE_MANIFEST_OUTPUT_PATH,
2526
} from "../build/constants.js";
2627
import { generate_html_template } from "../build/generate_html_template.js";
27-
import { log_routes_tree } from "../log/log_routes_tree.js";
2828

2929
export async function build() {
3030
logger.log(kleur.bold().magenta("Pranx Build\n"));
@@ -335,7 +335,7 @@ export async function build() {
335335

336336
const BUILD_TIME = measureTime("build_measure_time");
337337

338-
log_routes_tree(server_site_manifest.routes);
338+
log_routes_simple(server_site_manifest.routes);
339339

340340
logger.success(`Project builded in ${BUILD_TIME} ms\n`);
341341
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import kleur from "kleur";
2+
import type { ServerManifestRoute } from "types";
3+
import { logger } from "./logger";
4+
5+
type LogRouteKind = "static" | "static-dynamic" | "server-side";
6+
7+
const ICONS = {
8+
server: () => kleur.yellow("λ"),
9+
static: () => kleur.white("○"),
10+
staticDyn: () => kleur.white("●"),
11+
folder: () => kleur.white("┬"),
12+
};
13+
14+
const getKindIcon = (kind: LogRouteKind) =>
15+
kind === "server-side" ? ICONS.server() : kind === "static" ? ICONS.static() : ICONS.staticDyn();
16+
17+
export function log_routes_simple(input_routes: ServerManifestRoute[]) {
18+
logger.log(kleur.bold().blue().underline("Routes"));
19+
logger.log(".");
20+
21+
let index = 0;
22+
for (const r of input_routes) {
23+
if (r.static_generated_routes.length > 0) {
24+
for (const sr of r.static_generated_routes) {
25+
logger.log(`├─ ${getKindIcon("static-dynamic")} ${sr.path}`);
26+
}
27+
index++;
28+
continue;
29+
}
30+
31+
if (index === input_routes.length - 1) {
32+
logger.log(`└─ ${getKindIcon(r.rendering_kind)} ${r.path}`);
33+
continue;
34+
}
35+
logger.log(`├─ ${getKindIcon(r.rendering_kind)} ${r.path}`);
36+
37+
// "└─" : "├─";
38+
// "│ "
39+
40+
index++;
41+
}
42+
43+
logger.log("");
44+
logger.log(`${ICONS.server()} Server-side`);
45+
logger.log(`${ICONS.static()} Static`);
46+
logger.log(`${ICONS.staticDyn()} Static with dynamic params\n`);
47+
}

packages/pranx/src/log/log_routes_tree.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** biome-ignore-all lint/style/noNonNullAssertion: <explanation> */
1+
/** biome-ignore-all lint/style/noNonNullAssertion: <> */
22
import kleur from "kleur";
33
import type { ServerManifestRoute } from "types";
44
import { logger } from "./logger";

0 commit comments

Comments
 (0)