- 新数据链 web/teaching/cases/carrier-partdesign:20 件零件(spec.json 唯一来源)、 内核建造器 parts/*.mjs、traces/FCStd/replay 全量产物;装配 20 插入 + 19 关节。 - 工具包 tools/carrier:catalog / preflight / create-part / create-assembly / create-all / list / self-test / README,按零件与装配拆分为独立工具。 - 共享驱动扩展 web/tools/cad-ui-rebuild:Loft/Pipe/Hole/Fillet/Chamfer/Mirrored/ LinearPattern 交互,Reversed 复选框补齐;装配 saveAssemblyBundle 先 Accept 再保存。 - 教学:lessons.mjs 新增 carrier 组(环境课 + 20 件 + 装配),suite-runner 增加 carrier-part/carrier-assembly,生成 carrier-toolkit.html 并接入 index 与控制台证据。 验证:20 件 210 步全部有头通过(P05 修复后 39640 m³;P06 回归 8/8); 装配 20/20 插入、19/19 关节、20 组件 0 畸形、0 mismatch;check:carrier、 check:reducer、check-console --live 全绿。 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
91 lines
3.9 KiB
JavaScript
91 lines
3.9 KiB
JavaScript
#!/usr/bin/env node
|
||
// 航空母舰 PartDesign 建件入口。
|
||
//
|
||
// node web/teaching/cases/carrier-partdesign/build.mjs # 全部 20 件
|
||
// node web/teaching/cases/carrier-partdesign/build.mjs P02 # 单件(id 或 Document)
|
||
// node web/teaching/cases/carrier-partdesign/build.mjs Deck --dry # 只看摘要
|
||
// node web/teaching/cases/carrier-partdesign/build.mjs --subset # P01..P10 舰体部分
|
||
//
|
||
// Each document is written to out/FCStd/<Document>.FCStd (OPFS mirror first,
|
||
// then an evidence copy) and out/traces/<Document>.json. The replay stage reads
|
||
// only the trace, so a failed builder leaves a trace you can inspect instead of
|
||
// an empty out/replay entry.
|
||
import path from "node:path";
|
||
import fs from "node:fs";
|
||
import { fileURLToPath } from "node:url";
|
||
import { parts, partFor } from "./parts/index.mjs";
|
||
import { buildDocument, caseDir, outDir, useCaseOpfs } from "./lib/build.mjs";
|
||
|
||
const argv = process.argv.slice(2);
|
||
const flags = new Set(argv.filter(arg => arg.startsWith("--")));
|
||
const selectors = argv.filter(arg => !arg.startsWith("--"));
|
||
|
||
const SHIP = ["P01", "P02", "P03", "P04", "P05", "P06", "P07", "P08", "P09", "P10"];
|
||
|
||
function selected() {
|
||
if (selectors.length === 0) return flags.has("--subset") ? parts.filter(part => SHIP.includes(part.id)) : parts;
|
||
const found = selectors.map(key => {
|
||
const part = partFor(key) ?? parts.find(item => item.document.toLowerCase() === key.toLowerCase());
|
||
if (!part) {
|
||
console.error(`未知零件 ${key};可选:${parts.map(item => `${item.id} ${item.document}`).join(", ")}`);
|
||
process.exit(2);
|
||
}
|
||
return part;
|
||
});
|
||
return found;
|
||
}
|
||
|
||
function specIndex() {
|
||
const file = path.join(caseDir, "spec.json");
|
||
if (!fs.existsSync(file)) return new Map();
|
||
const spec = JSON.parse(fs.readFileSync(file, "utf8"));
|
||
return new Map(spec.parts.map(part => [part.document, part]));
|
||
}
|
||
|
||
async function main() {
|
||
useCaseOpfs();
|
||
const queue = selected();
|
||
const spec = specIndex();
|
||
const indexFile = path.join(outDir, "index.json");
|
||
const previous = fs.existsSync(indexFile) ? JSON.parse(fs.readFileSync(indexFile, "utf8")) : { documents: {} };
|
||
const results = [];
|
||
let failed = 0;
|
||
for (const part of queue) {
|
||
const entry = spec.get(part.document) ?? {};
|
||
process.stdout.write(`▶ ${part.id} ${part.document} ${entry.title ?? ""}\n`);
|
||
try {
|
||
const summary = await buildDocument(part, { dry: flags.has("--dry") });
|
||
const volume = Number(summary.volume);
|
||
console.log(
|
||
` ✓ ${summary.steps} 步 · ${summary.seconds}s · 体积 ${Number.isFinite(volume) ? `${volume.toFixed(3)} m³` : "n/a"} · ${summary.fcstd}`,
|
||
);
|
||
results.push({ id: part.id, title: entry.title ?? null, system: entry.system ?? null, ...summary });
|
||
previous.documents[part.document] = {
|
||
id: part.id, title: entry.title ?? null, system: entry.system ?? null,
|
||
steps: summary.steps, volume: summary.volume, bounds: summary.bounds,
|
||
seconds: summary.seconds, fcstd: summary.fcstd, builtAt: new Date().toISOString(),
|
||
};
|
||
} catch (error) {
|
||
failed += 1;
|
||
console.error(` ✗ ${part.document}: ${error?.message ?? error}`);
|
||
if (!flags.has("--dry")) console.error(error?.stack ?? "");
|
||
}
|
||
}
|
||
fs.mkdirSync(outDir, { recursive: true });
|
||
fs.writeFileSync(indexFile, `${JSON.stringify({
|
||
schema: "freecad-web-carrier-partdesign-index/v1",
|
||
generatedAt: new Date().toISOString(),
|
||
documents: previous.documents,
|
||
}, null, 2)}\n`);
|
||
const built = results.length;
|
||
console.log(`\n${built}/${queue.length} 件完成${failed ? `,${failed} 件失败` : ""};索引 ${path.relative(caseDir, indexFile)}`);
|
||
if (flags.has("--dry")) console.log(JSON.stringify(results.map(item => ({ id: item.id, volume: item.volume, steps: item.steps }))));
|
||
process.exit(failed ? 1 : 0);
|
||
}
|
||
|
||
main().catch(error => {
|
||
console.error(error?.stack ?? error);
|
||
process.exit(1);
|
||
});
|
||
void fileURLToPath;
|