#!/usr/bin/env node // Derives docs/current/web-freecad-manual-gaps.md from the real pipeline outputs so // the gap register never drifts from final-status.json / gap-ledger.json / // gap-register.json. The previous hand-written copy still described the retired // 32-module inventory, which is why this file is generated instead of maintained. // // node web/tools/manual/generate-gaps-doc.mjs // node web/tools/manual/generate-gaps-doc.mjs --check # exit 1 on drift 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 dataDir = path.join(webRoot, "manual", "data"); const outPath = path.join(repoRoot, "docs", "current", "web-freecad-manual-gaps.md"); const gapRegisterPath = path.join(repoRoot, "docs", "current", "ui-design", "data", "gap-register.json"); const args = process.argv.slice(2); const check = args.includes("--check"); const read = file => JSON.parse(fs.readFileSync(file, "utf8")); const status = read(path.join(dataDir, "final-status.json")); const ledger = read(path.join(dataDir, "gap-ledger.json")); const register = fs.existsSync(gapRegisterPath) ? read(gapRegisterPath) : null; const cell = value => String(value ?? "—").replace(/\|/g, "\\|"); const lines = []; const push = (...items) => lines.push(...items); push("# Web FreeCAD 手册与界面文档 · 缺口与边界账本", ""); push("> 本文件由 `web/tools/manual/generate-gaps-doc.mjs` 从真实产物派生,**不要手改**。"); push("> 输入:`web/manual/data/final-status.json`、`web/manual/data/gap-ledger.json`、`docs/current/ui-design/data/gap-register.json`。"); push("> 复核:`node web/tools/manual/generate-gaps-doc.mjs --check`。", ""); push("## 口径", ""); push(`- 模块数 **${status.modules}**(不含已整体摘除的 OpenSCAD)。`); push(`- 命令矩阵 **${status.commands}** 条,原生承接 **${status.nativeHandlers}** 条。`); push(`- 手工验证命令 **${status.verifiedCommands}** 条;已知边界 **${(ledger.boundaries ?? []).length}** 条。`); push(`- 手册 **${status.chaptersWithAppendix}** 章(正文 ${status.chapters} 章 + 附录章)、页面截图引用 **${status.pageCheck.images}** 处、磁盘 PNG **${status.screenshots}** 个。`); if (register) { const byCategory = register.counts.byCategory ?? {}; push(`- UI 表面 **${register.counts.surfaces}** 项:${Object.entries(byCategory).map(([key, value]) => `${key} ${value}`).join(" / ")}。`); const partial = (register.surfaces ?? []).filter(item => item.status === "partial").length; const gap = (register.surfaces ?? []).filter(item => item.status === "gap").length; push(`- 表面状态:implemented ${register.counts.surfaces - partial - gap} / partial ${partial} / gap **${gap}**。`); } push(""); push("## 已实现的界面覆盖(不是缺口)", ""); push("| 项 | 结果 |"); push("|---|---|"); push(`| 界面设计文档 | \`docs/current/web-freecad-ui-layout-and-functions.html\`,${status.chaptersWithAppendix} 章 + 命令附录 |`); push(`| 手册 | \`web/teaching/manual.html\`,${status.chapters} 章 ${status.pageCheck.sections} 节 |`); push(`| 截图 | 页面引用 ${status.pageCheck.images} 处;磁盘 ${status.screenshots} 个 PNG;采集报告 ${status.workflows} 份 |`); push(`| 浏览器校验 | 桌面 overflow ${status.pageCheck.desktopOverflow} / 移动 overflow ${status.pageCheck.mobileOverflow} / 破图 ${status.pageCheck.brokenImages.length} |`); push(""); push(`## 已知边界(${(ledger.boundaries ?? []).length} 条)`, ""); push("| ID | 模块 | 边界 | 状态 |"); push("|---|---|---|---|"); for (const item of ledger.boundaries ?? []) { push(`| \`${cell(item.id)}\` | ${cell(item.module)} | ${cell(item.detail)} | ${cell(item.status)} |`); } push(""); push("## 手工验证的用例", ""); push(`共 **${ledger.verified}** 条(台账 \`${path.relative(repoRoot, path.join(dataDir, "gap-ledger.json"))}\`)。`); for (const note of ledger.notes ?? []) push(`- ${note}`); push(""); if (register) { const flagged = (register.surfaces ?? []).filter(item => item.status === "partial" || item.status === "gap"); push(`## 界面表面审计(${register.counts.surfaces} 项,问题 ${register.issues.length} 项)`, ""); if (flagged.length) { push("| 表面 | 分类 | 状态 | 注释 |"); push("|---|---|---|---|"); for (const item of flagged) push(`| ${cell(item.nameZh)} | ${cell(item.category)} | ${cell(item.status)} | ${cell(item.note ?? "—")} |`); } else { push("没有 `partial` 或 `gap` 项。"); } push(""); push("审计命令:`node web/tools/manual/audit-ui-gaps.mjs --check`。"); push(""); } push("## 复现命令", ""); push("```bash"); push(`R="/media/mes123456/Elements SE/WebFreeCAD/FreeCADWasmDev/working/FreeCAD"`); push(`node "$R/tools/fcweb/ui-surface-inventory.mjs" --check`); push(`node "$R/tools/fcweb/build-ui-doc.mjs" --check`); push(`node "$R/web/tools/manual/audit-ui-gaps.mjs" --check`); push(`node "$R/web/tools/manual/generate-gaps-doc.mjs" --check`); push(`cd "$R/web" && npm run build:manual && npm run check:manual`); push("```"); push(""); push("## 边界判定口径", ""); push("- 前置未满足(缺文档、缺 Worker、缺原生对象)记边界并保留产品原始错误文本,不写成产品回归。"); push("- GUI 控件缺口用 React 组件补齐,不以 GUI-only 名义留作 blocked。"); push("- 空白或占位截图不得入库;空白工具栏裁剪由 `build-ui-doc.mjs` 的 1024 字节门槛自动跳过。"); push("- 生成物(本文件、第 16 章、`final-status.json`)一律由脚本产出并带 `--check`。"); push(""); const text = `${lines.join("\n")}\n`; if (check) { const previous = fs.existsSync(outPath) ? fs.readFileSync(outPath, "utf8") : ""; if (previous !== text) { console.error("[generate-gaps-doc] --check: docs/current/web-freecad-manual-gaps.md is stale"); process.exit(1); } console.log(JSON.stringify({ ok: true, checked: "docs/current/web-freecad-manual-gaps.md" })); process.exit(0); } fs.mkdirSync(path.dirname(outPath), { recursive: true }); fs.writeFileSync(outPath, text); console.log(JSON.stringify({ ok: true, out: "docs/current/web-freecad-manual-gaps.md", bytes: Buffer.byteLength(text), boundaries: (ledger.boundaries ?? []).length, surfaces: register?.counts.surfaces ?? null }));