#!/usr/bin/env node // Builds course.json from line-spec.json and the fixed 18-episode mapping, so // object lists always match the reference spec. import fs from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; const here = path.dirname(fileURLToPath(import.meta.url)); const spec = JSON.parse(fs.readFileSync(path.join(here, "line-spec.json"), "utf8")); const byName = new Map(spec.models.map(model => [model.name, model])); const episodes = [ ["E01", "S0", "ui-and-reference", "界面与产线参考模型", [], ["ui", "reference-glb", "tree", "navigation", "opfs"], [180, 480]], ["E02", "S0", "measure-and-spec", "测量、单位与零件表", [], ["measure", "bbox", "units", "spreadsheet"], [180, 480]], ["E03", "S1", "cabinet-a", "主控制柜", ["CabinetA"], ["box", "compound", "placement", "color", "save"], [300, 900]], ["E04", "S1", "cabinet-b", "长控制柜", ["CabinetB"], ["box", "compound", "placement", "color", "save"], [300, 900]], ["E05", "S1", "doors-and-displays", "柜门与双显示屏", ["CabinetDoor", "DisplayA", "DisplayB"], ["box", "placement", "color", "save"], [240, 780]], ["E06", "S2", "hopper-and-raw-feeder", "料仓与原料上料", ["Hopper", "RawFeeder"], ["cylinder", "box", "compound", "color", "save"], [300, 900]], ["E07", "S2", "loader-and-conveyor", "上料与传送带送料", ["Loader", "ConveyorFeeder"], ["box", "compound", "placement", "color", "save"], [300, 900]], ["E08", "S2", "rotary-and-weigh", "旋转运送与称重平台", ["RotaryTransfer", "WeighPlatform"], ["cylinder", "box", "placement", "color", "save"], [240, 780]], ["E09", "S3", "pick-feeder-and-gripper", "夹取送料与辅助夹爪", ["PickFeeder", "AuxGripper"], ["box", "compound", "placement", "color", "save"], [300, 900]], ["E10", "S3", "pusher-and-store", "推料装置与物料存储区", ["Pusher", "MaterialStore"], ["box", "compound", "array", "color", "save"], [300, 900]], ["E11", "S3", "sensor-bracket-inspector", "检测块、支架与运送检测", ["SensorBlock", "TransportBracket", "TransportInspector"], ["box", "placement", "color", "save"], [240, 780]], ["E12", "S4", "assembly-and-inspection", "原料装配与检测台", ["RawAssembly", "InspectionTable"], ["box", "compound", "placement", "color", "save"], [240, 780]], ["E13", "S4", "lights-and-origin", "三色灯、工具坐标系与原点", ["StackLight", "ToolFrame", "OriginMarker"], ["cylinder", "box", "color", "save"], [240, 780]], ["E14", "S5", "abb-robot", "ABB IRB 120 六轴机器人", ["ABB_IRB_120"], ["box", "cylinder", "compound", "placement", "color", "save"], [360, 1080]], ["E15", "S5", "robot-station-review", "机器人工作站复核", [], ["review", "bbox", "color", "save"], [180, 600]], ["E16", "S6", "ground-and-lines", "地面平面与地线", ["GroundPlane", "Plane", "Plane001"], ["box", "placement", "color", "save"], [240, 780]], ["E17", "S6", "line-assembly", "整线总装", [], ["assembly", "insert-link", "joint", "solve", "save"], [300, 900]], ["E18", "S6", "audit-and-delivery", "精度审计与交付", [], ["audit", "export", "stl", "evidence"], [300, 900]], ]; let cumulative = []; const result = []; for (const [id, season, slug, title, modelNames, features, durationRange] of episodes) { const models = modelNames.map(name => { const model = byName.get(name); if (!model) throw new Error(`line-spec has no model ${name} for ${id}`); return model; }); const objects = models.flatMap(model => model.parts.map(part => part.partName)); cumulative = [...new Set([...cumulative, ...objects])]; const index = episodes.findIndex(entry => entry[0] === id); const previous = index > 0 ? episodes[index - 1][0] : null; // E17 is an assembly demonstration and has no persisted document; E18 audits // and saves from the E16 checkpoint. const checkpointIn = id === "E01" || id === "E02" || id === "E03" ? null : id === "E17" || id === "E18" ? "E16" : previous; const checkpointOut = id === "E01" || id === "E02" || id === "E17" ? null : id; result.push({ id, season, slug, title, page: id === "E17" ? "assembly" : "project", workbench: id === "E17" ? "Assembly" : "Part", checkpointIn, checkpointOut, expectedObjects: ["E01", "E02", "E17"].includes(id) ? null : objects.length, objects, checkpointObjects: cumulative.slice(), models: models.map(model => ({ name: model.name, file: model.file, label: model.label, parts: model.parts.map(part => part.partName), })), features, durationRange, }); } const course = { schema: "freecad-web-line-course/course/v1", title: "生产线 27 件 GLB 模型 Web FreeCAD 初学者视频课程", voice: "zh-CN-XiaoxiaoNeural", rate: "-4%", appOrigin: "http://127.0.0.1:5181", teachingOrigin: "http://127.0.0.1:5190", seasons: [ { id: "S0", title: "入门与参考模型", episodes: ["E01", "E02"] }, { id: "S1", title: "机柜与显示屏", episodes: ["E03", "E04", "E05"] }, { id: "S2", title: "上料与输送", episodes: ["E06", "E07", "E08"] }, { id: "S3", title: "抓取、推料与存储", episodes: ["E09", "E10", "E11"] }, { id: "S4", title: "装配与检测", episodes: ["E12", "E13"] }, { id: "S5", title: "机器人工作站", episodes: ["E14", "E15"] }, { id: "S6", title: "场景、总装与交付", episodes: ["E16", "E17", "E18"] }, ], episodes: result, }; fs.writeFileSync(path.join(here, "course.json"), `${JSON.stringify(course, null, 2)}\n`); console.log(JSON.stringify({ ok: true, episodes: result.length, totalObjects: result.at(-1).checkpointObjects.length, objectsByEpisode: Object.fromEntries(result.map(episode => [episode.id, episode.objects.length])) }));