#!/usr/bin/env node // Builds the authoritative inventory of Web FreeCAD UI surfaces: every shell // region, dock, task panel, dialog, preference page, menu, toolbar, status bar // item and viewport tool, paired with its React owner and desktop source. // // node tools/fcweb/ui-surface-inventory.mjs // node tools/fcweb/ui-surface-inventory.mjs --stable # reproducible bytes // node tools/fcweb/ui-surface-inventory.mjs --check # compare, exit 1 on drift import fs from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { scanSurfaces } from "./ui-surface-scan.mjs"; const here = path.dirname(fileURLToPath(import.meta.url)); const repoRoot = path.resolve(here, "../.."); const desktopRoot = path.join(repoRoot, "freecad-source"); const webSrcRoot = path.join(repoRoot, "web", "src"); const args = process.argv.slice(2); const argValue = (name, fallback) => { const index = args.indexOf(name); return index >= 0 && args[index + 1] ? args[index + 1] : fallback; }; const inventoryPath = path.resolve(argValue("--inventory", path.join(here, "out", "ui-inventory.json"))); const outPath = path.resolve(argValue("--out", path.join(here, "out", "ui-surface-inventory.json"))); const stable = args.includes("--stable") || args.includes("--check"); const fail = (message, code = 2) => { console.error(`[ui-surface-inventory] ${message}`); process.exit(code); }; if (!fs.existsSync(inventoryPath)) fail(`missing inventory: ${inventoryPath} (run ui-inventory.mjs first)`); const inventory = JSON.parse(fs.readFileSync(inventoryPath, "utf8")); const manualFeaturesPath = path.join(repoRoot, "web", "manual", "data", "manual-features.json"); const manualFeatures = fs.existsSync(manualFeaturesPath) ? JSON.parse(fs.readFileSync(manualFeaturesPath, "utf8")) : null; const result = scanSurfaces({ repoRoot, desktopRoot, inventory, manualFeatures, webSrcRoot, stable }); if (args.includes("--check")) { if (!fs.existsSync(outPath)) fail(`--check: missing ${outPath}`, 1); const previous = JSON.parse(fs.readFileSync(outPath, "utf8")); const strip = value => JSON.stringify({ ...value, generatedAt: "__stable__" }); if (strip(previous) !== strip(result)) fail("--check: surface inventory is stale; rebuild without --check", 1); console.log(JSON.stringify({ ok: true, checked: outPath, total: result.counts.total, gaps: result.counts.gaps })); process.exit(0); } fs.mkdirSync(path.dirname(outPath), { recursive: true }); fs.writeFileSync(outPath, `${JSON.stringify(result, null, 2)}\n`); console.log(JSON.stringify({ ok: true, out: outPath, total: result.counts.total, byCategory: result.counts.byCategory, byStatus: result.counts.byStatus, gaps: result.counts.gaps, }));