feat(reducer): 二级减速器有头创建工具包与初学者教学
- tools/reducer:目录/前置/单件/批量/装配/自测,复用 cad-ui-rebuild 引擎 - 教学控制台新增「二级减速器」分组:23 件逐件课 + 装配课 + 环境课(job kind reducer-part / reducer-assembly) - web/teaching/reducer-toolkit.html 初学者配套页(生成物)+ Playwright 双视口门禁 - 首页补工具入口;工具手册随 npm 脚本变更重生成 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
File diff suppressed because one or more lines are too long
83
tools/reducer/README.md
Normal file
83
tools/reducer/README.md
Normal file
@@ -0,0 +1,83 @@
|
||||
# tools/reducer —— 二级减速器「有头」创建工具
|
||||
|
||||
在真实界面(有头 Chrome)里逐一重建二级减速器的 23 个零件并完成装配,产出归一化报告。
|
||||
本包**只做编排与前置检查**:真实点击仍由 `web/tools/cad-ui-rebuild/drive.mjs` /
|
||||
`assemble.mjs` 完成,零件目录仍来自 `web/tools/reducer-parts-course/project.json`,
|
||||
内核建模仍由 `web/teaching/cases/secondary-reducer-pro/parts/*.mjs` 与 `tools/fcweb` 完成。
|
||||
这里不复制任何步骤数据。
|
||||
|
||||
## 快速开始
|
||||
|
||||
```bash
|
||||
# 看目录:23 件、分组、步数、记录体积
|
||||
node tools/reducer/list.mjs
|
||||
node tools/reducer/list.mjs --json
|
||||
|
||||
# 单件:真实界面重建(默认有头)
|
||||
node tools/reducer/create-part.mjs P06
|
||||
node tools/reducer/create-part.mjs Bearing6206_Inner --slow # 慢放,便于观察
|
||||
node tools/reducer/create-part.mjs P21 --dry # 只查前置与步骤
|
||||
|
||||
# 批量:按组 / 按列表 / 全部
|
||||
node tools/reducer/create-all.mjs --group gears
|
||||
node tools/reducer/create-all.mjs --parts P06,P07 --keep-going
|
||||
|
||||
# 装配:32 链接 / 33 关节
|
||||
node tools/reducer/create-assembly.mjs
|
||||
```
|
||||
|
||||
## 命令与退出码
|
||||
|
||||
| 命令 | 说明 |
|
||||
|---|---|
|
||||
| `create-part.mjs <P01..P23\|Document>` | 校验前置 → 定位步骤 → 调 `drive.mjs` → 读 `out/ui-run/<Document>.json` → 写 `report.json` |
|
||||
| `create-assembly.mjs` | 同上,调 `assemble.mjs`,读 `out/ui-run/<document>-assembly.json` |
|
||||
| `create-all.mjs` | 串行调用 `create-part.mjs`;`--keep-going` 继续,末尾写 `summary.json` |
|
||||
| `list.mjs` | 分组文本列表;`--json` 输出 `freecad-web/reducer-toolkit/catalog/v1` |
|
||||
| `self-test.mjs` | 无浏览器自检:目录一致、非法 id 拒绝、前置报告结构 |
|
||||
|
||||
退出码统一为:`0` 通过 / `1` 产品不一致(体积或装配不匹配)/ `2` 前置缺失或参数错误。
|
||||
**前置失败不是产品失败**:只有前置全部满足后的比对不一致才记为 `1`。
|
||||
|
||||
## 前置检查(`preflight.mjs`)
|
||||
|
||||
8 项:`dist`(`web/dist/index.html`)、`kernel`(wasm 产物)、`chrome`、`display`、
|
||||
`playwright`、`engine`(`drive.mjs`/`assemble.mjs`)、`parts`(`out/ui-steps` 与 replay 齐全)、
|
||||
`app`(`project.json` 的 `appOrigin` 可达)。其中 `app` 只作提示:不可达时
|
||||
`ensureOrigin()` 会用 `tools/static-host.mjs` 在临时端口起静态服务,并把
|
||||
`appOrigin` 与全部 `paths` 改写为绝对路径,生成一份**派生 project.json** 放到
|
||||
`docs/current/reducer-toolkit/runtimes/<stamp>/`(`drive.mjs` 只从 project.json 读入口端口)。
|
||||
|
||||
## 报告字段
|
||||
|
||||
`docs/current/reducer-toolkit/runs/<stamp>-<id>/report.json`:
|
||||
|
||||
- 零件(schema `freecad-web/reducer-toolkit/part/v1`):`part{id,document,title,group}`、
|
||||
`steps/stepsTotal`、`failed`、`volume`(界面实测)、`expectedVolume`(构建记录)、
|
||||
`relativeError`、`volumeMatches`、`seconds`、`pageErrors`、`stillsDir`、`verdict`。
|
||||
- 装配(`.../assembly/v1`):`expected{inserts,rotated}`、`inserted`、`rotated`、
|
||||
`mismatches`、`links`、`fatal`、`pageErrors`、`verdict`。
|
||||
- 批量(`.../batch/v1`):`items[{id,document,title,exitCode}]`、`passed/failed/blocked/skipped`。
|
||||
|
||||
截图落在 `web/tools/reducer-parts-course/ui-stills/<Document>/`。
|
||||
|
||||
## 与其它入口的关系
|
||||
|
||||
| 入口 | 何时用 |
|
||||
|---|---|
|
||||
| `tools/reducer/*`(本包) | 有头界面重建、批量、归一化报告 |
|
||||
| `web/tools/cad-ui-rebuild/drive.mjs` | 底层点击引擎,本包直接调用 |
|
||||
| `web/teaching/cases/secondary-reducer-pro/parts/*.mjs` | 内核建模(无浏览器、秒级),适合先验证尺寸 |
|
||||
| `tools/fcweb/` | 在脚本中直接开文档/零件/装配并导出 OPFS |
|
||||
| `web/teaching/console.html` | 图形化运行本包课程(每个零件一节课) |
|
||||
| `web/teaching/reducer-toolkit.html` | 初学者配套讲义(生成物,勿手改) |
|
||||
|
||||
配套页面由 `web/tools/teaching-console/build-reducer-page.mjs` 生成,课程由
|
||||
`web/tools/teaching-console/lessons.mjs` 的 `reducer` 分组定义,运行经
|
||||
`web/teaching/suite-runner.mjs` 的 `reducer-part` / `reducer-assembly` 作业类型
|
||||
(参数只接受 `P\d{2}`,走白名单 argv)。
|
||||
|
||||
## OPFS 约定
|
||||
|
||||
界面上建出的文档由引擎写回 OPFS;报告与截图只是证据快照,放在 `docs/current/` 与
|
||||
`ui-stills/` 下,不作数据源,也不触发任何自动下载。
|
||||
133
tools/reducer/catalog.mjs
Normal file
133
tools/reducer/catalog.mjs
Normal file
@@ -0,0 +1,133 @@
|
||||
/**
|
||||
* Canonical catalog of the 23 secondary-reducer parts.
|
||||
*
|
||||
* This module deliberately owns no part list of its own: it reads the project
|
||||
* manifest that the shared UI driver already uses
|
||||
* (web/tools/reducer-parts-course/project.json) and joins it with the two
|
||||
* evidence trees that already exist on disk:
|
||||
* - out/ui-steps/<Document>.json — the per-step UI actions drive.mjs replays
|
||||
* - out/replay/<Document>.json — the build record, including final volume
|
||||
*
|
||||
* A part is only offered when both files exist, so `create-part` can never
|
||||
* start a browser for a part that has nothing to replay.
|
||||
*/
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
||||
export const REPO_ROOT = path.resolve(HERE, "../..");
|
||||
export const PROJECT_DIR = path.join(REPO_ROOT, "web/tools/reducer-parts-course");
|
||||
export const PROJECT_FILE = path.join(PROJECT_DIR, "project.json");
|
||||
const STEPS_DIR = path.join(PROJECT_DIR, "out/ui-steps");
|
||||
const RUN_DIR = path.join(PROJECT_DIR, "out/ui-run");
|
||||
const STILLS_DIR = path.join(PROJECT_DIR, "ui-stills");
|
||||
|
||||
/** Document prefix → teaching group. Longest prefix wins. */
|
||||
const GROUPS = [
|
||||
{ id: "gears", label: "齿轮", prefixes: ["Gear"] },
|
||||
{ id: "shafts", label: "轴", prefixes: ["Shaft"] },
|
||||
{ id: "bearings", label: "轴承", prefixes: ["Bearing"] },
|
||||
{ id: "keys", label: "平键", prefixes: ["Key"] },
|
||||
{ id: "seals", label: "骨架油封", prefixes: ["Seal"] },
|
||||
{ id: "coupling", label: "联轴器", prefixes: ["Coupling"] },
|
||||
{ id: "housing", label: "箱体与箱盖", prefixes: ["Housing", "Inspection"] },
|
||||
];
|
||||
|
||||
export function groupOf(document) {
|
||||
const match = GROUPS.find((group) => group.prefixes.some((prefix) => document.startsWith(prefix)));
|
||||
return match ?? { id: "other", label: "其他", prefixes: [] };
|
||||
}
|
||||
|
||||
function readJson(file) {
|
||||
try {
|
||||
return JSON.parse(fs.readFileSync(file, "utf8"));
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function stepsOf(document) {
|
||||
const payload = readJson(path.join(STEPS_DIR, `${document}.json`));
|
||||
return Array.isArray(payload?.steps) ? payload.steps : null;
|
||||
}
|
||||
|
||||
function replayOf(document) {
|
||||
return readJson(path.join(PROJECT_DIR, "out/replay", `${document}.json`))
|
||||
?? readJson(path.join(REPO_ROOT, "web/teaching/cases/secondary-reducer-pro/out/replay", `${document}.json`));
|
||||
}
|
||||
|
||||
function finalVolume(steps) {
|
||||
const volumes = (steps ?? []).map((step) => step.volume).filter((volume) => typeof volume === "number" && volume > 0);
|
||||
return volumes.length ? volumes.at(-1) : null;
|
||||
}
|
||||
|
||||
export function projectManifest() {
|
||||
const manifest = readJson(PROJECT_FILE);
|
||||
if (!manifest) throw new Error(`缺少项目清单:${PROJECT_FILE}`);
|
||||
return manifest;
|
||||
}
|
||||
|
||||
/** All parts, in manifest order, enriched with step counts and recorded volume. */
|
||||
export function parts() {
|
||||
const manifest = projectManifest();
|
||||
return (manifest.parts ?? []).map((entry) => {
|
||||
const steps = stepsOf(entry.document);
|
||||
const replay = replayOf(entry.document);
|
||||
const group = groupOf(entry.document);
|
||||
return {
|
||||
id: entry.id,
|
||||
document: entry.document,
|
||||
title: entry.title,
|
||||
group: group.id,
|
||||
groupLabel: group.label,
|
||||
steps: steps?.length ?? 0,
|
||||
volume: finalVolume(replay?.steps),
|
||||
reconstructable: Boolean(steps && steps.length && replay?.steps?.length),
|
||||
stepsFile: path.relative(REPO_ROOT, path.join(STEPS_DIR, `${entry.document}.json`)),
|
||||
runFile: path.relative(REPO_ROOT, path.join(RUN_DIR, `${entry.document}.json`)),
|
||||
stillsDir: path.relative(REPO_ROOT, path.join(STILLS_DIR, entry.id)),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
export function groups() {
|
||||
return GROUPS.map((group) => {
|
||||
const members = parts().filter((part) => part.group === group.id);
|
||||
return { id: group.id, label: group.label, count: members.length, ids: members.map((part) => part.id) };
|
||||
}).filter((group) => group.count > 0);
|
||||
}
|
||||
|
||||
const ID_PATTERN = /^[A-Za-z][A-Za-z0-9_-]{0,63}$/;
|
||||
|
||||
/**
|
||||
* Resolve "P06", "p06" or "Bearing6206_Inner" to a part.
|
||||
* Rejects anything that is not a plain token so a shell fragment can never be
|
||||
* forwarded to the driver.
|
||||
*/
|
||||
export function find(key) {
|
||||
if (typeof key !== "string" || !ID_PATTERN.test(key)) {
|
||||
const error = new Error(`非法零件标识:${String(key).slice(0, 40)}`);
|
||||
error.code = "E_PART";
|
||||
throw error;
|
||||
}
|
||||
const wanted = key.toLowerCase();
|
||||
const all = parts();
|
||||
const match = all.find((part) => part.id.toLowerCase() === wanted)
|
||||
?? all.find((part) => part.document.toLowerCase() === wanted);
|
||||
if (!match) {
|
||||
const error = new Error(`没有该零件:${key}`);
|
||||
error.code = "E_PART";
|
||||
throw error;
|
||||
}
|
||||
return match;
|
||||
}
|
||||
|
||||
export function stats() {
|
||||
const all = parts();
|
||||
return {
|
||||
parts: all.length,
|
||||
steps: all.reduce((sum, part) => sum + part.steps, 0),
|
||||
reconstructable: all.filter((part) => part.reconstructable).length,
|
||||
};
|
||||
}
|
||||
119
tools/reducer/create-all.mjs
Normal file
119
tools/reducer/create-all.mjs
Normal file
@@ -0,0 +1,119 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* Purpose: 按组或按列表串行重建多个零件(每个零件仍是一个独立运行)。
|
||||
*
|
||||
* 逐件调用 tools/reducer/create-part.mjs,保持与单件完全相同的判定。
|
||||
* 默认遇错即停;--keep-going 继续并在末尾给出汇总。
|
||||
*
|
||||
* Usage:
|
||||
* node tools/reducer/create-all.mjs --group gears --dry
|
||||
* node tools/reducer/create-all.mjs --parts P03,P04
|
||||
* node tools/reducer/create-all.mjs --all --keep-going --slow
|
||||
*
|
||||
* Exit: 0 全部通过 / 1 至少一件产品失败 / 2 前置缺失或参数错误
|
||||
*/
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { spawn } from "node:child_process";
|
||||
import { REPO_ROOT, find, groups, parts } from "./catalog.mjs";
|
||||
|
||||
const CREATE_PART = path.join(REPO_ROOT, "tools/reducer/create-part.mjs");
|
||||
|
||||
function parseArgs(argv) {
|
||||
const options = { parts: [], group: null, all: false, keepGoing: false, dry: false, slow: false, out: null };
|
||||
for (let index = 0; index < argv.length; index += 1) {
|
||||
const arg = argv[index];
|
||||
if (arg === "--parts") options.parts = String(argv[++index] ?? "").split(",").map((item) => item.trim()).filter(Boolean);
|
||||
else if (arg === "--group") options.group = argv[++index] ?? null;
|
||||
else if (arg === "--all") options.all = true;
|
||||
else if (arg === "--keep-going") options.keepGoing = true;
|
||||
else if (arg === "--dry") options.dry = true;
|
||||
else if (arg === "--slow") options.slow = true;
|
||||
else if (arg === "--out") options.out = path.resolve(argv[++index] ?? "");
|
||||
else if (arg === "--help" || arg === "-h") {
|
||||
console.log("node tools/reducer/create-all.mjs [--parts P01,P02 | --group gears | --all] [--keep-going] [--dry] [--slow] [--out <dir>]");
|
||||
process.exit(0);
|
||||
} else {
|
||||
console.error(`未知参数:${arg}`);
|
||||
process.exit(2);
|
||||
}
|
||||
}
|
||||
if (!options.parts.length && !options.group && !options.all) {
|
||||
console.error("用法:--parts P01,P02 | --group <id> | --all(分组见 node tools/reducer/list.mjs)");
|
||||
process.exit(2);
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
function selection(options) {
|
||||
if (options.parts.length) return options.parts.map((key) => find(key));
|
||||
if (options.group) {
|
||||
const group = groups().find((item) => item.id === options.group);
|
||||
if (!group) {
|
||||
console.error(`没有该分组:${options.group}(可用:${groups().map((item) => item.id).join(", ")})`);
|
||||
process.exit(2);
|
||||
}
|
||||
return group.ids.map((key) => find(key));
|
||||
}
|
||||
if (options.out) {
|
||||
// Reports live under the shared out dir so a whole build is one directory.
|
||||
return parts();
|
||||
}
|
||||
return parts();
|
||||
}
|
||||
|
||||
function runPart(part, options) {
|
||||
const argv = [process.execPath, CREATE_PART, part.id];
|
||||
if (options.dry) argv.push("--dry");
|
||||
if (options.slow) argv.push("--slow");
|
||||
if (options.out) argv.push("--out", path.join(options.out, part.id));
|
||||
return new Promise((resolve) => {
|
||||
const child = spawn(argv[0], argv.slice(1), { cwd: REPO_ROOT, stdio: "inherit" });
|
||||
child.on("error", () => resolve(2));
|
||||
child.on("close", (code) => resolve(code ?? 1));
|
||||
});
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const options = parseArgs(process.argv.slice(2));
|
||||
const selected = selection(options);
|
||||
const stamp = new Date().toISOString().replace(/[:.]/g, "-");
|
||||
const outDir = options.out;
|
||||
const summary = { schema: "freecad-web/reducer-toolkit/batch/v1", startedAt: new Date().toISOString(), items: [] };
|
||||
|
||||
for (const part of selected) {
|
||||
console.log(`\n=== ${part.id} ${part.document}(${part.title},${part.steps} 步)===`);
|
||||
const code = await runPart(part, options);
|
||||
summary.items.push({ id: part.id, document: part.document, title: part.title, exitCode: code });
|
||||
if (code === 2) {
|
||||
console.error(`前置缺失,停止:${part.id}`);
|
||||
break;
|
||||
}
|
||||
if (code !== 0 && !options.keepGoing) {
|
||||
console.error(`零件 ${part.id} 未通过(exit ${code}),停止。用 --keep-going 可继续。`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
summary.finishedAt = new Date().toISOString();
|
||||
summary.passed = summary.items.filter((item) => item.exitCode === 0).length;
|
||||
summary.failed = summary.items.filter((item) => item.exitCode === 1).length;
|
||||
summary.blocked = summary.items.filter((item) => item.exitCode === 2).length;
|
||||
summary.skipped = selected.length - summary.items.length;
|
||||
|
||||
const dir = outDir ?? path.join(REPO_ROOT, "docs/current/reducer-toolkit/runs", `${stamp}-batch`);
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
fs.writeFileSync(path.join(dir, "summary.json"), JSON.stringify(summary, null, 2));
|
||||
|
||||
console.log(`\n合计:通过 ${summary.passed} / 失败 ${summary.failed} / 前置 ${summary.blocked} / 未执行 ${summary.skipped}`);
|
||||
console.log(`汇总:${path.relative(REPO_ROOT, path.join(dir, "summary.json"))}`);
|
||||
|
||||
if (summary.failed > 0) process.exit(1);
|
||||
if (summary.blocked > 0 || summary.skipped > 0) process.exit(2);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
console.error(`失败:${error?.message ?? error}`);
|
||||
process.exit(error?.code === "E_PART" ? 2 : 1);
|
||||
});
|
||||
146
tools/reducer/create-assembly.mjs
Normal file
146
tools/reducer/create-assembly.mjs
Normal file
@@ -0,0 +1,146 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* Purpose: 在真实界面里把 23 个零件装配成二级减速器(有头 Chrome)。
|
||||
*
|
||||
* 复用 web/tools/cad-ui-rebuild/assemble.mjs:新建装配文档、逐个插入链接、
|
||||
* 按构建记录的位置与旋转落位。本工具只补前置检查与归一化报告。
|
||||
*
|
||||
* Usage:
|
||||
* node tools/reducer/create-assembly.mjs --dry
|
||||
* node tools/reducer/create-assembly.mjs
|
||||
* node tools/reducer/create-assembly.mjs --out <dir>
|
||||
*
|
||||
* Exit: 0 全部链接插入且无失配 / 1 有失配(产品问题)/ 2 前置缺失
|
||||
*/
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { spawn } from "node:child_process";
|
||||
import { REPO_ROOT, PROJECT_DIR, projectManifest } from "./catalog.mjs";
|
||||
import { ensureOrigin, preflight } from "./preflight.mjs";
|
||||
|
||||
const ASSEMBLE = path.join(REPO_ROOT, "web/tools/cad-ui-rebuild/assemble.mjs");
|
||||
|
||||
function parseArgs(argv) {
|
||||
const options = { headed: true, dry: false, serve: true, out: null, json: false };
|
||||
for (let index = 0; index < argv.length; index += 1) {
|
||||
const arg = argv[index];
|
||||
if (arg === "--headed") options.headed = true;
|
||||
else if (arg === "--headless") options.headed = false;
|
||||
else if (arg === "--dry") options.dry = true;
|
||||
else if (arg === "--no-serve") options.serve = false;
|
||||
else if (arg === "--json") options.json = true;
|
||||
else if (arg === "--out") options.out = path.resolve(argv[++index] ?? "");
|
||||
else if (arg === "--help" || arg === "-h") {
|
||||
console.log("node tools/reducer/create-assembly.mjs [--headed|--headless] [--dry] [--no-serve] [--out <dir>] [--json]");
|
||||
process.exit(0);
|
||||
} else {
|
||||
console.error(`未知参数:${arg}`);
|
||||
process.exit(2);
|
||||
}
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
function stamp() {
|
||||
return new Date().toISOString().replace(/[:.]/g, "-");
|
||||
}
|
||||
|
||||
function runAssembly(options, projectDir) {
|
||||
const argv = [process.execPath, ASSEMBLE, "--project", projectDir];
|
||||
if (options.headed) argv.push("--headed");
|
||||
if (options.dry) argv.push("--dry");
|
||||
return new Promise((resolve) => {
|
||||
const child = spawn(argv[0], argv.slice(1), { cwd: REPO_ROOT, stdio: ["ignore", "pipe", "pipe"] });
|
||||
let tail = "";
|
||||
child.stdout.on("data", (chunk) => { process.stdout.write(chunk); tail = (tail + chunk.toString("utf8")).slice(-4000); });
|
||||
child.stderr.on("data", (chunk) => process.stderr.write(chunk));
|
||||
child.on("error", (error) => resolve({ code: -1, error, tail }));
|
||||
child.on("close", (code) => resolve({ code: code ?? -1, tail }));
|
||||
});
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const options = parseArgs(process.argv.slice(2));
|
||||
const manifest = projectManifest();
|
||||
const report = await preflight();
|
||||
|
||||
if (options.dry) {
|
||||
const assembly = manifest.assembly ?? {};
|
||||
console.log(`装配:${assembly.document ?? "SecondaryReducer"}(接地 ${assembly.groundDocument ?? "—"})`);
|
||||
for (const check of report.checks) console.log(` ${check.ok ? "✓" : "✗"} ${check.id}: ${check.detail}`);
|
||||
console.log(report.ok ? "前置全部满足(dry run,未启动浏览器)" : "前置未满足(dry run)");
|
||||
process.exit(report.ok ? 0 : 2);
|
||||
}
|
||||
if (!report.ok) {
|
||||
for (const check of report.checks.filter((item) => !item.ok && item.id !== "app")) {
|
||||
console.error(`前置缺失 ${check.id}: ${check.detail} → ${check.fix}`);
|
||||
}
|
||||
console.error("未启动浏览器(前置失败不是产品失败)。");
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
let origin = null;
|
||||
if (options.serve) {
|
||||
try {
|
||||
origin = await ensureOrigin(report.origin);
|
||||
console.log(origin.started ? `已为 ${origin.origin} 启动静态服务` : `复用已在运行的应用入口 ${origin.origin}`);
|
||||
} catch (error) {
|
||||
console.error(`前置缺失:${error.message}`);
|
||||
process.exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
const startedAt = Date.now();
|
||||
let result;
|
||||
try {
|
||||
result = await runAssembly(options, origin?.projectDir ?? PROJECT_DIR);
|
||||
} finally {
|
||||
await origin?.close();
|
||||
}
|
||||
|
||||
const document = manifest.assembly?.document ?? "SecondaryReducer";
|
||||
const uiReportFile = path.join(PROJECT_DIR, "out/ui-run", `${document}-assembly.json`);
|
||||
const uiReport = (() => {
|
||||
try {
|
||||
return JSON.parse(fs.readFileSync(uiReportFile, "utf8"));
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
})();
|
||||
|
||||
const verdict = !uiReport ? "run_fail"
|
||||
: uiReport.fatal || uiReport.mismatches?.length ? "product_fail"
|
||||
: uiReport.inserted < (uiReport.expected?.inserts ?? Infinity) ? "product_fail"
|
||||
: "pass";
|
||||
|
||||
const dir = options.out ?? path.join(REPO_ROOT, "docs/current/reducer-toolkit/runs", `${stamp()}-assembly`);
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
const summary = {
|
||||
schema: "freecad-web/reducer-toolkit/assembly/v1",
|
||||
document,
|
||||
groundDocument: uiReport?.groundDocument ?? manifest.assembly?.groundDocument ?? null,
|
||||
expected: uiReport?.expected ?? null,
|
||||
inserted: uiReport?.inserted ?? null,
|
||||
rotated: uiReport?.rotated ?? null,
|
||||
mismatches: uiReport?.mismatches?.length ?? null,
|
||||
seconds: uiReport?.seconds ?? Math.round((Date.now() - startedAt) / 1000),
|
||||
fatal: uiReport?.fatal ?? null,
|
||||
pageErrors: uiReport?.pageErrors ?? [],
|
||||
driverExitCode: result.code,
|
||||
verdict,
|
||||
finishedAt: new Date().toISOString(),
|
||||
};
|
||||
fs.writeFileSync(path.join(dir, "report.json"), JSON.stringify(summary, null, 2));
|
||||
|
||||
if (options.json) console.log(JSON.stringify(summary));
|
||||
else {
|
||||
console.log(`装配 ${document}: ${verdict}(插入 ${summary.inserted}/${summary.expected?.inserts ?? "?"},失配 ${summary.mismatches ?? "—"},${summary.seconds}s)`);
|
||||
console.log(`报告:${path.relative(REPO_ROOT, path.join(dir, "report.json"))}`);
|
||||
}
|
||||
process.exit(verdict === "pass" ? 0 : verdict === "product_fail" ? 1 : 2);
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
console.error(`失败:${error?.message ?? error}`);
|
||||
process.exit(1);
|
||||
});
|
||||
174
tools/reducer/create-part.mjs
Normal file
174
tools/reducer/create-part.mjs
Normal file
@@ -0,0 +1,174 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* Purpose: 在真实界面里重建二级减速器的一个零件(有头 Chrome)。
|
||||
*
|
||||
* 本工具只做三件事:校验前置、定位该零件的界面步骤、调用既有引擎
|
||||
* web/tools/cad-ui-rebuild/drive.mjs 逐步点击,最后把结果归一化成一份报告。
|
||||
* 步骤数据、点击逻辑与体积比对全部复用已有实现,这里不复制。
|
||||
*
|
||||
* Usage:
|
||||
* node tools/reducer/create-part.mjs P06
|
||||
* node tools/reducer/create-part.mjs Bearing6206_Inner --slow
|
||||
* node tools/reducer/create-part.mjs P21 --dry # 只检查前置与步骤
|
||||
* node tools/reducer/create-part.mjs P06 --out <dir> # 报告目录
|
||||
*
|
||||
* Exit: 0 通过 / 1 界面上建出的体积与构建记录不一致(产品问题)/ 2 前置缺失
|
||||
*/
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { spawn } from "node:child_process";
|
||||
import { REPO_ROOT, PROJECT_DIR, find, parts } from "./catalog.mjs";
|
||||
import { ensureOrigin, preflight } from "./preflight.mjs";
|
||||
|
||||
const DRIVE = path.join(REPO_ROOT, "web/tools/cad-ui-rebuild/drive.mjs");
|
||||
const RUN_FILE = (document) => path.join(PROJECT_DIR, "out/ui-run", `${document}.json`);
|
||||
|
||||
function parseArgs(argv) {
|
||||
const options = { key: null, headed: true, slow: false, dry: false, serve: true, out: null, json: false };
|
||||
for (let index = 0; index < argv.length; index += 1) {
|
||||
const arg = argv[index];
|
||||
if (arg === "--headed") options.headed = true;
|
||||
else if (arg === "--headless") options.headed = false;
|
||||
else if (arg === "--slow") options.slow = true;
|
||||
else if (arg === "--dry") options.dry = true;
|
||||
else if (arg === "--no-serve") options.serve = false;
|
||||
else if (arg === "--json") options.json = true;
|
||||
else if (arg === "--out") options.out = path.resolve(argv[++index] ?? "");
|
||||
else if (arg === "--help" || arg === "-h") {
|
||||
console.log("node tools/reducer/create-part.mjs <P01|Document> [--headed|--headless] [--slow] [--dry] [--no-serve] [--out <dir>] [--json]");
|
||||
process.exit(0);
|
||||
} else if (arg.startsWith("--")) {
|
||||
console.error(`未知参数:${arg}`);
|
||||
process.exit(2);
|
||||
} else if (!options.key) options.key = arg;
|
||||
else {
|
||||
console.error(`多余的参数:${arg}`);
|
||||
process.exit(2);
|
||||
}
|
||||
}
|
||||
if (!options.key) {
|
||||
console.error("用法:node tools/reducer/create-part.mjs <P01|Document> [--slow] [--dry]");
|
||||
process.exit(2);
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
function runDir(options, part) {
|
||||
const root = options.out ?? path.join(REPO_ROOT, "docs/current/reducer-toolkit/runs");
|
||||
const stamp = new Date().toISOString().replace(/[:.]/g, "-");
|
||||
return path.join(root, `${stamp}-${part.id}`);
|
||||
}
|
||||
|
||||
function line(text) {
|
||||
process.stdout.write(`${text}\n`);
|
||||
}
|
||||
|
||||
/** Spawn the shared driver and forward its stdout/stderr unchanged. */
|
||||
function drive(part, options, projectDir) {
|
||||
const argv = [process.execPath, DRIVE, "--project", projectDir, part.id];
|
||||
if (options.headed) argv.push("--headed");
|
||||
if (options.slow) argv.push("--slow");
|
||||
return new Promise((resolve) => {
|
||||
const child = spawn(argv[0], argv.slice(1), { cwd: REPO_ROOT, stdio: ["ignore", "pipe", "pipe"] });
|
||||
child.stdout.on("data", (chunk) => process.stdout.write(chunk));
|
||||
child.stderr.on("data", (chunk) => process.stderr.write(chunk));
|
||||
child.on("error", (error) => resolve({ code: -1, error }));
|
||||
child.on("close", (code) => resolve({ code: code ?? -1 }));
|
||||
});
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const options = parseArgs(process.argv.slice(2));
|
||||
const part = find(options.key);
|
||||
|
||||
const report = await preflight();
|
||||
if (options.dry) {
|
||||
line(`零件 ${part.id} ${part.document}(${part.title}):${part.steps} 步,记录体积 ${part.volume ?? "—"}`);
|
||||
for (const check of report.checks) line(` ${check.ok ? "✓" : "✗"} ${check.id}: ${check.detail}`);
|
||||
line(report.ok ? "前置全部满足(dry run,未启动浏览器)" : "前置未满足(dry run)");
|
||||
process.exit(report.ok ? 0 : 2);
|
||||
}
|
||||
if (!report.ok) {
|
||||
for (const check of report.checks.filter((item) => !item.ok && item.id !== "app")) {
|
||||
console.error(`前置缺失 ${check.id}: ${check.detail} → ${check.fix}`);
|
||||
}
|
||||
console.error("未启动浏览器(前置失败不是产品失败)。可先跑 --dry 查看全部检查。");
|
||||
process.exit(2);
|
||||
}
|
||||
if (!part.reconstructable) {
|
||||
console.error(`前置缺失:${part.document} 缺少界面步骤或构建记录,先运行 node web/tools/reducer-parts-course/build-ui-steps.mjs`);
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
line(`零件 ${part.id} ${part.document}(${part.title}):${part.steps} 步,记录体积 ${part.volume ?? "—"}`);
|
||||
let origin = null;
|
||||
if (options.serve) {
|
||||
try {
|
||||
origin = await ensureOrigin(report.origin);
|
||||
line(origin.started ? `已为 ${origin.origin} 启动静态服务` : `复用已在运行的应用入口 ${origin.origin}`);
|
||||
} catch (error) {
|
||||
console.error(`前置缺失:${error.message}`);
|
||||
process.exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
const startedAt = Date.now();
|
||||
let result;
|
||||
try {
|
||||
result = await drive(part, options, origin?.projectDir ?? PROJECT_DIR);
|
||||
} finally {
|
||||
await origin?.close();
|
||||
}
|
||||
|
||||
const uiRun = (() => {
|
||||
try {
|
||||
return JSON.parse(fs.readFileSync(RUN_FILE(part.document), "utf8"));
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
})();
|
||||
|
||||
const dir = options.out ?? runDir(options, part);
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
const verdict = !uiRun ? "run_fail"
|
||||
: uiRun.failed > 0 || uiRun.volumeMatches === false ? "product_fail"
|
||||
: "pass";
|
||||
const summary = {
|
||||
schema: "freecad-web/reducer-toolkit/part/v1",
|
||||
part: { id: part.id, document: part.document, title: part.title, group: part.group },
|
||||
steps: uiRun?.steps ?? part.steps,
|
||||
stepsTotal: uiRun?.stepsTotal ?? part.steps,
|
||||
failed: uiRun?.failed ?? null,
|
||||
volume: uiRun?.volume ?? null,
|
||||
expectedVolume: uiRun?.expected ?? part.volume,
|
||||
relativeError: uiRun?.relativeError ?? null,
|
||||
volumeMatches: uiRun?.volumeMatches ?? null,
|
||||
seconds: uiRun?.seconds ?? Math.round((Date.now() - startedAt) / 1000),
|
||||
pageErrors: uiRun?.pageErrors ?? [],
|
||||
stillsDir: part.stillsDir,
|
||||
driverExitCode: result.code,
|
||||
verdict,
|
||||
finishedAt: new Date().toISOString(),
|
||||
};
|
||||
fs.writeFileSync(path.join(dir, "report.json"), JSON.stringify(summary, null, 2));
|
||||
|
||||
if (options.json) line(JSON.stringify(summary));
|
||||
else {
|
||||
line(`零件 ${part.id}: ${verdict}(${summary.steps}/${summary.stepsTotal} 步,体积 ${summary.volume ?? "—"},${summary.seconds}s)`);
|
||||
line(`报告:${path.relative(REPO_ROOT, path.join(dir, "report.json"))}`);
|
||||
if (summary.stillsDir) line(`截图:${summary.stillsDir}`);
|
||||
}
|
||||
|
||||
if (verdict === "pass") process.exit(0);
|
||||
if (verdict === "product_fail") {
|
||||
console.error(`体积不一致:界面 ${summary.volume} / 记录 ${summary.expectedVolume}(相对误差 ${summary.relativeError})`);
|
||||
process.exit(1);
|
||||
}
|
||||
console.error("驱动未产出界面运行报告,按前置/运行失败处理。");
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
console.error(`失败:${error?.message ?? error}`);
|
||||
process.exit(error?.code === "E_PART" ? 2 : 1);
|
||||
});
|
||||
47
tools/reducer/list.mjs
Normal file
47
tools/reducer/list.mjs
Normal file
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* Purpose: 列出二级减速器的 23 个零件与分组(供人看,也供脚本读)。
|
||||
*
|
||||
* Usage:
|
||||
* node tools/reducer/list.mjs
|
||||
* node tools/reducer/list.mjs --group gears
|
||||
* node tools/reducer/list.mjs --json
|
||||
*
|
||||
* Exit: 0
|
||||
*/
|
||||
import { groups, parts, stats } from "./catalog.mjs";
|
||||
|
||||
const argv = process.argv.slice(2);
|
||||
if (argv.includes("--help") || argv.includes("-h")) {
|
||||
console.log("node tools/reducer/list.mjs [--group <id>] [--json]");
|
||||
process.exit(0);
|
||||
}
|
||||
const groupFilter = argv.includes("--group") ? argv[argv.indexOf("--group") + 1] : null;
|
||||
const asJson = argv.includes("--json");
|
||||
|
||||
const all = parts();
|
||||
const selected = groupFilter ? all.filter((part) => part.group === groupFilter) : all;
|
||||
const summary = stats();
|
||||
|
||||
if (asJson) {
|
||||
console.log(JSON.stringify({
|
||||
schema: "freecad-web/reducer-toolkit/catalog/v1",
|
||||
stats: summary,
|
||||
groups: groups(),
|
||||
parts: selected.map(({ id, document, title, group, groupLabel, steps, volume, reconstructable }) => ({
|
||||
id, document, title, group, groupLabel, steps, volume, reconstructable,
|
||||
})),
|
||||
}, null, 2));
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
for (const group of groups()) {
|
||||
const members = selected.filter((part) => part.group === group.id);
|
||||
if (!members.length) continue;
|
||||
console.log(`\n${group.label}(${group.id})`);
|
||||
for (const part of members) {
|
||||
const volume = part.volume == null ? "—" : part.volume.toFixed(1);
|
||||
console.log(` ${part.id} ${part.document.padEnd(30)} ${part.title.padEnd(28)} ${String(part.steps).padStart(2)} 步 体积 ${volume}${part.reconstructable ? "" : " (不可界面重建)"}`);
|
||||
}
|
||||
}
|
||||
console.log(`\n合计 ${summary.parts} 件 / ${summary.steps} 步 / 可界面重建 ${summary.reconstructable} 件`);
|
||||
153
tools/reducer/preflight.mjs
Normal file
153
tools/reducer/preflight.mjs
Normal file
@@ -0,0 +1,153 @@
|
||||
/**
|
||||
* Prerequisites for a headed reducer rebuild.
|
||||
*
|
||||
* Iron law: a missing dist, kernel, Chrome, DISPLAY or dev server is a
|
||||
* prerequisite failure, never a product failure. `create-*` exits 2 for these
|
||||
* and only ever exits 1 after the browser actually ran.
|
||||
*/
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { createRequire } from "node:module";
|
||||
import { REPO_ROOT, PROJECT_DIR, parts, projectManifest, stats } from "./catalog.mjs";
|
||||
import { findChrome, startStaticHost } from "../static-host.mjs";
|
||||
|
||||
const require = createRequire(path.join(REPO_ROOT, "web/package.json"));
|
||||
|
||||
function originPort(origin) {
|
||||
try {
|
||||
const url = new URL(origin);
|
||||
return Number(url.port || (url.protocol === "https:" ? 443 : 80));
|
||||
} catch {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
async function originReachable(origin, timeoutMs = 1500) {
|
||||
const controller = new AbortController();
|
||||
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
||||
try {
|
||||
const response = await fetch(`${origin}/index.html`, { signal: controller.signal, cache: "no-store" });
|
||||
return response.ok;
|
||||
} catch {
|
||||
return false;
|
||||
} finally {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
}
|
||||
|
||||
export async function preflight() {
|
||||
const checks = [];
|
||||
const add = (id, ok, detail, fix) => checks.push({ id, ok, detail, fix });
|
||||
|
||||
const manifest = projectManifest();
|
||||
const origin = manifest.appOrigin;
|
||||
|
||||
const distIndex = path.join(REPO_ROOT, "web/dist/index.html");
|
||||
add("dist", fs.existsSync(distIndex), fs.existsSync(distIndex) ? "web/dist/index.html 已就绪" : "web/dist/index.html 不存在",
|
||||
"cd web && npx vite build");
|
||||
|
||||
const wasm = ["web/dist/kernel", "web/public/kernel"].flatMap((rel) => {
|
||||
try {
|
||||
return fs.readdirSync(path.join(REPO_ROOT, rel)).filter((name) => name.endsWith(".wasm"));
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
});
|
||||
add("kernel", wasm.length > 0, wasm.length ? `内核产物 ${wasm.length} 个 .wasm` : "未找到内核 .wasm 产物",
|
||||
"cd web && node ../tools/sync-assets.mjs");
|
||||
|
||||
let chrome = null;
|
||||
try {
|
||||
chrome = findChrome();
|
||||
} catch {
|
||||
chrome = null;
|
||||
}
|
||||
add("chrome", Boolean(chrome), chrome || "未找到 Chrome/Chromium", "export FREECAD_CHROME=/usr/bin/google-chrome");
|
||||
|
||||
const display = process.env.DISPLAY || "";
|
||||
const displayOk = Boolean(display);
|
||||
add("display", displayOk, display ? `DISPLAY=${display}` : "DISPLAY 未设置(有头运行需要)", "DISPLAY=:1 node tools/reducer/create-part.mjs …");
|
||||
|
||||
let playwright = null;
|
||||
try {
|
||||
playwright = require.resolve("playwright");
|
||||
} catch {
|
||||
playwright = null;
|
||||
}
|
||||
add("playwright", Boolean(playwright), playwright ? "web/node_modules 可解析 playwright" : "web/node_modules 中找不到 playwright",
|
||||
"cd web && npm install");
|
||||
|
||||
const engine = ["web/tools/cad-ui-rebuild/drive.mjs", "web/tools/cad-ui-rebuild/assemble.mjs", "web/tools/cad-ui-rebuild/manifest.mjs"];
|
||||
const missingEngine = engine.filter((rel) => !fs.existsSync(path.join(REPO_ROOT, rel)));
|
||||
add("engine", missingEngine.length === 0, missingEngine.length ? `缺少共享引擎:${missingEngine.join(", ")}` : "界面重建引擎完整",
|
||||
"git status web/tools/cad-ui-rebuild");
|
||||
|
||||
const summary = stats();
|
||||
add("parts", summary.reconstructable === summary.parts,
|
||||
`${summary.reconstructable}/${summary.parts} 个零件具备界面步骤与构建记录(共 ${summary.steps} 步)`,
|
||||
"node web/tools/reducer-parts-course/build-ui-steps.mjs");
|
||||
|
||||
const originOk = await originReachable(origin);
|
||||
add("app", originOk, originOk ? `应用入口可达:${origin}` : `应用入口不可达:${origin}(create-part 会自动起静态服务)`,
|
||||
`cd web && npx vite build && node ../tools/static-host.mjs --root dist --port ${originPort(origin) || 5180}`);
|
||||
|
||||
return {
|
||||
ok: checks.every((check) => check.ok || check.id === "app"),
|
||||
checks,
|
||||
origin,
|
||||
projectDir: PROJECT_DIR,
|
||||
stats: summary,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a one-off project manifest that keeps the real paths but points at a
|
||||
* different app origin. The driver reads appOrigin from project.json only, so
|
||||
* this is the least invasive way to run it without touching the checked-in
|
||||
* manifest (port 5180 on this machine is occupied by an unrelated server).
|
||||
*/
|
||||
function derivedProject(originMW) {
|
||||
const raw = projectManifest();
|
||||
const base = {
|
||||
...raw,
|
||||
appOrigin: originMW,
|
||||
paths: Object.fromEntries(Object.entries(raw.paths ?? {}).map(([key, value]) => [key, path.resolve(PROJECT_DIR, value)])),
|
||||
};
|
||||
const dir = path.join(REPO_ROOT, "docs/current/reducer-toolkit/runtimes", new Date().toISOString().replace(/[:.]/g, "-"));
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
fs.writeFileSync(path.join(dir, "project.json"), `${JSON.stringify(base, null, 2)}\n`);
|
||||
return dir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure something serves the built app, reusing tools/static-host.mjs.
|
||||
*
|
||||
* Returns the project directory the driver should use: the checked-in one when
|
||||
* its appOrigin already serves the app, otherwise a derived manifest in the run
|
||||
* evidence tree that points at the ephemeral host we just started.
|
||||
*/
|
||||
export async function ensureOrigin(origin = projectManifest().appOrigin) {
|
||||
if (await originReachable(origin)) return { origin, started: false, projectDir: PROJECT_DIR, close: async () => {} };
|
||||
|
||||
const dist = path.join(REPO_ROOT, "web/dist");
|
||||
if (!fs.existsSync(path.join(dist, "index.html"))) {
|
||||
throw Object.assign(new Error(`web/dist/index.html 不存在,无法为 ${origin} 起服务`), { code: "E_PREFLIGHT" });
|
||||
}
|
||||
|
||||
// Preferred: take over the manifest port so the manifest itself stays valid.
|
||||
const port = originPort(origin) || 5180;
|
||||
try {
|
||||
const host = await startStaticHost(dist, "index.html", port);
|
||||
if (host.origin === origin) {
|
||||
return { origin: host.origin, started: true, projectDir: PROJECT_DIR, close: () => host.close() };
|
||||
}
|
||||
await host.close();
|
||||
} catch {
|
||||
/* port busy (or refused) — fall through to an ephemeral host */
|
||||
}
|
||||
|
||||
const host = await startStaticHost(dist, "index.html", 0);
|
||||
return { origin: host.origin, started: true, projectDir: derivedProject(host.origin), close: () => host.close() };
|
||||
}
|
||||
|
||||
export { parts };
|
||||
91
tools/reducer/self-test.mjs
Normal file
91
tools/reducer/self-test.mjs
Normal file
@@ -0,0 +1,91 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* Purpose: 无浏览器自测二级减速器工具包(目录、分组、前置、参数校验)。
|
||||
*
|
||||
* Usage: node tools/reducer/self-test.mjs
|
||||
* Exit: 0 全部通过 / 1 首个失败
|
||||
*/
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { REPO_ROOT, PROJECT_FILE, find, groups, parts, projectManifest, stats } from "./catalog.mjs";
|
||||
import { preflight } from "./preflight.mjs";
|
||||
|
||||
let failures = 0;
|
||||
function check(name, fn) {
|
||||
try {
|
||||
fn();
|
||||
console.log(`ok ${name}`);
|
||||
} catch (error) {
|
||||
failures += 1;
|
||||
console.error(`FAIL ${name}\n ${error instanceof Error ? error.message.split("\n")[0] : error}`);
|
||||
}
|
||||
}
|
||||
|
||||
function throwsCode(fn, code) {
|
||||
try {
|
||||
fn();
|
||||
} catch (error) {
|
||||
assert.equal(error.code, code, `expected ${code}, got ${error.code ?? error.message}`);
|
||||
return;
|
||||
}
|
||||
throw new Error(`expected ${code}, nothing thrown`);
|
||||
}
|
||||
|
||||
check("project manifest is the single source", () => {
|
||||
const manifest = projectManifest();
|
||||
assert.equal(manifest.parts.length, 23);
|
||||
assert.ok(fs.existsSync(PROJECT_FILE));
|
||||
});
|
||||
|
||||
check("catalog joins steps and replay for every part", () => {
|
||||
const all = parts();
|
||||
assert.equal(all.length, 23);
|
||||
assert.equal(stats().steps, 104);
|
||||
for (const part of all) {
|
||||
assert.ok(part.steps > 0, `${part.id} steps`);
|
||||
assert.ok(part.volume > 0, `${part.id} volume`);
|
||||
assert.ok(part.reconstructable, `${part.id} reconstructable`);
|
||||
assert.ok(fs.existsSync(path.join(REPO_ROOT, part.stepsFile)), `${part.id} stepsFile`);
|
||||
}
|
||||
});
|
||||
|
||||
check("groups cover all 23 parts", () => {
|
||||
const grouped = groups().reduce((sum, group) => sum + group.count, 0);
|
||||
assert.equal(grouped, 23);
|
||||
assert.ok(groups().some((group) => group.id === "bearings" && group.count === 9));
|
||||
assert.ok(groups().some((group) => group.id === "gears" && group.count === 2));
|
||||
});
|
||||
|
||||
check("find resolves by id and by document", () => {
|
||||
assert.equal(find("P06").document, "Bearing6206_Inner");
|
||||
assert.equal(find("p06").document, "Bearing6206_Inner");
|
||||
assert.equal(find("HousingCover").id, "P22");
|
||||
});
|
||||
|
||||
check("find rejects unknown ids and shell fragments", () => {
|
||||
throwsCode(() => find("P99"), "E_PART");
|
||||
throwsCode(() => find("; rm -rf /"), "E_PART");
|
||||
throwsCode(() => find("P01 --headed"), "E_PART");
|
||||
throwsCode(() => find(""), "E_PART");
|
||||
throwsCode(() => find(undefined), "E_PART");
|
||||
});
|
||||
|
||||
// preflight is async, so it runs before the assertions that depend on it.
|
||||
const report = await preflight();
|
||||
check("preflight checks are well formed", () => {
|
||||
assert.equal(typeof report.ok, "boolean");
|
||||
assert.ok(report.checks.length >= 7, `checks ${report.checks.length}`);
|
||||
for (const item of report.checks) assert.equal(typeof item.ok, "boolean", item.id);
|
||||
assert.match(report.origin, /^http:\/\/127\.0\.0\.1:\d+$/);
|
||||
assert.equal(report.stats.parts, 23);
|
||||
for (const id of ["dist", "kernel", "chrome", "display", "playwright", "engine", "parts", "app"]) {
|
||||
assert.ok(report.checks.some((item) => item.id === id), `missing check ${id}`);
|
||||
}
|
||||
});
|
||||
|
||||
if (failures) {
|
||||
console.error(`\nself-test: ${failures} failure(s)`);
|
||||
process.exit(1);
|
||||
}
|
||||
console.log(`self-test: OK(${stats().parts} 件 / ${stats().steps} 步;前置 ${report.ok ? "全部满足" : "有缺项"})`);
|
||||
@@ -47,6 +47,12 @@
|
||||
"build:console": "node tools/teaching-console/build-console.mjs",
|
||||
"check:console": "node tools/teaching-console/build-console.mjs --check && node tools/teaching-console/self-test.mjs",
|
||||
"teach:console": "node teaching/server.mjs",
|
||||
"reducer:list": "node ../tools/reducer/list.mjs",
|
||||
"reducer:part": "node ../tools/reducer/create-part.mjs",
|
||||
"reducer:all": "node ../tools/reducer/create-all.mjs",
|
||||
"reducer:assembly": "node ../tools/reducer/create-assembly.mjs",
|
||||
"build:reducer-page": "node tools/teaching-console/build-reducer-page.mjs",
|
||||
"check:reducer": "node ../tools/reducer/self-test.mjs && node tools/teaching-console/build-reducer-page.mjs --check && node tools/teaching-console/check-reducer-page.mjs",
|
||||
"prebuild": "npm run sync-show-python-family-fixture && npm run check:geometry-boundary",
|
||||
"dev": "npm run sync-api-index && npm run sync-object-index && npm run sync-format-index && npm run sync-module-registry && npm run sync-part-tier2-adapter && npm run sync-partdesign-tier2-adapter && npm run sync-sketcher-tier2-adapter && npm run sync-techdraw-tier2-adapter && npm run sync-import-tier2-adapter && npm run sync-mesh-tier2-adapter && npm run sync-material-tier1-adapter && npm run sync-tier2-remainder && npm run sync-tier3-stateful && npm run sync-viewprovider-index && npm run sync-property-index && npm run sync-geometry-index && npm run sync-document-graph-index && npm run sync-capability-index && npm run sync-tier1-readonly && npm run sync-tier4-restricted && npm run sync-api-adapter-fill && npm run sync-format-extensions && npm run sync-kernel && npm run sync-release-manifest && vite --host 0.0.0.0",
|
||||
"build": "npm run sync-api-index && npm run sync-object-index && npm run sync-format-index && npm run sync-module-registry && npm run sync-part-tier2-adapter && npm run sync-partdesign-tier2-adapter && npm run sync-sketcher-tier2-adapter && npm run sync-techdraw-tier2-adapter && npm run sync-import-tier2-adapter && npm run sync-mesh-tier2-adapter && npm run sync-material-tier1-adapter && npm run sync-tier2-remainder && npm run sync-tier3-stateful && npm run sync-viewprovider-index && npm run sync-property-index && npm run sync-geometry-index && npm run sync-document-graph-index && npm run sync-capability-index && npm run sync-tier1-readonly && npm run sync-tier4-restricted && npm run sync-api-adapter-fill && npm run sync-format-extensions && npm run sync-kernel && npm run sync-release-manifest && tsc --noEmit && vite build",
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -81,6 +81,7 @@
|
||||
<a href="features.html">功能列表</a>
|
||||
<a href="runner.html">可视化执行 →</a>
|
||||
<a href="console.html">教学控制台 →</a>
|
||||
<a href="reducer-toolkit.html">减速器建件工具 →</a>
|
||||
</nav>
|
||||
</div>
|
||||
</header>
|
||||
@@ -215,7 +216,7 @@
|
||||
</li>
|
||||
</ol>
|
||||
|
||||
<p><a class="cta" href="runner.html">打开可视化执行页</a><a class="cta" href="console.html">打开教学控制台(按工作台课程在线运行真实用例)</a><a class="cta secondary" href="features.html">查看 32 个模块的功能列表</a><a class="cta" href="cases/engine-block.html">案例教学:4 缸发动机缸体</a><a class="cta secondary" href="cases/t1-replica.html">案例教学:照 t1.stp 复刻零件</a><a class="cta secondary" href="cases/secondary-reducer.html">案例教学:二级齿轮减速器(界面操作)</a><a class="cta" href="cases/reducer-course.html">视频课程:二级减速器生产级建模(12 集)</a><a class="cta secondary" href="reducer-manual.html">初学者手册:二级减速器</a><a class="cta" href="cases/reducer-replay.html">过程可视化:二级减速器建模回放(24 件 + 装配)</a><a class="cta" href="cases/reducer-parts-course.html">逐零件建模过程视频(23 集 + 中文配音)</a><a class="cta secondary" href="reducer-parts-manual.html">零件设计入门:图文教案(14 章)</a><a class="cta" href="fcweb-toolkit.html">工具库:建零件与装配的通用工具(API 指南)</a><a class="cta" href="cases/assembly-tolerance.html">案例教学:装配公差分析(初学者)</a><a class="cta" href="cases/cam-teaching.html">案例教学:三轴 CAM(初学者)</a><a class="cta" href="cases/carrier.html">案例教学:航空母舰(含培训视频)</a><a class="cta" href="cases/fem-cantilever.html">案例教学:FEM 悬臂梁(应力云图)</a><a class="cta" href="cases/production-line.html">案例教学:三维产线(有头界面 + MCP)</a><a class="cta" href="cases/abb120-line.html">案例教学:ABB IRB 120 产线(MCP)</a><a class="cta" href="cases/production-line-course.html">视频课程:27 件 GLB 产线建模(18 集)</a><a class="cta secondary" href="z-up-verification.html">Three.js Z-up 验证报告</a><a class="cta" href="http://127.0.0.1:5180/bim-workshop.html">BIM 厂房车间(30×18m)</a><a class="cta secondary" href="bim-workshop-tutorial.html">BIM 厂房教程</a><a class="cta secondary" href="bim-workshop-manual.html">BIM 厂房初学者手册(视频)</a><a class="cta secondary" href="http://127.0.0.1:5180/workbench.html?module=Inspection&command=inspection.createRecompute" target="_blank" rel="noopener">直接打开这条案例</a></p>
|
||||
<p><a class="cta" href="runner.html">打开可视化执行页</a><a class="cta" href="console.html">打开教学控制台(按工作台课程在线运行真实用例)</a><a class="cta secondary" href="features.html">查看 32 个模块的功能列表</a><a class="cta" href="cases/engine-block.html">案例教学:4 缸发动机缸体</a><a class="cta secondary" href="cases/t1-replica.html">案例教学:照 t1.stp 复刻零件</a><a class="cta secondary" href="cases/secondary-reducer.html">案例教学:二级齿轮减速器(界面操作)</a><a class="cta" href="cases/reducer-course.html">视频课程:二级减速器生产级建模(12 集)</a><a class="cta secondary" href="reducer-manual.html">初学者手册:二级减速器</a><a class="cta" href="cases/reducer-replay.html">过程可视化:二级减速器建模回放(24 件 + 装配)</a><a class="cta" href="cases/reducer-parts-course.html">逐零件建模过程视频(23 集 + 中文配音)</a><a class="cta secondary" href="reducer-parts-manual.html">零件设计入门:图文教案(14 章)</a><a class="cta" href="fcweb-toolkit.html">工具库:建零件与装配的通用工具(API 指南)</a><a class="cta secondary" href="reducer-toolkit.html">工具:有头创建二级减速器(按零件分步 + 初学者讲义)</a><a class="cta" href="cases/assembly-tolerance.html">案例教学:装配公差分析(初学者)</a><a class="cta" href="cases/cam-teaching.html">案例教学:三轴 CAM(初学者)</a><a class="cta" href="cases/carrier.html">案例教学:航空母舰(含培训视频)</a><a class="cta" href="cases/fem-cantilever.html">案例教学:FEM 悬臂梁(应力云图)</a><a class="cta" href="cases/production-line.html">案例教学:三维产线(有头界面 + MCP)</a><a class="cta" href="cases/abb120-line.html">案例教学:ABB IRB 120 产线(MCP)</a><a class="cta" href="cases/production-line-course.html">视频课程:27 件 GLB 产线建模(18 集)</a><a class="cta secondary" href="z-up-verification.html">Three.js Z-up 验证报告</a><a class="cta" href="http://127.0.0.1:5180/bim-workshop.html">BIM 厂房车间(30×18m)</a><a class="cta secondary" href="bim-workshop-tutorial.html">BIM 厂房教程</a><a class="cta secondary" href="bim-workshop-manual.html">BIM 厂房初学者手册(视频)</a><a class="cta secondary" href="http://127.0.0.1:5180/workbench.html?module=Inspection&command=inspection.createRecompute" target="_blank" rel="noopener">直接打开这条案例</a></p>
|
||||
</section>
|
||||
|
||||
<section id="gallery">
|
||||
|
||||
358
web/teaching/reducer-toolkit.html
Normal file
358
web/teaching/reducer-toolkit.html
Normal file
@@ -0,0 +1,358 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>二级减速器 · 有头创建工具(初学者)</title>
|
||||
<style>
|
||||
:root{--bg:#0f1419;--panel:#17212b;--panel2:#1b2733;--line:#2a3a45;--text:#dbe6ee;--muted:#93a6b3;--accent:#73c6d4;--ok:#7fc98b;--warn:#e0b15c;--bad:#e58a8a;color-scheme:dark}
|
||||
*{box-sizing:border-box}
|
||||
body{margin:0;background:var(--bg);color:var(--text);font:15px/1.65 system-ui,-apple-system,"Segoe UI","Noto Sans CJK SC","Microsoft YaHei",sans-serif;overflow-wrap:break-word}
|
||||
a{color:var(--accent);text-decoration:none}a:hover{text-decoration:underline}
|
||||
code,pre{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}
|
||||
code{background:#0b1117;border:1px solid var(--line);border-radius:4px;padding:.1em .35em;font-size:.9em}
|
||||
header.top{position:sticky;top:0;z-index:10;display:flex;gap:14px;align-items:center;padding:10px 18px;background:rgba(15,20,25,.94);border-bottom:1px solid var(--line);backdrop-filter:blur(6px)}
|
||||
header.top .brand{font-weight:650}
|
||||
header.top .spacer{flex:1}
|
||||
main{max-width:1180px;margin:0 auto;padding:18px}
|
||||
h1{font-size:22px;margin:6px 0}
|
||||
h2{font-size:17px;margin:26px 0 10px;border-bottom:1px solid var(--line);padding-bottom:6px}
|
||||
h3{font-size:15px;margin:0}
|
||||
.lead{color:#c6d6e2}
|
||||
.muted{color:var(--muted)}.small{font-size:12.5px}
|
||||
.card{background:var(--panel);border:1px solid var(--line);border-radius:10px;padding:14px 16px;margin:12px 0}
|
||||
.pill{background:var(--panel2);border:1px solid var(--line);border-radius:999px;padding:1px 9px;font-size:12px;color:var(--muted)}
|
||||
.parts{display:grid;grid-template-columns:repeat(auto-fill,minmax(330px,1fr));gap:12px}
|
||||
.part{background:var(--panel);border:1px solid var(--line);border-radius:10px;padding:12px 14px}
|
||||
.part .head{display:flex;gap:8px;align-items:center;justify-content:space-between}
|
||||
.part .meta{color:var(--muted);font-size:12.5px;margin:4px 0 8px}
|
||||
.steps{margin:6px 0 10px 18px;padding:0;font-size:13px}
|
||||
.steps li{margin:2px 0}
|
||||
.steps .zh{color:var(--muted);margin-left:6px;font-size:12.5px}
|
||||
pre.cmd{background:#0b1117;border:1px solid var(--line);border-radius:8px;padding:8px 10px;font-size:12px;overflow:auto;white-space:pre-wrap;word-break:break-all}
|
||||
.links{display:flex;gap:12px;flex-wrap:wrap;font-size:13px;margin-top:8px}
|
||||
table{border-collapse:collapse;width:100%;font-size:13.5px}
|
||||
th,td{border-bottom:1px solid var(--line);padding:6px 8px;text-align:left;vertical-align:top}
|
||||
th{color:var(--muted);font-weight:500}
|
||||
.note{border-left:3px solid var(--warn);padding:8px 12px;background:#1d1a12;border-radius:0 8px 8px 0;margin:10px 0}
|
||||
@media (max-width:700px){.parts{grid-template-columns:1fr}main{padding:12px}}
|
||||
@media print{header.top,.links,pre.cmd{display:none!important}}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<header class="top"><span class="brand">二级减速器 · 有头创建工具</span><span class="spacer"></span>
|
||||
<a href="index.html">教学中心</a><a href="console.html">教学控制台</a><a href="reducer-parts-manual.html">图文教案</a></header>
|
||||
<main>
|
||||
<h1>在真实界面里造一台二级减速器</h1>
|
||||
<p class="lead">23 个零件,104 个界面步骤,一步一步点出来;最后装配成整机。每一步都是真实浏览器里的操作,建完由界面算出的体积与构建记录逐件对照。</p>
|
||||
|
||||
<div class="card">
|
||||
<h2 style="margin-top:0">先做三件事</h2>
|
||||
<ol>
|
||||
<li>构建前端:<code>cd web && npx vite build</code>(改过 <code>web/src</code> 之后必做)。</li>
|
||||
<li>检查环境:<code>node tools/reducer/create-part.mjs P01 --dry</code> —— 只看前置,不启动浏览器。</li>
|
||||
<li>建第一个零件:下面任意一张卡片里的命令,或直接打开<a href="console.html">教学控制台</a>点「开始」。</li>
|
||||
</ol>
|
||||
<p class="small muted">有头运行需要图形环境(<code>DISPLAY=:1</code>)与 Chrome。所有证据落在 <code>docs/current/reducer-toolkit/runs/</code>,截图落在 <code>web/tools/reducer-parts-course/ui-stills/</code>。</p>
|
||||
</div>
|
||||
|
||||
<div class="note"><strong>判定怎么读:</strong>通过 = 每一步都点到、最终体积与记录一致;产品失败(exit 1)= 界面建出的体积不对;前置失败(exit 2)= dist/内核/Chrome/DISPLAY/步骤文件缺失,此时还没开始点,不算产品问题。</div>
|
||||
|
||||
<section class="group" id="group-gears">
|
||||
<h2>齿轮 <span class="muted small">2 件</span></h2>
|
||||
<div class="parts"><article class="part" id="P01">
|
||||
<div class="head"><h3>P01 · 一级大齿轮 80 齿</h3><span class="pill">4 步</span></div>
|
||||
<div class="meta"><code>Gear2_80T</code> · 记录体积 1,374,346 mm³</div>
|
||||
<ol class="steps"><li><code>gear profile</code><span class="zh">齿轮轮廓(渐开线参数)</span></li><li><code>pad</code><span class="zh">拉伸成实体</span></li><li><code>cut profile</code><span class="zh">挖切轮廓</span></li><li><code>cut</code><span class="zh">挖切</span></li></ol>
|
||||
<pre class="cmd">cd "/media/mes123456/Elements SE/WebFreeCAD/FreeCADWasmDev/working/FreeCAD" && DISPLAY=:1 node tools/reducer/create-part.mjs P01</pre>
|
||||
<div class="links">
|
||||
<a href="console.html">在教学控制台运行</a>
|
||||
<a href="reducer-parts-manual.html#P01">图文教案</a>
|
||||
<a href="cases/reducer-replay.html?doc=Gear2_80T">建模回放</a>
|
||||
</div>
|
||||
</article><article class="part" id="P02">
|
||||
<div class="head"><h3>P02 · 二级大齿轮 100 齿</h3><span class="pill">4 步</span></div>
|
||||
<div class="meta"><code>Gear4_100T</code> · 记录体积 3,238,340 mm³</div>
|
||||
<ol class="steps"><li><code>gear profile</code><span class="zh">齿轮轮廓(渐开线参数)</span></li><li><code>pad</code><span class="zh">拉伸成实体</span></li><li><code>cut profile</code><span class="zh">挖切轮廓</span></li><li><code>cut</code><span class="zh">挖切</span></li></ol>
|
||||
<pre class="cmd">cd "/media/mes123456/Elements SE/WebFreeCAD/FreeCADWasmDev/working/FreeCAD" && DISPLAY=:1 node tools/reducer/create-part.mjs P02</pre>
|
||||
<div class="links">
|
||||
<a href="console.html">在教学控制台运行</a>
|
||||
<a href="reducer-parts-manual.html#P02">图文教案</a>
|
||||
<a href="cases/reducer-replay.html?doc=Gear4_100T">建模回放</a>
|
||||
</div>
|
||||
</article></div>
|
||||
</section><section class="group" id="group-shafts">
|
||||
<h2>轴 <span class="muted small">3 件</span></h2>
|
||||
<div class="parts"><article class="part" id="P03">
|
||||
<div class="head"><h3>P03 · 输入轴(带 20 齿小齿轮)</h3><span class="pill">4 步</span></div>
|
||||
<div class="meta"><code>Shaft_input</code> · 记录体积 381,626 mm³</div>
|
||||
<ol class="steps"><li><code>Gear1_20T involute</code><span class="zh">Gear1_20T 渐开线齿廓</span></li><li><code>Gear1_20T blank</code><span class="zh">Gear1_20T 毛坯</span></li><li><code>shaft profile</code><span class="zh">轴的外形轮廓</span></li><li><code>revolution</code><span class="zh">旋转成轴</span></li></ol>
|
||||
<pre class="cmd">cd "/media/mes123456/Elements SE/WebFreeCAD/FreeCADWasmDev/working/FreeCAD" && DISPLAY=:1 node tools/reducer/create-part.mjs P03</pre>
|
||||
<div class="links">
|
||||
<a href="console.html">在教学控制台运行</a>
|
||||
<a href="reducer-parts-manual.html#P03">图文教案</a>
|
||||
<a href="cases/reducer-replay.html?doc=Shaft_input">建模回放</a>
|
||||
</div>
|
||||
</article><article class="part" id="P04">
|
||||
<div class="head"><h3>P04 · 中间轴(双联,带 20 齿小齿轮 + 键槽)</h3><span class="pill">6 步</span></div>
|
||||
<div class="meta"><code>Shaft_intermediate</code> · 记录体积 522,631 mm³</div>
|
||||
<ol class="steps"><li><code>Gear3_20T involute</code><span class="zh">Gear3_20T 渐开线齿廓</span></li><li><code>Gear3_20T blank</code><span class="zh">Gear3_20T 毛坯</span></li><li><code>shaft profile</code><span class="zh">轴的外形轮廓</span></li><li><code>revolution</code><span class="zh">旋转成轴</span></li><li><code>Gear2_80T keyseat profile</code><span class="zh">Gear2_80T keyseat 草图</span></li><li><code>Gear2_80T keyseat</code><span class="zh">Gear2_80T 键槽</span></li></ol>
|
||||
<pre class="cmd">cd "/media/mes123456/Elements SE/WebFreeCAD/FreeCADWasmDev/working/FreeCAD" && DISPLAY=:1 node tools/reducer/create-part.mjs P04</pre>
|
||||
<div class="links">
|
||||
<a href="console.html">在教学控制台运行</a>
|
||||
<a href="reducer-parts-manual.html#P04">图文教案</a>
|
||||
<a href="cases/reducer-replay.html?doc=Shaft_intermediate">建模回放</a>
|
||||
</div>
|
||||
</article><article class="part" id="P05">
|
||||
<div class="head"><h3>P05 · 输出轴(带键槽,72.5 rpm)</h3><span class="pill">4 步</span></div>
|
||||
<div class="meta"><code>Shaft_output</code> · 记录体积 823,602 mm³</div>
|
||||
<ol class="steps"><li><code>shaft profile</code><span class="zh">轴的外形轮廓</span></li><li><code>revolution</code><span class="zh">旋转成轴</span></li><li><code>Gear4_100T keyseat profile</code><span class="zh">Gear4_100T keyseat 草图</span></li><li><code>Gear4_100T keyseat</code><span class="zh">Gear4_100T 键槽</span></li></ol>
|
||||
<pre class="cmd">cd "/media/mes123456/Elements SE/WebFreeCAD/FreeCADWasmDev/working/FreeCAD" && DISPLAY=:1 node tools/reducer/create-part.mjs P05</pre>
|
||||
<div class="links">
|
||||
<a href="console.html">在教学控制台运行</a>
|
||||
<a href="reducer-parts-manual.html#P05">图文教案</a>
|
||||
<a href="cases/reducer-replay.html?doc=Shaft_output">建模回放</a>
|
||||
</div>
|
||||
</article></div>
|
||||
</section><section class="group" id="group-bearings">
|
||||
<h2>轴承 <span class="muted small">9 件</span></h2>
|
||||
<div class="parts"><article class="part" id="P06">
|
||||
<div class="head"><h3>P06 · 6206 轴承内圈</h3><span class="pill">2 步</span></div>
|
||||
<div class="meta"><code>Bearing6206_Inner</code> · 记录体积 6,994 mm³</div>
|
||||
<ol class="steps"><li><code>profile</code><span class="zh">轮廓草图</span></li><li><code>revolution</code><span class="zh">旋转成轴</span></li></ol>
|
||||
<pre class="cmd">cd "/media/mes123456/Elements SE/WebFreeCAD/FreeCADWasmDev/working/FreeCAD" && DISPLAY=:1 node tools/reducer/create-part.mjs P06</pre>
|
||||
<div class="links">
|
||||
<a href="console.html">在教学控制台运行</a>
|
||||
<a href="reducer-parts-manual.html#P06">图文教案</a>
|
||||
<a href="cases/reducer-replay.html?doc=Bearing6206_Inner">建模回放</a>
|
||||
</div>
|
||||
</article><article class="part" id="P07">
|
||||
<div class="head"><h3>P07 · 6206 轴承外圈</h3><span class="pill">2 步</span></div>
|
||||
<div class="meta"><code>Bearing6206_Outer</code> · 记录体积 11,855 mm³</div>
|
||||
<ol class="steps"><li><code>profile</code><span class="zh">轮廓草图</span></li><li><code>revolution</code><span class="zh">旋转成轴</span></li></ol>
|
||||
<pre class="cmd">cd "/media/mes123456/Elements SE/WebFreeCAD/FreeCADWasmDev/working/FreeCAD" && DISPLAY=:1 node tools/reducer/create-part.mjs P07</pre>
|
||||
<div class="links">
|
||||
<a href="console.html">在教学控制台运行</a>
|
||||
<a href="reducer-parts-manual.html#P07">图文教案</a>
|
||||
<a href="cases/reducer-replay.html?doc=Bearing6206_Outer">建模回放</a>
|
||||
</div>
|
||||
</article><article class="part" id="P08">
|
||||
<div class="head"><h3>P08 · 6206 轴承滚珠(9 粒圆周阵列)</h3><span class="pill">2 步</span></div>
|
||||
<div class="meta"><code>Bearing6206_Balls</code> · 记录体积 4,040 mm³</div>
|
||||
<ol class="steps"><li><code>ball</code><span class="zh">ball</span></li><li><code>ball pattern</code><span class="zh">ball pattern</span></li></ol>
|
||||
<pre class="cmd">cd "/media/mes123456/Elements SE/WebFreeCAD/FreeCADWasmDev/working/FreeCAD" && DISPLAY=:1 node tools/reducer/create-part.mjs P08</pre>
|
||||
<div class="links">
|
||||
<a href="console.html">在教学控制台运行</a>
|
||||
<a href="reducer-parts-manual.html#P08">图文教案</a>
|
||||
<a href="cases/reducer-replay.html?doc=Bearing6206_Balls">建模回放</a>
|
||||
</div>
|
||||
</article><article class="part" id="P09">
|
||||
<div class="head"><h3>P09 · 6209 轴承内圈</h3><span class="pill">2 步</span></div>
|
||||
<div class="meta"><code>Bearing6209_Inner</code> · 记录体积 13,950 mm³</div>
|
||||
<ol class="steps"><li><code>profile</code><span class="zh">轮廓草图</span></li><li><code>revolution</code><span class="zh">旋转成轴</span></li></ol>
|
||||
<pre class="cmd">cd "/media/mes123456/Elements SE/WebFreeCAD/FreeCADWasmDev/working/FreeCAD" && DISPLAY=:1 node tools/reducer/create-part.mjs P09</pre>
|
||||
<div class="links">
|
||||
<a href="console.html">在教学控制台运行</a>
|
||||
<a href="reducer-parts-manual.html#P09">图文教案</a>
|
||||
<a href="cases/reducer-replay.html?doc=Bearing6209_Inner">建模回放</a>
|
||||
</div>
|
||||
</article><article class="part" id="P10">
|
||||
<div class="head"><h3>P10 · 6209 轴承外圈</h3><span class="pill">2 步</span></div>
|
||||
<div class="meta"><code>Bearing6209_Outer</code> · 记录体积 22,471 mm³</div>
|
||||
<ol class="steps"><li><code>profile</code><span class="zh">轮廓草图</span></li><li><code>revolution</code><span class="zh">旋转成轴</span></li></ol>
|
||||
<pre class="cmd">cd "/media/mes123456/Elements SE/WebFreeCAD/FreeCADWasmDev/working/FreeCAD" && DISPLAY=:1 node tools/reducer/create-part.mjs P10</pre>
|
||||
<div class="links">
|
||||
<a href="console.html">在教学控制台运行</a>
|
||||
<a href="reducer-parts-manual.html#P10">图文教案</a>
|
||||
<a href="cases/reducer-replay.html?doc=Bearing6209_Outer">建模回放</a>
|
||||
</div>
|
||||
</article><article class="part" id="P11">
|
||||
<div class="head"><h3>P11 · 6209 轴承滚珠</h3><span class="pill">2 步</span></div>
|
||||
<div class="meta"><code>Bearing6209_Balls</code> · 记录体积 10,725 mm³</div>
|
||||
<ol class="steps"><li><code>ball</code><span class="zh">ball</span></li><li><code>ball pattern</code><span class="zh">ball pattern</span></li></ol>
|
||||
<pre class="cmd">cd "/media/mes123456/Elements SE/WebFreeCAD/FreeCADWasmDev/working/FreeCAD" && DISPLAY=:1 node tools/reducer/create-part.mjs P11</pre>
|
||||
<div class="links">
|
||||
<a href="console.html">在教学控制台运行</a>
|
||||
<a href="reducer-parts-manual.html#P11">图文教案</a>
|
||||
<a href="cases/reducer-replay.html?doc=Bearing6209_Balls">建模回放</a>
|
||||
</div>
|
||||
</article><article class="part" id="P12">
|
||||
<div class="head"><h3>P12 · 6211 轴承内圈</h3><span class="pill">2 步</span></div>
|
||||
<div class="meta"><code>Bearing6211_Inner</code> · 记录体积 17,782 mm³</div>
|
||||
<ol class="steps"><li><code>profile</code><span class="zh">轮廓草图</span></li><li><code>revolution</code><span class="zh">旋转成轴</span></li></ol>
|
||||
<pre class="cmd">cd "/media/mes123456/Elements SE/WebFreeCAD/FreeCADWasmDev/working/FreeCAD" && DISPLAY=:1 node tools/reducer/create-part.mjs P12</pre>
|
||||
<div class="links">
|
||||
<a href="console.html">在教学控制台运行</a>
|
||||
<a href="reducer-parts-manual.html#P12">图文教案</a>
|
||||
<a href="cases/reducer-replay.html?doc=Bearing6211_Inner">建模回放</a>
|
||||
</div>
|
||||
</article><article class="part" id="P13">
|
||||
<div class="head"><h3>P13 · 6211 轴承外圈</h3><span class="pill">2 步</span></div>
|
||||
<div class="meta"><code>Bearing6211_Outer</code> · 记录体积 28,400 mm³</div>
|
||||
<ol class="steps"><li><code>profile</code><span class="zh">轮廓草图</span></li><li><code>revolution</code><span class="zh">旋转成轴</span></li></ol>
|
||||
<pre class="cmd">cd "/media/mes123456/Elements SE/WebFreeCAD/FreeCADWasmDev/working/FreeCAD" && DISPLAY=:1 node tools/reducer/create-part.mjs P13</pre>
|
||||
<div class="links">
|
||||
<a href="console.html">在教学控制台运行</a>
|
||||
<a href="reducer-parts-manual.html#P13">图文教案</a>
|
||||
<a href="cases/reducer-replay.html?doc=Bearing6211_Outer">建模回放</a>
|
||||
</div>
|
||||
</article><article class="part" id="P14">
|
||||
<div class="head"><h3>P14 · 6211 轴承滚珠</h3><span class="pill">2 步</span></div>
|
||||
<div class="meta"><code>Bearing6211_Balls</code> · 记录体积 21,047 mm³</div>
|
||||
<ol class="steps"><li><code>ball</code><span class="zh">ball</span></li><li><code>ball pattern</code><span class="zh">ball pattern</span></li></ol>
|
||||
<pre class="cmd">cd "/media/mes123456/Elements SE/WebFreeCAD/FreeCADWasmDev/working/FreeCAD" && DISPLAY=:1 node tools/reducer/create-part.mjs P14</pre>
|
||||
<div class="links">
|
||||
<a href="console.html">在教学控制台运行</a>
|
||||
<a href="reducer-parts-manual.html#P14">图文教案</a>
|
||||
<a href="cases/reducer-replay.html?doc=Bearing6211_Balls">建模回放</a>
|
||||
</div>
|
||||
</article></div>
|
||||
</section><section class="group" id="group-keys">
|
||||
<h2>平键 <span class="muted small">2 件</span></h2>
|
||||
<div class="parts"><article class="part" id="P15">
|
||||
<div class="head"><h3>P15 · 中间轴平键(80 齿齿轮用)</h3><span class="pill">2 步</span></div>
|
||||
<div class="meta"><code>Key_intermediate_Gear2_80T</code> · 记录体积 4,293 mm³</div>
|
||||
<ol class="steps"><li><code>key profile</code><span class="zh">key 草图</span></li><li><code>key pad</code><span class="zh">key pad</span></li></ol>
|
||||
<pre class="cmd">cd "/media/mes123456/Elements SE/WebFreeCAD/FreeCADWasmDev/working/FreeCAD" && DISPLAY=:1 node tools/reducer/create-part.mjs P15</pre>
|
||||
<div class="links">
|
||||
<a href="console.html">在教学控制台运行</a>
|
||||
<a href="reducer-parts-manual.html#P15">图文教案</a>
|
||||
<a href="cases/reducer-replay.html?doc=Key_intermediate_Gear2_80T">建模回放</a>
|
||||
</div>
|
||||
</article><article class="part" id="P16">
|
||||
<div class="head"><h3>P16 · 输出轴平键(100 齿齿轮用)</h3><span class="pill">2 步</span></div>
|
||||
<div class="meta"><code>Key_output_Gear4_100T</code> · 记录体积 8,617 mm³</div>
|
||||
<ol class="steps"><li><code>key profile</code><span class="zh">key 草图</span></li><li><code>key pad</code><span class="zh">key pad</span></li></ol>
|
||||
<pre class="cmd">cd "/media/mes123456/Elements SE/WebFreeCAD/FreeCADWasmDev/working/FreeCAD" && DISPLAY=:1 node tools/reducer/create-part.mjs P16</pre>
|
||||
<div class="links">
|
||||
<a href="console.html">在教学控制台运行</a>
|
||||
<a href="reducer-parts-manual.html#P16">图文教案</a>
|
||||
<a href="cases/reducer-replay.html?doc=Key_output_Gear4_100T">建模回放</a>
|
||||
</div>
|
||||
</article></div>
|
||||
</section><section class="group" id="group-seals">
|
||||
<h2>骨架油封 <span class="muted small">3 件</span></h2>
|
||||
<div class="parts"><article class="part" id="P17">
|
||||
<div class="head"><h3>P17 · 输入轴骨架油封</h3><span class="pill">2 步</span></div>
|
||||
<div class="meta"><code>Seal_input</code> · 记录体积 6,590 mm³</div>
|
||||
<ol class="steps"><li><code>seal profile</code><span class="zh">seal 草图</span></li><li><code>seal revolution</code><span class="zh">seal revolution</span></li></ol>
|
||||
<pre class="cmd">cd "/media/mes123456/Elements SE/WebFreeCAD/FreeCADWasmDev/working/FreeCAD" && DISPLAY=:1 node tools/reducer/create-part.mjs P17</pre>
|
||||
<div class="links">
|
||||
<a href="console.html">在教学控制台运行</a>
|
||||
<a href="reducer-parts-manual.html#P17">图文教案</a>
|
||||
<a href="cases/reducer-replay.html?doc=Seal_input">建模回放</a>
|
||||
</div>
|
||||
</article><article class="part" id="P18">
|
||||
<div class="head"><h3>P18 · 中间轴骨架油封</h3><span class="pill">2 步</span></div>
|
||||
<div class="meta"><code>Seal_intermediate</code> · 记录体积 11,832 mm³</div>
|
||||
<ol class="steps"><li><code>seal profile</code><span class="zh">seal 草图</span></li><li><code>seal revolution</code><span class="zh">seal revolution</span></li></ol>
|
||||
<pre class="cmd">cd "/media/mes123456/Elements SE/WebFreeCAD/FreeCADWasmDev/working/FreeCAD" && DISPLAY=:1 node tools/reducer/create-part.mjs P18</pre>
|
||||
<div class="links">
|
||||
<a href="console.html">在教学控制台运行</a>
|
||||
<a href="reducer-parts-manual.html#P18">图文教案</a>
|
||||
<a href="cases/reducer-replay.html?doc=Seal_intermediate">建模回放</a>
|
||||
</div>
|
||||
</article><article class="part" id="P19">
|
||||
<div class="head"><h3>P19 · 输出轴骨架油封</h3><span class="pill">2 步</span></div>
|
||||
<div class="meta"><code>Seal_output</code> · 记录体积 15,635 mm³</div>
|
||||
<ol class="steps"><li><code>seal profile</code><span class="zh">seal 草图</span></li><li><code>seal revolution</code><span class="zh">seal revolution</span></li></ol>
|
||||
<pre class="cmd">cd "/media/mes123456/Elements SE/WebFreeCAD/FreeCADWasmDev/working/FreeCAD" && DISPLAY=:1 node tools/reducer/create-part.mjs P19</pre>
|
||||
<div class="links">
|
||||
<a href="console.html">在教学控制台运行</a>
|
||||
<a href="reducer-parts-manual.html#P19">图文教案</a>
|
||||
<a href="cases/reducer-replay.html?doc=Seal_output">建模回放</a>
|
||||
</div>
|
||||
</article></div>
|
||||
</section><section class="group" id="group-coupling">
|
||||
<h2>联轴器 <span class="muted small">1 件</span></h2>
|
||||
<div class="parts"><article class="part" id="P20">
|
||||
<div class="head"><h3>P20 · 输入联轴器(轮毂 + 法兰 + 内孔 + 螺栓孔)</h3><span class="pill">8 步</span></div>
|
||||
<div class="meta"><code>Coupling_input</code> · 记录体积 68,247 mm³</div>
|
||||
<ol class="steps"><li><code>hub profile</code><span class="zh">轮毂轮廓</span></li><li><code>hub</code><span class="zh">轮毂</span></li><li><code>flange profile</code><span class="zh">法兰轮廓</span></li><li><code>flange</code><span class="zh">法兰</span></li><li><code>bore profile</code><span class="zh">轴承孔轮廓</span></li><li><code>bore</code><span class="zh">内孔</span></li><li><code>bolt profile</code><span class="zh">螺栓孔轮廓</span></li><li><code>bolt pocket</code><span class="zh">螺栓沉孔</span></li></ol>
|
||||
<pre class="cmd">cd "/media/mes123456/Elements SE/WebFreeCAD/FreeCADWasmDev/working/FreeCAD" && DISPLAY=:1 node tools/reducer/create-part.mjs P20</pre>
|
||||
<div class="links">
|
||||
<a href="console.html">在教学控制台运行</a>
|
||||
<a href="reducer-parts-manual.html#P20">图文教案</a>
|
||||
<a href="cases/reducer-replay.html?doc=Coupling_input">建模回放</a>
|
||||
</div>
|
||||
</article></div>
|
||||
</section><section class="group" id="group-housing">
|
||||
<h2>箱体与箱盖 <span class="muted small">3 件</span></h2>
|
||||
<div class="parts"><article class="part" id="P21">
|
||||
<div class="head"><h3>P21 · 剖分式下箱体(16 步)</h3><span class="pill">16 步</span></div>
|
||||
<div class="meta"><code>HousingBase</code> · 记录体积 4,887,641 mm³</div>
|
||||
<ol class="steps"><li><code>outer profile</code><span class="zh">外形轮廓</span></li><li><code>outer pad</code><span class="zh">外壳拉伸</span></li><li><code>CavityBossLeft profile</code><span class="zh">CavityBossLeft 草图</span></li><li><code>CavityBossLeft</code><span class="zh">CavityBossLeft</span></li><li><code>CavityMiddle profile</code><span class="zh">CavityMiddle 草图</span></li><li><code>CavityMiddle</code><span class="zh">CavityMiddle</span></li><li><code>CavityBossRight profile</code><span class="zh">CavityBossRight 草图</span></li><li><code>CavityBossRight</code><span class="zh">CavityBossRight</span></li><li><code>bore profile</code><span class="zh">轴承孔轮廓</span></li><li><code>bores</code><span class="zh">镗轴承孔</span></li><li><code>seal bore Near</code><span class="zh">seal bore Near</span></li><li><code>seal bores Near</code><span class="zh">seal bores Near</span></li><li><code>seal bore Far</code><span class="zh">seal bore Far</span></li><li><code>seal bores Far</code><span class="zh">seal bores Far</span></li><li><code>bolt profile</code><span class="zh">螺栓孔轮廓</span></li><li><code>bolts</code><span class="zh">bolts</span></li></ol>
|
||||
<pre class="cmd">cd "/media/mes123456/Elements SE/WebFreeCAD/FreeCADWasmDev/working/FreeCAD" && DISPLAY=:1 node tools/reducer/create-part.mjs P21</pre>
|
||||
<div class="links">
|
||||
<a href="console.html">在教学控制台运行</a>
|
||||
<a href="reducer-parts-manual.html#P21">图文教案</a>
|
||||
<a href="cases/reducer-replay.html?doc=HousingBase">建模回放</a>
|
||||
</div>
|
||||
</article><article class="part" id="P22">
|
||||
<div class="head"><h3>P22 · 上箱盖(26 步,含观察孔与吊耳)</h3><span class="pill">26 步</span></div>
|
||||
<div class="meta"><code>HousingCover</code> · 记录体积 4,418,502 mm³</div>
|
||||
<ol class="steps"><li><code>outer profile</code><span class="zh">外形轮廓</span></li><li><code>outer pad</code><span class="zh">外壳拉伸</span></li><li><code>CoverCavityBossLeft profile</code><span class="zh">CoverCavityBossLeft 草图</span></li><li><code>CoverCavityBossLeft</code><span class="zh">CoverCavityBossLeft</span></li><li><code>CoverCavityMiddle profile</code><span class="zh">CoverCavityMiddle 草图</span></li><li><code>CoverCavityMiddle</code><span class="zh">CoverCavityMiddle</span></li><li><code>CoverCavityBossRight profile</code><span class="zh">CoverCavityBossRight 草图</span></li><li><code>CoverCavityBossRight</code><span class="zh">CoverCavityBossRight</span></li><li><code>bore profile</code><span class="zh">轴承孔轮廓</span></li><li><code>bores</code><span class="zh">镗轴承孔</span></li><li><code>seal bore Near</code><span class="zh">seal bore Near</span></li><li><code>seal bores Near</code><span class="zh">seal bores Near</span></li><li><code>seal bore Far</code><span class="zh">seal bore Far</span></li><li><code>seal bores Far</code><span class="zh">seal bores Far</span></li><li><code>inspection profile</code><span class="zh">观察孔轮廓</span></li><li><code>inspection opening</code><span class="zh">开观察孔</span></li><li><code>inspection bolt profile</code><span class="zh">inspection bolt 草图</span></li><li><code>inspection bolts</code><span class="zh">inspection bolts</span></li><li><code>breather profile</code><span class="zh">breather 草图</span></li><li><code>breather seat</code><span class="zh">breather seat</span></li><li><code>LiftBossA profile</code><span class="zh">LiftBossA 草图</span></li><li><code>LiftBossA</code><span class="zh">LiftBossA</span></li><li><code>LiftBossB profile</code><span class="zh">LiftBossB 草图</span></li><li><code>LiftBossB</code><span class="zh">LiftBossB</span></li><li><code>lifting profile</code><span class="zh">吊耳轮廓</span></li><li><code>lifting threads</code><span class="zh">吊耳螺纹孔</span></li></ol>
|
||||
<pre class="cmd">cd "/media/mes123456/Elements SE/WebFreeCAD/FreeCADWasmDev/working/FreeCAD" && DISPLAY=:1 node tools/reducer/create-part.mjs P22</pre>
|
||||
<div class="links">
|
||||
<a href="console.html">在教学控制台运行</a>
|
||||
<a href="reducer-parts-manual.html#P22">图文教案</a>
|
||||
<a href="cases/reducer-replay.html?doc=HousingCover">建模回放</a>
|
||||
</div>
|
||||
</article><article class="part" id="P23">
|
||||
<div class="head"><h3>P23 · 观察孔盖板</h3><span class="pill">4 步</span></div>
|
||||
<div class="meta"><code>InspectionPlate</code> · 记录体积 149,854 mm³</div>
|
||||
<ol class="steps"><li><code>plate profile</code><span class="zh">plate 草图</span></li><li><code>plate</code><span class="zh">plate</span></li><li><code>plate holes profile</code><span class="zh">plate holes 草图</span></li><li><code>plate holes</code><span class="zh">plate holes</span></li></ol>
|
||||
<pre class="cmd">cd "/media/mes123456/Elements SE/WebFreeCAD/FreeCADWasmDev/working/FreeCAD" && DISPLAY=:1 node tools/reducer/create-part.mjs P23</pre>
|
||||
<div class="links">
|
||||
<a href="console.html">在教学控制台运行</a>
|
||||
<a href="reducer-parts-manual.html#P23">图文教案</a>
|
||||
<a href="cases/reducer-replay.html?doc=InspectionPlate">建模回放</a>
|
||||
</div>
|
||||
</article></div>
|
||||
</section>
|
||||
|
||||
<section class="group" id="assembly">
|
||||
<h2>装配 <span class="muted small">1 台</span></h2>
|
||||
<article class="part">
|
||||
<div class="head"><h3>SecondaryReducer · 23 件合成整机</h3><span class="pill">插入链接</span></div>
|
||||
<div class="meta">新建装配文档,按构建记录的位置与旋转逐个插入并接地;插入数与期望比对。</div>
|
||||
<pre class="cmd">cd "/media/mes123456/Elements SE/WebFreeCAD/FreeCADWasmDev/working/FreeCAD" && DISPLAY=:1 node tools/reducer/create-assembly.mjs</pre>
|
||||
<div class="links"><a href="console.html">在教学控制台运行</a><a href="reducer-manual.html">初学者手册(设计原理)</a><a href="cases/reducer-course.html">视频课程</a></div>
|
||||
</article>
|
||||
</section>
|
||||
|
||||
<section class="group" id="tools">
|
||||
<h2>这套工具本身</h2>
|
||||
<table>
|
||||
<thead><tr><th>命令</th><th>作用</th></tr></thead>
|
||||
<tbody>
|
||||
<tr><td><code>node tools/reducer/list.mjs</code></td><td>列出 23 个零件、分组、步数与体积</td></tr>
|
||||
<tr><td><code>node tools/reducer/create-part.mjs P06</code></td><td>有头重建一个零件(P 编号或 Document 名都行)</td></tr>
|
||||
<tr><td><code>node tools/reducer/create-part.mjs P06 --dry</code></td><td>只做前置检查,不启动浏览器</td></tr>
|
||||
<tr><td><code>node tools/reducer/create-part.mjs P06 --slow</code></td><td>放慢点击,适合边看边学</td></tr>
|
||||
<tr><td><code>node tools/reducer/create-all.mjs --group bearings</code></td><td>按组串行重建</td></tr>
|
||||
<tr><td><code>node tools/reducer/create-all.mjs --all --keep-going</code></td><td>全部 23 件,出错继续</td></tr>
|
||||
<tr><td><code>node tools/reducer/create-assembly.mjs</code></td><td>真实界面装配</td></tr>
|
||||
<tr><td><code>node tools/reducer/self-test.mjs</code></td><td>无浏览器自测(目录、分组、参数校验、前置)</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p class="small muted">工具只做编排与前置检查;每一步的点击由共享引擎 <code>web/tools/cad-ui-rebuild/</code> 执行,构建记录来自 <code>web/teaching/cases/secondary-reducer-pro/out/replay/</code>,界面步骤来自 <code>web/tools/reducer-parts-course/out/ui-steps/</code>。</p>
|
||||
</section>
|
||||
|
||||
<section class="group" id="troubleshooting">
|
||||
<h2>常见问题</h2>
|
||||
<table>
|
||||
<thead><tr><th>现象</th><th>原因与处理</th></tr></thead>
|
||||
<tbody>
|
||||
<tr><td>退出码 2,日志里有「前置缺失」</td><td>dist、内核产物、Chrome、DISPLAY 或步骤文件缺失。照提示修,或用 <code>--dry</code> 看全部检查项。</td></tr>
|
||||
<tr><td>退出码 1,体积不一致</td><td>界面建出的几何与构建记录不同,是产品回归;报告里给出两边体积与相对误差。</td></tr>
|
||||
<tr><td>看不到浏览器窗口</td><td>有头需要可用的 X 显示;在带图形界面的会话里用 <code>DISPLAY=:1</code> 启动。</td></tr>
|
||||
<tr><td>页面打开是空白/旧版本</td><td>先 <code>cd web && npx vite build</code>,工具会自动为构建好的 dist 起临时服务。</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
|
||||
<p class="small muted" style="margin:26px 0 40px">本页由 <code>web/tools/teaching-console/build-reducer-page.mjs</code> 生成,请勿手改。</p>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
@@ -33,12 +33,21 @@ export const CONSOLE_ROOT = path.join(REPO_ROOT, "docs/current/teaching-console"
|
||||
const SUITE_ENTRY = path.join(REPO_ROOT, "tools/web-freecad-functional-suite.mjs");
|
||||
const PROBE_ENTRY = path.join(REPO_ROOT, "tools/layout-probe.mjs");
|
||||
const HOST_ENTRY = path.join(REPO_ROOT, "tools/static-host.mjs");
|
||||
const REDUCER_PART = path.join(REPO_ROOT, "tools/reducer/create-part.mjs");
|
||||
const REDUCER_ASSEMBLY = path.join(REPO_ROOT, "tools/reducer/create-assembly.mjs");
|
||||
|
||||
const LINE_LIMIT = 2000;
|
||||
const BYTE_LIMIT = 512 * 1024;
|
||||
const POLL_MS = 750;
|
||||
const PROBE_PAGES = new Set(["/", "/project.html", "/partdesign.html"]);
|
||||
const TIMEOUTS = { suite: 45 * 60_000, probe: 10 * 60_000, host: 2 * 60_000 };
|
||||
const TIMEOUTS = {
|
||||
suite: 45 * 60_000,
|
||||
probe: 10 * 60_000,
|
||||
host: 2 * 60_000,
|
||||
// A 26-step cover part takes ~10 min headed; leave room without hanging forever.
|
||||
"reducer-part": 40 * 60_000,
|
||||
"reducer-assembly": 45 * 60_000,
|
||||
};
|
||||
|
||||
export class JobError extends Error {
|
||||
constructor(code, message, detail) {
|
||||
@@ -189,6 +198,17 @@ export function buildJobArgv(lesson, params = {}, { jobDir } = {}) {
|
||||
dir: jobDir,
|
||||
};
|
||||
}
|
||||
if (job.kind === "reducer-part") {
|
||||
const partId = String(job.partId ?? "");
|
||||
if (!/^P\d{2}$/.test(partId)) throw new JobError("E_PARAM", `非法零件编号:${partId.slice(0, 20)}`);
|
||||
const argv = [process.execPath, REDUCER_PART, partId];
|
||||
if (job.dry) argv.push("--dry");
|
||||
argv.push("--out", jobDir, "--json");
|
||||
return { argv, dir: jobDir };
|
||||
}
|
||||
if (job.kind === "reducer-assembly") {
|
||||
return { argv: [process.execPath, REDUCER_ASSEMBLY, "--out", jobDir, "--json"], dir: jobDir };
|
||||
}
|
||||
throw new JobError("E_PARAM", `未知课程类型:${job.kind}`);
|
||||
}
|
||||
|
||||
@@ -349,6 +369,26 @@ export function createRunner({ root = CONSOLE_ROOT } = {}) {
|
||||
else if (code === 0) job.verdict = "pass";
|
||||
else if (code === 2) job.verdict = "precondition_fail";
|
||||
else job.verdict = "product_fail";
|
||||
} else if (job.kind === "reducer-part" || job.kind === "reducer-assembly") {
|
||||
const report = readJson(path.join(job.dir, "report.json")).value;
|
||||
const label = job.kind === "reducer-part" ? (report?.part?.id ?? "part") : "assembly";
|
||||
job.progress = {
|
||||
...job.progress,
|
||||
planned: 1,
|
||||
completed: 1,
|
||||
results: report ? [{
|
||||
id: label,
|
||||
title: report.part?.title ?? report.document ?? "装配",
|
||||
status: report.verdict === "pass" ? "passed" : report.verdict === "product_fail" ? "failed" : "blocked",
|
||||
seconds: report.seconds ?? null,
|
||||
error: report.verdict === "product_fail" && report.volumeMatches === false
|
||||
? `体积 ${report.volume} ≠ 记录 ${report.expectedVolume}` : (report.fatal ?? null),
|
||||
}] : [],
|
||||
};
|
||||
if (job.cancelled) job.verdict = "cancelled";
|
||||
else if (job.timedOut) job.verdict = "timeout";
|
||||
else if (!report) job.verdict = code === 2 ? "precondition_fail" : "run_fail";
|
||||
else job.verdict = report.verdict;
|
||||
} else if (job.kind === "host") {
|
||||
// The host lesson succeeds once ORIGIN is printed; an explicit user
|
||||
// cancel still reads as cancelled even if that already happened.
|
||||
@@ -404,7 +444,12 @@ export function createRunner({ root = CONSOLE_ROOT } = {}) {
|
||||
exitCode: null, runDir: null, verdict: null, error: null, fatal: null,
|
||||
cancelRequested: false, cancelled: false, timedOut: false,
|
||||
lines: [], bytes: 0, partial: { stdout: "", stderr: "" },
|
||||
progress: { planned: entry.job.selectable ? (params.only?.length ?? 0) : (entry.job.only?.length ?? 0), completed: 0, current: null, counts: null, results: [] },
|
||||
progress: {
|
||||
planned: entry.job.kind === "reducer-part" || entry.job.kind === "reducer-assembly"
|
||||
? 1
|
||||
: entry.job.selectable ? (params.only?.length ?? 0) : (entry.job.only?.length ?? 0),
|
||||
completed: 0, current: null, counts: null, results: [],
|
||||
},
|
||||
command: argv ? argvToCommand(argv) : "(无命令:仅检查前置条件)",
|
||||
};
|
||||
fs.writeFileSync(path.join(dir, "job.json"), JSON.stringify({
|
||||
|
||||
254
web/tools/teaching-console/build-reducer-page.mjs
Normal file
254
web/tools/teaching-console/build-reducer-page.mjs
Normal file
@@ -0,0 +1,254 @@
|
||||
#!/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) => `<li><code>${esc(step.label)}</code><span class="zh">${esc(zh(step.label))}</span></li>`).join("");
|
||||
return `<article class="part" id="${esc(part.id)}">
|
||||
<div class="head"><h3>${esc(part.id)} · ${esc(part.title)}</h3><span class="pill">${part.steps} 步</span></div>
|
||||
<div class="meta"><code>${esc(part.document)}</code> · 记录体积 ${esc(volumeText(part.volume))}</div>
|
||||
<ol class="steps">${rows}</ol>
|
||||
<pre class="cmd">cd "${esc(REPO_ROOT)}" && DISPLAY=:1 node tools/reducer/create-part.mjs ${esc(part.id)}</pre>
|
||||
<div class="links">
|
||||
<a href="console.html">在教学控制台运行</a>
|
||||
<a href="reducer-parts-manual.html#${esc(part.id)}">图文教案</a>
|
||||
<a href="cases/reducer-replay.html?doc=${esc(part.document)}">建模回放</a>
|
||||
</div>
|
||||
</article>`;
|
||||
}
|
||||
|
||||
function render() {
|
||||
const summary = stats();
|
||||
const all = parts();
|
||||
const sections = groups().map((group) => {
|
||||
const members = all.filter((part) => part.group === group.id);
|
||||
return `<section class="group" id="group-${esc(group.id)}">
|
||||
<h2>${esc(group.label)} <span class="muted small">${members.length} 件</span></h2>
|
||||
<div class="parts">${members.map(partCard).join("")}</div>
|
||||
</section>`;
|
||||
}).join("");
|
||||
|
||||
return `<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>二级减速器 · 有头创建工具(初学者)</title>
|
||||
<style>
|
||||
:root{--bg:#0f1419;--panel:#17212b;--panel2:#1b2733;--line:#2a3a45;--text:#dbe6ee;--muted:#93a6b3;--accent:#73c6d4;--ok:#7fc98b;--warn:#e0b15c;--bad:#e58a8a;color-scheme:dark}
|
||||
*{box-sizing:border-box}
|
||||
body{margin:0;background:var(--bg);color:var(--text);font:15px/1.65 system-ui,-apple-system,"Segoe UI","Noto Sans CJK SC","Microsoft YaHei",sans-serif;overflow-wrap:break-word}
|
||||
a{color:var(--accent);text-decoration:none}a:hover{text-decoration:underline}
|
||||
code,pre{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}
|
||||
code{background:#0b1117;border:1px solid var(--line);border-radius:4px;padding:.1em .35em;font-size:.9em}
|
||||
header.top{position:sticky;top:0;z-index:10;display:flex;gap:14px;align-items:center;padding:10px 18px;background:rgba(15,20,25,.94);border-bottom:1px solid var(--line);backdrop-filter:blur(6px)}
|
||||
header.top .brand{font-weight:650}
|
||||
header.top .spacer{flex:1}
|
||||
main{max-width:1180px;margin:0 auto;padding:18px}
|
||||
h1{font-size:22px;margin:6px 0}
|
||||
h2{font-size:17px;margin:26px 0 10px;border-bottom:1px solid var(--line);padding-bottom:6px}
|
||||
h3{font-size:15px;margin:0}
|
||||
.lead{color:#c6d6e2}
|
||||
.muted{color:var(--muted)}.small{font-size:12.5px}
|
||||
.card{background:var(--panel);border:1px solid var(--line);border-radius:10px;padding:14px 16px;margin:12px 0}
|
||||
.pill{background:var(--panel2);border:1px solid var(--line);border-radius:999px;padding:1px 9px;font-size:12px;color:var(--muted)}
|
||||
.parts{display:grid;grid-template-columns:repeat(auto-fill,minmax(330px,1fr));gap:12px}
|
||||
.part{background:var(--panel);border:1px solid var(--line);border-radius:10px;padding:12px 14px}
|
||||
.part .head{display:flex;gap:8px;align-items:center;justify-content:space-between}
|
||||
.part .meta{color:var(--muted);font-size:12.5px;margin:4px 0 8px}
|
||||
.steps{margin:6px 0 10px 18px;padding:0;font-size:13px}
|
||||
.steps li{margin:2px 0}
|
||||
.steps .zh{color:var(--muted);margin-left:6px;font-size:12.5px}
|
||||
pre.cmd{background:#0b1117;border:1px solid var(--line);border-radius:8px;padding:8px 10px;font-size:12px;overflow:auto;white-space:pre-wrap;word-break:break-all}
|
||||
.links{display:flex;gap:12px;flex-wrap:wrap;font-size:13px;margin-top:8px}
|
||||
table{border-collapse:collapse;width:100%;font-size:13.5px}
|
||||
th,td{border-bottom:1px solid var(--line);padding:6px 8px;text-align:left;vertical-align:top}
|
||||
th{color:var(--muted);font-weight:500}
|
||||
.note{border-left:3px solid var(--warn);padding:8px 12px;background:#1d1a12;border-radius:0 8px 8px 0;margin:10px 0}
|
||||
@media (max-width:700px){.parts{grid-template-columns:1fr}main{padding:12px}}
|
||||
@media print{header.top,.links,pre.cmd{display:none!important}}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<header class="top"><span class="brand">二级减速器 · 有头创建工具</span><span class="spacer"></span>
|
||||
<a href="index.html">教学中心</a><a href="console.html">教学控制台</a><a href="reducer-parts-manual.html">图文教案</a></header>
|
||||
<main>
|
||||
<h1>在真实界面里造一台二级减速器</h1>
|
||||
<p class="lead">${summary.parts} 个零件,${summary.steps} 个界面步骤,一步一步点出来;最后装配成整机。每一步都是真实浏览器里的操作,建完由界面算出的体积与构建记录逐件对照。</p>
|
||||
|
||||
<div class="card">
|
||||
<h2 style="margin-top:0">先做三件事</h2>
|
||||
<ol>
|
||||
<li>构建前端:<code>cd web && npx vite build</code>(改过 <code>web/src</code> 之后必做)。</li>
|
||||
<li>检查环境:<code>node tools/reducer/create-part.mjs P01 --dry</code> —— 只看前置,不启动浏览器。</li>
|
||||
<li>建第一个零件:下面任意一张卡片里的命令,或直接打开<a href="console.html">教学控制台</a>点「开始」。</li>
|
||||
</ol>
|
||||
<p class="small muted">有头运行需要图形环境(<code>DISPLAY=:1</code>)与 Chrome。所有证据落在 <code>docs/current/reducer-toolkit/runs/</code>,截图落在 <code>web/tools/reducer-parts-course/ui-stills/</code>。</p>
|
||||
</div>
|
||||
|
||||
<div class="note"><strong>判定怎么读:</strong>通过 = 每一步都点到、最终体积与记录一致;产品失败(exit 1)= 界面建出的体积不对;前置失败(exit 2)= dist/内核/Chrome/DISPLAY/步骤文件缺失,此时还没开始点,不算产品问题。</div>
|
||||
|
||||
${sections}
|
||||
|
||||
<section class="group" id="assembly">
|
||||
<h2>装配 <span class="muted small">1 台</span></h2>
|
||||
<article class="part">
|
||||
<div class="head"><h3>SecondaryReducer · 23 件合成整机</h3><span class="pill">插入链接</span></div>
|
||||
<div class="meta">新建装配文档,按构建记录的位置与旋转逐个插入并接地;插入数与期望比对。</div>
|
||||
<pre class="cmd">cd "${esc(REPO_ROOT)}" && DISPLAY=:1 node tools/reducer/create-assembly.mjs</pre>
|
||||
<div class="links"><a href="console.html">在教学控制台运行</a><a href="reducer-manual.html">初学者手册(设计原理)</a><a href="cases/reducer-course.html">视频课程</a></div>
|
||||
</article>
|
||||
</section>
|
||||
|
||||
<section class="group" id="tools">
|
||||
<h2>这套工具本身</h2>
|
||||
<table>
|
||||
<thead><tr><th>命令</th><th>作用</th></tr></thead>
|
||||
<tbody>
|
||||
<tr><td><code>node tools/reducer/list.mjs</code></td><td>列出 23 个零件、分组、步数与体积</td></tr>
|
||||
<tr><td><code>node tools/reducer/create-part.mjs P06</code></td><td>有头重建一个零件(P 编号或 Document 名都行)</td></tr>
|
||||
<tr><td><code>node tools/reducer/create-part.mjs P06 --dry</code></td><td>只做前置检查,不启动浏览器</td></tr>
|
||||
<tr><td><code>node tools/reducer/create-part.mjs P06 --slow</code></td><td>放慢点击,适合边看边学</td></tr>
|
||||
<tr><td><code>node tools/reducer/create-all.mjs --group bearings</code></td><td>按组串行重建</td></tr>
|
||||
<tr><td><code>node tools/reducer/create-all.mjs --all --keep-going</code></td><td>全部 23 件,出错继续</td></tr>
|
||||
<tr><td><code>node tools/reducer/create-assembly.mjs</code></td><td>真实界面装配</td></tr>
|
||||
<tr><td><code>node tools/reducer/self-test.mjs</code></td><td>无浏览器自测(目录、分组、参数校验、前置)</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p class="small muted">工具只做编排与前置检查;每一步的点击由共享引擎 <code>web/tools/cad-ui-rebuild/</code> 执行,构建记录来自 <code>web/teaching/cases/secondary-reducer-pro/out/replay/</code>,界面步骤来自 <code>web/tools/reducer-parts-course/out/ui-steps/</code>。</p>
|
||||
</section>
|
||||
|
||||
<section class="group" id="troubleshooting">
|
||||
<h2>常见问题</h2>
|
||||
<table>
|
||||
<thead><tr><th>现象</th><th>原因与处理</th></tr></thead>
|
||||
<tbody>
|
||||
<tr><td>退出码 2,日志里有「前置缺失」</td><td>dist、内核产物、Chrome、DISPLAY 或步骤文件缺失。照提示修,或用 <code>--dry</code> 看全部检查项。</td></tr>
|
||||
<tr><td>退出码 1,体积不一致</td><td>界面建出的几何与构建记录不同,是产品回归;报告里给出两边体积与相对误差。</td></tr>
|
||||
<tr><td>看不到浏览器窗口</td><td>有头需要可用的 X 显示;在带图形界面的会话里用 <code>DISPLAY=:1</code> 启动。</td></tr>
|
||||
<tr><td>页面打开是空白/旧版本</td><td>先 <code>cd web && npx vite build</code>,工具会自动为构建好的 dist 起临时服务。</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
|
||||
<p class="small muted" style="margin:26px 0 40px">本页由 <code>web/tools/teaching-console/build-reducer-page.mjs</code> 生成,请勿手改。</p>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
}
|
||||
|
||||
function main() {
|
||||
const argv = process.argv.slice(2);
|
||||
let check = false;
|
||||
let out = DEFAULT_OUT;
|
||||
for (let index = 0; index < argv.length; index += 1) {
|
||||
const arg = argv[index];
|
||||
if (arg === "--check") check = true;
|
||||
else if (arg === "--out") out = path.resolve(argv[++index] ?? DEFAULT_OUT);
|
||||
else if (arg === "--help" || arg === "-h") {
|
||||
console.log("node web/tools/teaching-console/build-reducer-page.mjs [--check] [--out <file>]");
|
||||
process.exit(0);
|
||||
} else {
|
||||
console.error(`未知参数:${arg}`);
|
||||
process.exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
const html = render();
|
||||
if (check) {
|
||||
let existing = "";
|
||||
try {
|
||||
existing = fs.readFileSync(out, "utf8");
|
||||
} catch {
|
||||
console.error(`FAIL --check:目标文件不存在 ${out}`);
|
||||
process.exit(1);
|
||||
}
|
||||
if (existing === html) {
|
||||
console.log("check: OK(reducer-toolkit.html 已是最新)");
|
||||
return;
|
||||
}
|
||||
let offset = 0;
|
||||
while (offset < existing.length && offset < html.length && existing[offset] === html[offset]) offset += 1;
|
||||
console.error(`FAIL --check:不一致(首个差异偏移 ${offset})`);
|
||||
process.exit(1);
|
||||
}
|
||||
fs.mkdirSync(path.dirname(out), { recursive: true });
|
||||
fs.writeFileSync(out, html);
|
||||
console.log(`written ${path.relative(REPO_ROOT, out)} (${(Buffer.byteLength(html) / 1024).toFixed(0)} KB)`);
|
||||
}
|
||||
|
||||
main();
|
||||
@@ -194,6 +194,23 @@ async function checkLive(browser) {
|
||||
await page.waitForFunction(() => /已取消/.test(document.getElementById("verdict").textContent), null, { timeout: 60000 });
|
||||
console.log("live: cancel ok");
|
||||
|
||||
// Reducer lesson: runs tools/reducer/create-part.mjs P06 headed and maps
|
||||
// the part report into the same verdict / results / evidence UI.
|
||||
await page.fill("#search", "P06");
|
||||
await page.click('#course-list button[data-id="lesson-reducer-p06"]');
|
||||
await page.click("#run");
|
||||
await page.waitForFunction(() => document.getElementById("terminal").textContent.includes("零件 P06"), null, { timeout: 120000 });
|
||||
await page.waitForFunction(() => /通过|失败|运行失败|超时/.test(document.getElementById("verdict").textContent), null, { timeout: 360000 });
|
||||
const reducer = await page.evaluate(() => ({
|
||||
verdict: document.getElementById("verdict").textContent,
|
||||
rows: document.querySelectorAll("#results tbody tr").length,
|
||||
evidence: document.querySelectorAll("#evidence a").length,
|
||||
}));
|
||||
if (!/通过/.test(reducer.verdict)) note(`live reducer: 判定为「${reducer.verdict}」`);
|
||||
if (reducer.rows < 1) note("live reducer: 结果表没有零件行");
|
||||
if (reducer.evidence < 1) note("live reducer: 没有证据链接");
|
||||
console.log(`live reducer: verdict=${reducer.verdict} rows=${reducer.rows} evidence=${reducer.evidence}`);
|
||||
|
||||
// Mobile layout on the same live server.
|
||||
await page.setViewportSize({ width: 390, height: 844 });
|
||||
await page.waitForTimeout(300);
|
||||
|
||||
97
web/tools/teaching-console/check-reducer-page.mjs
Normal file
97
web/tools/teaching-console/check-reducer-page.mjs
Normal file
@@ -0,0 +1,97 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* Browser gate for the beginner page web/teaching/reducer-toolkit.html.
|
||||
*
|
||||
* Opens the generated page over file:// (it must be self-contained and readable
|
||||
* with no server) and asserts: 23 part cards, every group section present,
|
||||
* copyable commands and links to the console / replay / parts manual, no
|
||||
* template leakage, no pageerror/console/request failures, and zero horizontal
|
||||
* overflow at 1440×900 and 390×844.
|
||||
*
|
||||
* Prerequisite: playwright resolvable from web/node_modules.
|
||||
* Exit: 0 pass / 1 page problem / 2 prerequisite missing.
|
||||
*
|
||||
* Usage: node web/tools/teaching-console/check-reducer-page.mjs
|
||||
*/
|
||||
import path from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { createRequire } from "node:module";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
||||
const REPO = path.resolve(HERE, "../../..");
|
||||
const require = createRequire(path.join(REPO, "web/package.json"));
|
||||
const PAGE = path.join(REPO, "web/teaching/reducer-toolkit.html");
|
||||
|
||||
const failures = [];
|
||||
const note = (message) => { failures.push(message); console.error(`FAIL ${message}`); };
|
||||
|
||||
let chromium;
|
||||
try {
|
||||
({ chromium } = require("playwright"));
|
||||
} catch {
|
||||
console.error("前置缺失:web/node_modules 下没有 playwright");
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
const VIEWPORTS = [{ width: 1440, height: 900 }, { width: 390, height: 844 }];
|
||||
|
||||
const browser = await chromium.launch({ headless: true, args: ["--no-sandbox", "--disable-dev-shm-usage"] });
|
||||
const page = await browser.newPage({ viewport: VIEWPORTS[0] });
|
||||
const pageErrors = [];
|
||||
const consoleErrors = [];
|
||||
const failedRequests = [];
|
||||
page.on("pageerror", (error) => pageErrors.push(String(error.message ?? error)));
|
||||
page.on("console", (message) => { if (message.type() === "error") consoleErrors.push(message.text()); });
|
||||
page.on("requestfailed", (request) => failedRequests.push(`${request.url()} ${request.failure()?.errorText ?? ""}`));
|
||||
|
||||
const response = await page.goto(pathToFileURL(PAGE).href, { waitUntil: "load" });
|
||||
if (!response) note("file:// 打开页面失败(无 response)");
|
||||
|
||||
const dom = await page.evaluate(() => {
|
||||
const text = document.body.innerText;
|
||||
const partIds = [...document.querySelectorAll("article.part[id]")].map((node) => node.id);
|
||||
const hrefs = [...document.querySelectorAll("a[href]")].map((node) => node.getAttribute("href"));
|
||||
const commands = [...document.querySelectorAll("code")].map((node) => node.textContent).join("\n");
|
||||
return {
|
||||
partIds,
|
||||
groups: document.querySelectorAll("section.group").length,
|
||||
hrefs,
|
||||
hasConsole: hrefs.some((href) => /console\.html/.test(href)),
|
||||
hasReplay: hrefs.some((href) => /reducer-replay\.html\?doc=/.test(href)),
|
||||
hasManual: hrefs.some((href) => /reducer-parts-manual\.html#P\d{2}/.test(href)),
|
||||
hasIndex: hrefs.some((href) => /(^|\/)index\.html$/.test(href)),
|
||||
command: /create-part\.mjs P\d{2}/.test(commands) && /create-assembly\.mjs/.test(commands),
|
||||
leakage: ["[object Object]", "undefined", "NaN", "${"].filter((token) => text.includes(token)),
|
||||
};
|
||||
});
|
||||
|
||||
const expectedIds = Array.from({ length: 23 }, (_, index) => `P${String(index + 1).padStart(2, "0")}`);
|
||||
const missing = expectedIds.filter((id) => !dom.partIds.includes(id));
|
||||
if (dom.partIds.length !== 23) note(`零件卡片 ${dom.partIds.length} 张,应为 23 张`);
|
||||
if (missing.length) note(`缺少零件卡片:${missing.join(", ")}`);
|
||||
if (dom.groups < 10) note(`分组区仅 ${dom.groups} 个,应至少 10 个(7 组 + 装配/工具/排错)`);
|
||||
if (!dom.hasConsole) note("没有跳转教学控制台的链接");
|
||||
if (!dom.hasReplay) note("没有跳转建模回放的链接");
|
||||
if (!dom.hasManual) note("没有跳转图文教案(reducer-parts-manual.html#P0x)的链接");
|
||||
if (!dom.hasIndex) note("没有返回 index.html 的链接");
|
||||
if (!dom.command) note("缺少可复制的 create-part / create-assembly 命令");
|
||||
for (const token of dom.leakage) note(`模板泄漏标记:${token}`);
|
||||
for (const error of pageErrors) note(`pageerror: ${error}`);
|
||||
for (const error of consoleErrors) note(`console: ${error}`);
|
||||
for (const error of failedRequests) note(`request: ${error}`);
|
||||
|
||||
for (const viewport of VIEWPORTS) {
|
||||
await page.setViewportSize(viewport);
|
||||
await page.waitForTimeout(120);
|
||||
const overflow = await page.evaluate(() => Math.max(0, document.documentElement.scrollWidth - window.innerWidth));
|
||||
if (overflow > 0) note(`${viewport.width}px: 横向溢出 ${overflow}px`);
|
||||
console.log(`${viewport.width}x${viewport.height}: overflow=${overflow}`);
|
||||
}
|
||||
|
||||
await browser.close();
|
||||
if (failures.length) {
|
||||
console.error(`\nreducer-toolkit.html 门禁失败:${failures.length} 项`);
|
||||
process.exit(1);
|
||||
}
|
||||
console.log(`\nreducer-toolkit.html 门禁通过:23 张零件卡片 / ${dom.groups} 个分组区 / 双视口 0 溢出`);
|
||||
@@ -8,8 +8,11 @@
|
||||
* against catalog.mjs and fails the build if one no longer exists.
|
||||
*/
|
||||
|
||||
import { groups as reducerGroups, parts as reducerParts } from "../../../tools/reducer/catalog.mjs";
|
||||
|
||||
export const GROUPS = [
|
||||
{ id: "basics", title: "准备:让环境可用", workbench: "系统", blurb: "先证明 dist、Chrome、显示和静态服务都就绪,再谈功能。" },
|
||||
{ id: "reducer", title: "二级减速器:逐件建模", workbench: "Reducer", blurb: "23 个零件各自一课,在真实界面里从头建出来;最后是装配课。" },
|
||||
{ id: "shell", title: "壳层与入口", workbench: "Shell", blurb: "COOP/COEP 隔离、工作台外壳、命令面板与偏好——所有功能的前提。" },
|
||||
{ id: "part", title: "Part:参数化零件", workbench: "Part", blurb: "图元、布尔、任务面板;最直观的建模入口。" },
|
||||
{ id: "partdesign", title: "PartDesign:实体特征", workbench: "PartDesign", blurb: "Body、草图、Pad 与边缘特征、Thickness。" },
|
||||
@@ -258,8 +261,54 @@ function crosscutLessons(catalog) {
|
||||
}));
|
||||
}
|
||||
|
||||
function volumeText(volume) {
|
||||
return volume == null ? "—" : `${Math.round(volume).toLocaleString("en-US")} mm³`;
|
||||
}
|
||||
|
||||
/** The 23-part reducer curriculum comes from the toolkit catalog, not a copy. */
|
||||
function reducerLessons() {
|
||||
const parts = reducerParts();
|
||||
const byGroup = new Map(reducerGroups().map((group) => [group.id, group.label]));
|
||||
const intro = [
|
||||
{
|
||||
id: "lesson-reducer-environment",
|
||||
groupId: "reducer",
|
||||
title: "减速器 · 环境自检(不启动浏览器)",
|
||||
level: "入门",
|
||||
durationMin: 1,
|
||||
summary: "23 个零件都有界面步骤与构建记录,但先要确认 dist、内核、Chrome、DISPLAY 就绪。本课用 dry run 只做前置检查。",
|
||||
sees: ["八项前置检查的真实结果", "提示缺失项可直接执行的修复命令"],
|
||||
expect: "前置全部满足;缺项时判定为「前置失败」,不启动浏览器。",
|
||||
job: { kind: "reducer-part", partId: parts[0]?.id ?? "P01", dry: true },
|
||||
},
|
||||
];
|
||||
const perPart = parts.map((part) => ({
|
||||
id: `lesson-reducer-${part.id.toLowerCase()}`,
|
||||
groupId: "reducer",
|
||||
title: `${part.id} · ${part.title}`,
|
||||
level: part.steps <= 2 ? "入门" : "进阶",
|
||||
durationMin: Math.max(2, part.steps + 2),
|
||||
summary: `在真实界面里重建 ${part.document}(${byGroup.get(part.group) ?? part.group}):共 ${part.steps} 步,完成后界面算出的体积应与构建记录 ${volumeText(part.volume)} 一致。`,
|
||||
sees: ["有头 Chrome 打开 PartDesign 页面并逐步点击", "每步一张截图,最终体积与记录对比"],
|
||||
expect: `create-part ${part.id} 判 pass(体积相对误差在引擎容差内)。`,
|
||||
job: { kind: "reducer-part", partId: part.id },
|
||||
}));
|
||||
const assembly = {
|
||||
id: "lesson-reducer-assembly",
|
||||
groupId: "reducer",
|
||||
title: "装配 · 23 件合成二级减速器",
|
||||
level: "进阶",
|
||||
durationMin: 15,
|
||||
summary: "新建装配文档,按构建记录的位置与旋转逐个插入链接并接地。装配的输入就是前面 23 节课建出来的零件数据。",
|
||||
sees: ["装配文档中出现全部零件链接", "插入数量与期望一致、无失配"],
|
||||
expect: "create-assembly 判 pass;失配或插入不全判产品失败。",
|
||||
job: { kind: "reducer-assembly" },
|
||||
};
|
||||
return [...intro, ...perPart, assembly];
|
||||
}
|
||||
|
||||
export function buildLessons(catalog) {
|
||||
const lessons = [...CORE_LESSONS, ...chapterLessons(catalog), ...moduleLessons(catalog), ...crosscutLessons(catalog)];
|
||||
const lessons = [...CORE_LESSONS, ...reducerLessons(), ...chapterLessons(catalog), ...moduleLessons(catalog), ...crosscutLessons(catalog)];
|
||||
const seen = new Set();
|
||||
for (const lesson of lessons) {
|
||||
if (seen.has(lesson.id)) throw new Error(`课程 id 重复:${lesson.id}`);
|
||||
|
||||
@@ -372,6 +372,7 @@ summary{cursor:pointer;font-size:13.5px}
|
||||
links.push('<a href="' + esc(base) + '/GAPS.md" target="_blank" rel="noopener">GAPS.md</a>');
|
||||
}
|
||||
if (job.kind === "probe") links.push('<a href="/api/console/artifacts/' + esc(job.jobId) + '/layout.json" target="_blank" rel="noopener">布局报告 JSON</a>');
|
||||
if (job.kind === "reducer-part" || job.kind === "reducer-assembly") links.push('<a href="/api/console/artifacts/' + esc(job.jobId) + '/report.json" target="_blank" rel="noopener">零件/装配报告 JSON</a>');
|
||||
if (job.origin) links.push('<span class="small muted">本次运行 origin:<code>' + esc(job.origin) + '</code></span>');
|
||||
$("evidence").innerHTML = links.length ? links.map(function(x){ return '<div>' + x + '</div>'; }).join("") : '<p class="muted small">运行结束后可打开完整报告与截图。</p>';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user