Tweak runCQ

This commit is contained in:
Kurt Hutten
2021-10-09 05:50:52 +11:00
parent 0a13b7aea7
commit 7260e5b94e

View File

@@ -1,5 +1,6 @@
import { writeFiles, runCommand } from '../common/utils' import { writeFiles, runCommand } from '../common/utils'
import { nanoid } from 'nanoid' import { nanoid } from 'nanoid'
import { readFile } from 'fs/promises'
export const runCQ = async ({ export const runCQ = async ({
file, file,
@@ -11,34 +12,35 @@ export const runCQ = async ({
) )
const fullPath = `/tmp/${tempFile}/output.gz` const fullPath = `/tmp/${tempFile}/output.gz`
const stlPath = `/tmp/${tempFile}/output.stl` const stlPath = `/tmp/${tempFile}/output.stl`
const customizerPath = `/tmp/${tempFile}/customizer.param` // const customizerPath = `/tmp/${tempFile}/customizer.param`
const command = [ const command = [
`cq-cli/cq-cli`, `cq-cli/cq-cli`,
`--codec stl`, `--codec stl`,
`--infile /tmp/${tempFile}/main.py`, `--infile /tmp/${tempFile}/main.py`,
`--outfile ${stlPath}`, `--outfile ${stlPath}`,
`--outputopts "deflection:${deflection};angularDeflection:${deflection};"`, `--outputopts "deflection:${deflection};angularDeflection:${deflection};"`,
`--params ${customizerPath}`, // `--params ${customizerPath}`,
].join(' ') ].join(' ')
const command2 = [ // const command2 = [
`cq-cli/cq-cli`, // `cq-cli/cq-cli`,
`--getparams true`, // `--getparams true`,
`--infile /tmp/${tempFile}/main.py`, // `--infile /tmp/${tempFile}/main.py`,
`--outfile ${customizerPath}`, // `--outfile ${customizerPath}`,
] // ]
console.log('command', command) console.log('command', command)
let consoleMessage = '' let consoleMessage = ''
try { try {
consoleMessage = await runCommand(command, 30000) consoleMessage = await runCommand(command, 30000)
consoleMessage2 = await runCommand(command2, 30000) // const consoleMessage2 = await runCommand(command2, 30000)
const params = JSON.parse( // const params = JSON.parse(
await readFile(customizerPath, { encoding: 'ascii'}) // await readFile(customizerPath, { encoding: 'ascii'})
).parameters // )
// console.log('params', params)
await writeFiles( await writeFiles(
[ [
{ {
file: JSON.stringify({ file: JSON.stringify({
customizerParams: params, // customizerParams: params,
consoleMessage, consoleMessage,
type: 'stl', type: 'stl',
}), }),