${esc(part.id)} · ${esc(part.title)}
${part.steps} 步- ${rows}
cd "${esc(REPO_ROOT)}" && DISPLAY=:1 node tools/reducer/create-part.mjs ${esc(part.id)}
#!/usr/bin/env node /** * Generate web/teaching/reducer-toolkit.html — the beginner companion page for * the headed reducer toolkit (tools/reducer/). * * Deterministic: reads the toolkit catalog and the per-part UI step files, no * timestamps, so `--check` can byte-compare. Running anything still happens in * the teaching console (console.html) or by copying a command; this page never * executes tools itself. * * Usage: * node web/tools/teaching-console/build-reducer-page.mjs * node web/tools/teaching-console/build-reducer-page.mjs --check * Exit: 0 written/identical, 1 stale (--check), 2 bad arguments. */ import fs from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { REPO_ROOT, PROJECT_DIR, groups, parts, stats } from "../../../tools/reducer/catalog.mjs"; const HERE = path.dirname(fileURLToPath(import.meta.url)); const DEFAULT_OUT = path.resolve(HERE, "../../teaching/reducer-toolkit.html"); /** Common driver step labels → Chinese, so a beginner knows what will be clicked. */ const LABEL_ZH = { "gear profile": "齿轮轮廓(渐开线参数)", pad: "拉伸成实体", "cut profile": "挖切轮廓", cut: "挖切", revolution: "旋转成轴", "shaft profile": "轴的外形轮廓", "outer profile": "外形轮廓", "outer pad": "外壳拉伸", "bore profile": "轴承孔轮廓", bores: "镗轴承孔", profile: "轮廓草图", hub: "轮毂", "hub profile": "轮毂轮廓", flange: "法兰", "flange profile": "法兰轮廓", bore: "内孔", "bolt profile": "螺栓孔轮廓", "bolt pocket": "螺栓沉孔", "inspection profile": "观察孔轮廓", "inspection opening": "开观察孔", "lifting profile": "吊耳轮廓", "lifting threads": "吊耳螺纹孔", }; function zh(label) { if (LABEL_ZH[label]) return LABEL_ZH[label]; // Part-specific labels ("CoverCavityBossLeft profile") get a mechanical suffix. if (label.endsWith(" profile")) return `${label.slice(0, -8)} 草图`; if (/involute/i.test(label)) return `${label.replace(/ involute/i, "")} 渐开线齿廓`; if (/keyseat/i.test(label)) return `${label.replace(/ keyseat.*/i, "")} 键槽`; if (/blank/i.test(label)) return `${label.replace(/ blank/i, "")} 毛坯`; return label; } function readSteps(document) { try { const payload = JSON.parse(fs.readFileSync(path.join(PROJECT_DIR, "out/ui-steps", `${document}.json`), "utf8")); return payload.steps ?? []; } catch { return []; } } function esc(text) { return String(text ?? "").replace(/[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ }[c])); } function volumeText(volume) { return volume == null ? "—" : `${Math.round(volume).toLocaleString("en-US")} mm³`; } function partCard(part) { const steps = readSteps(part.document); const rows = steps.map((step) => `
${esc(step.label)}${esc(zh(step.label))}cd "${esc(REPO_ROOT)}" && DISPLAY=:1 node tools/reducer/create-part.mjs ${esc(part.id)}
${summary.parts} 个零件,${summary.steps} 个界面步骤,一步一步点出来;最后装配成整机。每一步都是真实浏览器里的操作,建完由界面算出的体积与构建记录逐件对照。
cd web && npx vite build(改过 web/src 之后必做)。node tools/reducer/create-part.mjs P01 --dry —— 只看前置,不启动浏览器。有头运行需要图形环境(DISPLAY=:1)与 Chrome。所有证据落在 docs/current/reducer-toolkit/runs/,截图落在 web/tools/reducer-parts-course/ui-stills/。
cd "${esc(REPO_ROOT)}" && DISPLAY=:1 node tools/reducer/create-assembly.mjs
| 命令 | 作用 |
|---|---|
node tools/reducer/list.mjs | 列出 23 个零件、分组、步数与体积 |
node tools/reducer/create-part.mjs P06 | 有头重建一个零件(P 编号或 Document 名都行) |
node tools/reducer/create-part.mjs P06 --dry | 只做前置检查,不启动浏览器 |
node tools/reducer/create-part.mjs P06 --slow | 放慢点击,适合边看边学 |
node tools/reducer/create-all.mjs --group bearings | 按组串行重建 |
node tools/reducer/create-all.mjs --all --keep-going | 全部 23 件,出错继续 |
node tools/reducer/create-assembly.mjs | 真实界面装配 |
node tools/reducer/self-test.mjs | 无浏览器自测(目录、分组、参数校验、前置) |
工具只做编排与前置检查;每一步的点击由共享引擎 web/tools/cad-ui-rebuild/ 执行,构建记录来自 web/teaching/cases/secondary-reducer-pro/out/replay/,界面步骤来自 web/tools/reducer-parts-course/out/ui-steps/。
| 现象 | 原因与处理 |
|---|---|
| 退出码 2,日志里有「前置缺失」 | dist、内核产物、Chrome、DISPLAY 或步骤文件缺失。照提示修,或用 --dry 看全部检查项。 |
| 退出码 1,体积不一致 | 界面建出的几何与构建记录不同,是产品回归;报告里给出两边体积与相对误差。 |
| 看不到浏览器窗口 | 有头需要可用的 X 显示;在带图形界面的会话里用 DISPLAY=:1 启动。 |
| 页面打开是空白/旧版本 | 先 cd web && npx vite build,工具会自动为构建好的 dist 起临时服务。 |
本页由 web/tools/teaching-console/build-reducer-page.mjs 生成,请勿手改。