// `ctl-dev-kit dashboard-manifest `: a fleet dashboard's build // step (task 122 K). Writes `/dashboard.json`, which norsk-mgr reads at // upload for what the dashboard uses, from the calls in ``. import { mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs"; import { join, relative } from "node:path"; import { dashboardUses, type UsesResult } from "./uses.ts"; const SOURCE = /\.(m?[jt]sx?)$/; const TEST = /\.(test|spec)\.[^.]+$/; function sources(dir: string): string[] { const out: string[] = []; for (const name of readdirSync(dir)) { if (name === "node_modules") continue; const full = join(dir, name); if (statSync(full).isDirectory()) out.push(...sources(full)); else if (SOURCE.test(name) && !TEST.test(name)) out.push(full); } return out; } export function writeDashboardManifest(srcDir: string, distDir: string): UsesResult { const files = sources(srcDir).map((path) => ({ path: relative(srcDir, path), source: readFileSync(path, "utf8") })); const uses = dashboardUses(files); if (uses.status === "error") return uses; mkdirSync(distDir, { recursive: true }); writeFileSync(join(distDir, "dashboard.json"), `${JSON.stringify({ uses: uses.value }, null, 2)}\n`); return uses; }