28 lines
1.8 KiB
JavaScript
28 lines
1.8 KiB
JavaScript
import { spawnSync } from 'node:child_process'
|
|
import { mkdir, writeFile } from 'node:fs/promises'
|
|
import { resolve } from 'node:path'
|
|
|
|
const root = resolve(new URL('..', import.meta.url).pathname)
|
|
const command = process.env.FREECAD_CMD || resolve(root, '.cache/freecad/install-desktop/bin/FreeCADCmd')
|
|
const sysroot = resolve(root, '.cache/freecad/sysroot')
|
|
const script = resolve(root, 'scripts/freecad-partdesign-revolution-groove-oracle.py')
|
|
const outputFile = resolve(root, 'config/freecad-partdesign-revolution-groove-oracle.json')
|
|
const execution = spawnSync(command, ['--python-path', resolve(sysroot, 'usr/lib/python3/dist-packages'), script], {
|
|
cwd: root, encoding: 'utf8', timeout: 120000, maxBuffer: 4 * 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_PARTDESIGN_REVOLUTION_GROOVE_ORACLE_RESULT='
|
|
const line = output.split(/\r?\n/).find((entry) => entry.includes(marker))
|
|
if (execution.error || execution.status !== 0 || !line) throw new Error(`FreeCAD PartDesign Revolution/Groove oracle failed: ${execution.error?.message || output.trim()}`)
|
|
const report = JSON.parse(line.slice(line.indexOf(marker) + marker.length))
|
|
await mkdir(resolve(root, 'config'), { recursive: true })
|
|
await writeFile(outputFile, `${JSON.stringify(report, null, 2)}\n`)
|
|
console.log(JSON.stringify({ status: 'freecad-partdesign-revolution-groove-oracle-generated', output: outputFile, summary: report.summary }, null, 2))
|