printRoutes

tcmts.cli.web.printRoutes · #p4mdwlep · term · runs on the server

uses tcmts.cli.style.dim, which uses node:util

import type { Codebase } from "#codebase/tcmts/cli/codebase";
import { dim } from "#codebase/tcmts/cli/style";
import type { HttpRoutes } from "#codebase/tcmts/cli/web";

export function printRoutes(cb: Codebase, routes: HttpRoutes, url: string) {
  const names = cb.store
    .names()
    .filter((n) => n.kind === "term" && n.path.startsWith(routes.namespace + "."));
  if (!names.length)
    return console.log(
      `  http     ${dim(`nothing under ${routes.namespace} yet (it would be served at ${routes.prefix}/…)`)}`,
    );
  for (const n of names) {
    const segs = n.path.slice(routes.namespace.length + 1).split(".");
    const p = segs.join("/") === "index" ? routes.prefix : `${routes.prefix}/${segs.join("/")}`;
    // (under the app's base, as url ends: `.${p}`, not p, which would leave it out)
    console.log(`  http     ${new URL(`.${p}`, url).href} ${dim(`→ ${n.path}`)}`);
  }
}

uses

used by