runFmt
uses tcmts.cli.main.execute, which uses tcmts.cli.help.usageError, which uses tcmts.cli.help.usageOf, which uses tcmts.cli.style.bold, which uses node:util
Runs tcm fmt.
import { routeFmt } from "#codebase/tcmts/cli/commands"; import { formatStored } from "#codebase/tcmts/cli/fmt"; import { inLibrary, librariesIn } from "#codebase/tcmts/cli/libraries"; import { execute } from "#codebase/tcmts/cli/main"; import type { Context } from "#codebase/tcmts/cli/run"; import { dim, green, yellow } from "#codebase/tcmts/cli/style"; import { shortHash } from "#codebase/tcmts/core/hash"; import { parse } from "@bomb.sh/router"; export function runFmt({ cb, cmd, rest }: Context): number { const { model } = execute(cmd, parse(routeFmt(), { argv: rest })); const ns = model.namespace ?? ""; // (a library reads as it was released: what it names, under any name, is left as it is) const libraries = librariesIn(cb.store); const hashes = cb.store .names() .filter((n) => !ns || n.path === ns || n.path.startsWith(ns + ".")) .map((n) => n.hash) .filter((h) => !cb.store.pathsOf(h).some((p) => inLibrary(libraries, p))); const r = formatStored(cb, [...new Set(hashes)]); for (const h of r.formatted) console.log(` ${green("~")} ${cb.store.pathsOf(h).join(", ") || shortHash(h)}`); for (const h of r.skipped) console.log( yellow( ` skipped ${cb.store.pathsOf(h)[0] ?? shortHash(h)}: formatting it would change its hash (please report this)`, ), ); console.log( `${r.formatted.length ? `reformatted ${r.formatted.length} definition(s)` : green("everything is formatted")}${dim(`; no hashes changed`)}`, ); if (r.formatted.length) cb.refreshShim(true); return r.skipped.length ? 1 : 0; }
uses
- tcmts.cli.commands.routeFmt
- tcmts.cli.fmt.formatStored
- tcmts.cli.libraries.inLibrary
- tcmts.cli.libraries.librariesIn
- tcmts.cli.main.execute
- tcmts.cli.run.Context
- tcmts.cli.style.dim
- tcmts.cli.style.green
- tcmts.cli.style.yellow
- tcmts.core.hash.shortHash