61 lines
3.4 KiB
JavaScript
61 lines
3.4 KiB
JavaScript
#!/usr/bin/env node
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { createRequire } from "node:module";
|
|
import { pathToFileURL } from "node:url";
|
|
|
|
const root = "/home/mes123456/FreeCADWasmDev/working/FreeCAD";
|
|
const build = path.join(root, "freecad-source/build-web/configure/bin");
|
|
const mode = process.argv[2] ?? "load";
|
|
const sketcherMode = mode === "sketcher-next";
|
|
const probeName = sketcherMode ? "FreeCADWebSketcherProbe" : "FreeCADWebPartBoxProbe";
|
|
const loaderPath = path.join(build, `${probeName}.js`);
|
|
const wasmPath = path.join(build, `${probeName}.wasm`);
|
|
|
|
globalThis.__dirname = `${build}${path.sep}`;
|
|
globalThis.require = createRequire(import.meta.url);
|
|
const loader = await import(pathToFileURL(loaderPath));
|
|
const kernel = await loader.default({
|
|
wasmBinary: fs.readFileSync(wasmPath),
|
|
locateFile: file => file.endsWith(".worker.js")
|
|
? path.join(build, `${probeName}.worker.cjs`)
|
|
: path.join(build, file),
|
|
print: () => {},
|
|
printErr: () => {},
|
|
});
|
|
|
|
const rows = {
|
|
mirroring: [{ apiId: "obj:Part:Part::Mirroring", name: "Part::Mirroring", family: "generic-document-object", sourcePath: "src/Mod/Part/App/FeatureMirroring.h", disposition: "planned" }],
|
|
offsets: ["Part::Offset", "Part::Offset2D"].map(name => ({ apiId: `obj:Part:${name}`, name, family: "generic-document-object", sourcePath: "src/Mod/Part/App/FeatureOffset.h", disposition: "planned" })),
|
|
common: ["Part::Common", "Part::MultiCommon"].map(name => ({ apiId: `obj:Part:${name}`, name, family: "generic-document-object", sourcePath: "src/Mod/Part/App/FeaturePartCommon.h", disposition: "planned" })),
|
|
batch: [{ apiId: "obj:Part:Part::Feature", name: "Part::Feature", family: "generic-document-object", sourcePath: "src/Mod/Part/App/PartFeature.h", disposition: "planned" }],
|
|
};
|
|
|
|
if (mode === "load") {
|
|
console.log(JSON.stringify({ loaded: true, probe: path.basename(loaderPath) }));
|
|
process.exit(0);
|
|
}
|
|
if (sketcherMode) {
|
|
const records = [
|
|
["Sketcher::PropertyConstraintList", "PropertyConstraintList.cpp", 48],
|
|
["Sketcher::Sketch", "Sketch.cpp", 67],
|
|
["Sketcher::SketchGeometryExtension", "SketchGeometryExtension.cpp", 37],
|
|
["Sketcher::SketchObject", "SketchObject.h", 85],
|
|
["Sketcher::SketchObjectSF", "SketchObjectSF.h", 37],
|
|
["Sketcher::SolverGeometryExtension", "SolverGeometryExtension.cpp", 35],
|
|
].map(([name, file]) => ({ apiId: `obj:Sketcher:${name}`, name, family: "geometry-recompute", sourcePath: `src/Mod/Sketcher/App/${file}`, disposition: "planned" }));
|
|
const request = { cmd: "sketcher.pythonFamilyBatch", args: { tier: "object-contract", records } };
|
|
const result = JSON.parse(String(kernel.ccall("fc_web_dispatch_json", "string", ["string"], [JSON.stringify(request)])));
|
|
console.log(JSON.stringify(result));
|
|
process.exit(result.ok === true ? 0 : 1);
|
|
}
|
|
const records = rows[mode];
|
|
if (!records) throw new Error(`unknown replay mode: ${mode}`);
|
|
const request = { cmd: "part.pythonFamilyBatch", args: { tier: "object-contract", records } };
|
|
const result = JSON.parse(String(kernel.ccall("fc_web_dispatch_json", "string", ["string"], [JSON.stringify(request)])));
|
|
if (result.ok !== true || result.count !== records.length || result.resourcesReleased !== true) {
|
|
throw new Error(JSON.stringify(result));
|
|
}
|
|
console.log(JSON.stringify({ mode, count: result.count, statuses: result.records.map(record => record.status), resourcesReleased: result.resourcesReleased }));
|
|
process.exit(0);
|