#!/usr/bin/env node // Audits the UI surface inventory against the repository and the manual. // // For every surface it verifies: // - the React owner file exists and (when given) the symbol appears in it // - the desktop reference file exists // - the surface is documented in the generated manual chapter ch16 // - status is implemented/partial/gap/boundary as recorded, with reasons // // Output: docs/current/ui-design/data/gap-register.json (summary + issues). // // node tools/manual/audit-ui-gaps.mjs // node tools/manual/audit-ui-gaps.mjs --check # exit 1 if any gap import fs from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; const here = path.dirname(fileURLToPath(import.meta.url)); const webRoot = path.resolve(here, "../.."); const repoRoot = path.resolve(webRoot, ".."); const inventoryPath = path.join(repoRoot, "tools/fcweb/out/ui-surface-inventory.json"); const chapterPath = path.join(webRoot, "manual/content/ch16-panel-index.md"); const outPath = path.join(repoRoot, "docs/current/ui-design/data/gap-register.json"); const args = process.argv.slice(2); const check = args.includes("--check"); const fail = message => { console.error(`[audit-ui-gaps] ${message}`); process.exit(2); }; if (!fs.existsSync(inventoryPath)) fail(`missing ${inventoryPath}; run ui-surface-inventory.mjs first`); if (!fs.existsSync(chapterPath)) fail(`missing ${chapterPath}; run generate-panel-index.mjs first`); const inventory = JSON.parse(fs.readFileSync(inventoryPath, "utf8")); const chapter = fs.readFileSync(chapterPath, "utf8"); const categorySection = { "shell-region": "ch16-16-3-壳层区域", statusbar: "ch16-16-4-状态栏", "viewport-tool": "ch16-16-5-视口工具", dock: "ch16-16-6-停靠面板", "task-panel": "ch16-16-7-任务面板", "modal-dialog": "ch16-16-8-模态对话框", "preferences-page": "ch16-16-9-偏好设置页", menu: "ch16-16-10-菜单", toolbar: "ch16-16-11-工具栏", }; const symbolCache = new Map(); const fileContains = (file, symbol) => { if (!symbol) return true; if (!file) return false; const key = file; if (!symbolCache.has(key)) { const full = path.join(repoRoot, file); symbolCache.set(key, fs.existsSync(full) ? fs.readFileSync(full, "utf8") : null); } const text = symbolCache.get(key); return Boolean(text && text.includes(symbol)); }; const issues = []; const perSurface = inventory.surfaces.map(surface => { const problems = []; const ownerFile = surface.owner?.file ? path.join(repoRoot, surface.owner.file) : null; if (!ownerFile || !fs.existsSync(ownerFile)) problems.push("owner-file-missing"); else if (!fileContains(surface.owner.file, surface.owner.symbol)) problems.push("owner-symbol-missing"); const desktopFile = surface.desktopRef?.file ? path.join(repoRoot, surface.desktopRef.file) : null; if (desktopFile && !fs.existsSync(desktopFile)) problems.push("desktop-file-missing"); if (!chapter.includes(surface.nameZh)) problems.push("manual-anchor-missing"); if (surface.status === "gap") problems.push("ui-gap"); if (surface.status === "partial" && !surface.note) problems.push("partial-without-note"); for (const problem of problems) issues.push({ id: surface.id, category: surface.category, status: surface.status, problem }); return { id: surface.id, category: surface.category, status: surface.status, manualAnchor: categorySection[surface.category] ?? "ch16", problems }; }); const byProblem = {}; for (const issue of issues) byProblem[issue.problem] = (byProblem[issue.problem] ?? 0) + 1; const report = { schema: "freecad-web-manual/ui-gap-register/v1", counts: { surfaces: perSurface.length, withProblems: perSurface.filter(row => row.problems.length).length, byProblem, byStatus: inventory.counts.byStatus, }, ok: issues.length === 0, issues, surfaces: perSurface, }; if (check) { if (!report.ok) { console.error(JSON.stringify({ ok: false, counts: report.counts, sample: issues.slice(0, 10) }, null, 2)); process.exit(1); } fs.mkdirSync(path.dirname(outPath), { recursive: true }); fs.writeFileSync(outPath, `${JSON.stringify(report, null, 2)}\n`); console.log(JSON.stringify({ ok: true, checked: path.relative(repoRoot, outPath), surfaces: perSurface.length })); process.exit(0); } fs.mkdirSync(path.dirname(outPath), { recursive: true }); fs.writeFileSync(outPath, `${JSON.stringify(report, null, 2)}\n`); console.log(JSON.stringify({ ok: report.ok, out: path.relative(repoRoot, outPath), counts: report.counts, sample: issues.slice(0, 5) }, null, 2)); process.exit(report.ok ? 0 : 1);