Files
Web_FreeCAD_Bitbybit/scripts/run-freecad-sketcher-editor-oracle.mjs

31 lines
1.8 KiB
JavaScript

import { existsSync } from 'node:fs'
import { writeFile } from 'node:fs/promises'
import { resolve } from 'node:path'
import { spawnSync } from 'node:child_process'
const root = resolve(new URL('..', import.meta.url).pathname)
const executable = process.env.FREECAD_CMD || resolve(root, '.cache/freecad/install-desktop/bin/FreeCADCmd')
if (!existsSync(executable)) throw new Error(`FreeCAD Sketcher editor oracle executable is missing: ${executable}`)
const sysroot = resolve(root, '.cache/freecad/sysroot')
const execution = spawnSync(executable, ['--python-path', resolve(sysroot, 'usr/lib/python3/dist-packages'), resolve(root, 'scripts/freecad-sketcher-editor-oracle.py')], {
cwd: root,
encoding: 'utf8',
timeout: 120_000,
maxBuffer: 20 * 1024 * 1024,
env: {
...process.env,
PYTHONPATH: `${resolve(sysroot, 'usr/lib/python3/dist-packages')}${process.env.PYTHONPATH ? `:${process.env.PYTHONPATH}` : ''}`,
LD_LIBRARY_PATH: `${resolve(sysroot, 'usr/lib/x86_64-linux-gnu')}${process.env.LD_LIBRARY_PATH ? `:${process.env.LD_LIBRARY_PATH}` : ''}`,
MATPLOTLIBRC: resolve(sysroot, 'usr/share/matplotlib/mpl-data/matplotlibrc'),
MPLBACKEND: 'Agg',
},
})
const output = `${execution.stdout || ''}\n${execution.stderr || ''}`
const marker = 'FREECAD_SKETCHER_EDITOR_ORACLE_RESULT='
const resultLine = output.split(/\r?\n/).find((line) => line.startsWith(marker))
if (execution.error || execution.status !== 0 || !resultLine) throw new Error(`FreeCAD Sketcher editor oracle failed with status ${execution.status}: ${execution.error?.message || output.trim()}`)
const report = JSON.parse(resultLine.slice(marker.length))
await writeFile(resolve(root, 'config/freecad-sketcher-editor-oracle.json'), `${JSON.stringify(report, null, 2)}\n`)
console.log(JSON.stringify(report, null, 2))
if (report.status !== 'pass') process.exitCode = 1