Add CadQuery customizer #547

Merged
jmwright merged 15 commits from main into main 2021-10-14 17:39:04 +02:00
4 changed files with 39 additions and 25 deletions
Showing only changes of commit 624868b0e8 - Show all commits

View File

@@ -42,7 +42,7 @@ RUN npm install aws-lambda-ric@1.0.0
RUN wget \
https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh \
&& bash Miniconda3-latest-Linux-x86_64.sh -b \
&& rm -f Miniconda3-latest-Linux-x86_64.sh
&& rm -f Miniconda3-latest-Linux-x86_64.sh
RUN conda --version
# Install CadQuery

View File

@@ -12,7 +12,7 @@ export const runCQ = async ({
{
file: JSON.stringify(parameters),
fileName: 'params.json',
}
},
],
'a' + nanoid() // 'a' ensure nothing funny happens if it start with a bad character like "-", maybe I should pick a safer id generator :shrug:
)
@@ -36,12 +36,12 @@ export const runCQ = async ({
console.log('command', mainCommand)
let consoleMessage = ''
try {
;([consoleMessage] = await Promise.all([
;[consoleMessage] = await Promise.all([
runCommand(mainCommand, 30000),
runCommand(customizerCommand, 30000)
]))
runCommand(customizerCommand, 30000),
])
const params = JSON.parse(
await readFile(customizerPath, { encoding: 'ascii'})
await readFile(customizerPath, { encoding: 'ascii' })
)
await writeFiles(
[
@@ -63,6 +63,6 @@ export const runCQ = async ({
)
return { consoleMessage, fullPath }
} catch (error) {
return { error: consoleMessage, fullPath }
return { error: consoleMessage || error, fullPath }
}
}

View File

@@ -51,7 +51,7 @@ export const render: DefaultKernelExport['render'] = async ({
data: await stlToGeometry(window.URL.createObjectURL(blob)),
consoleMessage,
date: new Date(),
customizerParams: CadQueryToCadhubParams([customizerParams]), // TODO, should already be an array and not need to be wrapped in one.
customizerParams: CadQueryToCadhubParams(customizerParams),
})
} catch (e) {
return createUnhealthyResponse(new Date())

View File

@@ -2,8 +2,8 @@ import { CadhubParams } from 'src/components/Customizer/customizerConverter'
interface CadQueryParamsBase {
name: string
initial: number | string
type?: 'number'
initial: number | string | boolean
type?: 'number' | 'string' | 'boolean'
}
interface CadQueryNumberParam extends CadQueryParamsBase {
@@ -12,13 +12,19 @@ interface CadQueryNumberParam extends CadQueryParamsBase {
}
interface CadQueryStringParam extends CadQueryParamsBase {
type: 'string'
initial: string
}
interface CadQueryBooleanParam extends CadQueryParamsBase {
type: 'boolean'
initial: boolean
}
export type CadQueryStringParams =
| CadQueryNumberParam
| CadQueryStringParam
| CadQueryBooleanParam
export function CadQueryToCadhubParams(
input: CadQueryStringParams[]
@@ -29,21 +35,29 @@ export function CadQueryToCadhubParams(
caption: '',
name: param.name,
}
if(param.type === 'number') {
return {
type: 'number',
input: 'default-number',
...common,
initial: Number(param.initial),
}
}
return {
type: 'string',
input: 'default-string',
...common,
initial: String(param.initial),
switch (param.type) {
case 'number':
return {
type: 'number',
input: 'default-number',
...common,
initial: param.initial,
}
case 'string':
return {
type: 'string',
input: 'default-string',
...common,
initial: param.initial,
}
case 'boolean':
return {
type: 'boolean',
input: 'default-boolean',
...common,
initial: param.initial,
}
}
})
.filter((a) => a)
}