- 新数据链 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>
151 lines
5.9 KiB
JavaScript
151 lines
5.9 KiB
JavaScript
#!/usr/bin/env node
|
||
/**
|
||
* Purpose: 按系统分组或零件列表串行重建航空母舰的多个零件。
|
||
*
|
||
* 每个零件仍是一次独立运行:逐件调用 tools/carrier/create-part.mjs,
|
||
* 判定、报告格式与退出码完全一致,这里只做编排与汇总。
|
||
* 默认遇错即停;--keep-going 继续并在末尾给出汇总。
|
||
*
|
||
* Usage:
|
||
* node tools/carrier/create-all.mjs --group flight-deck --dry
|
||
* node tools/carrier/create-all.mjs --parts P02,P03
|
||
* node tools/carrier/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/carrier/create-part.mjs");
|
||
|
||
function usage() {
|
||
console.log("node tools/carrier/create-all.mjs [--parts P01,P02 | --group <id> | --all] [--keep-going] [--dry] [--slow] [--headless] [--out <dir>]");
|
||
}
|
||
|
||
function parseArgs(argv) {
|
||
const options = { keys: [], group: null, all: false, keepGoing: false, dry: false, slow: false, headed: true, out: null };
|
||
for (let index = 0; index < argv.length; index += 1) {
|
||
const arg = argv[index];
|
||
if (arg === "--parts") options.keys = 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 === "--headed") options.headed = true;
|
||
else if (arg === "--headless") options.headed = false;
|
||
else if (arg === "--out") options.out = path.resolve(argv[++index] ?? "");
|
||
else if (arg === "--help" || arg === "-h") {
|
||
usage();
|
||
process.exit(0);
|
||
} else {
|
||
console.error(`未知参数:${arg}`);
|
||
process.exit(2);
|
||
}
|
||
}
|
||
if (!options.keys.length && !options.group && !options.all) {
|
||
usage();
|
||
console.error("必须给出 --parts / --group / --all(分组见 node tools/carrier/list.mjs)");
|
||
process.exit(2);
|
||
}
|
||
return options;
|
||
}
|
||
|
||
function selection(options) {
|
||
if (options.keys.length) return options.keys.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));
|
||
}
|
||
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.headed) argv.push("--headless");
|
||
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));
|
||
});
|
||
}
|
||
|
||
function readReport(dir, part) {
|
||
try {
|
||
return JSON.parse(fs.readFileSync(path.join(dir, part.id, "report.json"), "utf8"));
|
||
} catch {
|
||
return null;
|
||
}
|
||
}
|
||
|
||
async function main() {
|
||
const options = parseArgs(process.argv.slice(2));
|
||
const selected = selection(options);
|
||
const stamp = new Date().toISOString().replace(/[:.]/g, "-");
|
||
const summary = {
|
||
schema: "freecad-web/carrier-toolkit/batch/v1",
|
||
startedAt: new Date().toISOString(),
|
||
items: [],
|
||
};
|
||
|
||
for (const part of selected) {
|
||
console.log(`\n=== ${part.id} ${part.document}(${part.title},${part.steps} 步,体积 ${part.volume ?? "—"})===`);
|
||
const code = await runPart(part, options);
|
||
const item = { id: part.id, document: part.document, title: part.title, system: part.system, exitCode: code };
|
||
if (!options.dry) {
|
||
const report = readReport(options.out ?? "", part);
|
||
if (report) {
|
||
item.verdict = report.verdict;
|
||
item.steps = report.steps;
|
||
item.stepsTotal = report.stepsTotal;
|
||
item.volume = report.volume;
|
||
item.expectedVolume = report.expectedVolume;
|
||
item.relativeError = report.relativeError;
|
||
item.seconds = report.seconds;
|
||
}
|
||
}
|
||
summary.items.push(item);
|
||
|
||
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;
|
||
summary.seconds = Math.round((Date.parse(summary.finishedAt) - Date.parse(summary.startedAt)) / 1000);
|
||
|
||
const dir = options.out ?? path.join(REPO_ROOT, "docs/current/carrier-partdesign-toolkit/runs", `${stamp}-batch`);
|
||
fs.mkdirSync(dir, { recursive: true });
|
||
fs.writeFileSync(path.join(dir, "summary.json"), `${JSON.stringify(summary, null, 2)}\n`);
|
||
|
||
console.log(`\n合计:通过 ${summary.passed} / 失败 ${summary.failed} / 前置 ${summary.blocked} / 未执行 ${summary.skipped}(${summary.seconds}s)`);
|
||
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);
|
||
});
|