Skip to content

Commit

Permalink
fix(bindgen): Support no positional inputs, no positional outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
thewtex committed Mar 3, 2023
1 parent ccc31e0 commit 90de509
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/bindgen/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ function typescriptBindings(outputDir, buildDir, wasmBinaries, options, forNode=
functionContent += ` ${interfaceType},\n`
})
functionContent += ` InterfaceTypes,\n`
functionContent += ` PipelineOutput,\n`
functionContent += ` PipelineInput,\n`
if (forNode) {
functionContent += ` runPipelineNode\n`
Expand Down Expand Up @@ -376,15 +377,15 @@ function typescriptBindings(outputDir, buildDir, wasmBinaries, options, forNode=
functionContent += functionCall
functionContent += ' {\n\n'

functionContent += ` const desiredOutputs = [\n`
functionContent += ` const desiredOutputs: Array<PipelineOutput> = [\n`
interfaceJson.outputs.forEach((output) => {
if (interfaceJsonTypeToInterfaceType.has(output.type)) {
const interfaceType = interfaceJsonTypeToInterfaceType.get(output.type)
functionContent += ` { type: InterfaceTypes.${interfaceType} },\n`
}
})
functionContent += ` ]\n`
functionContent += ` const inputs: [ PipelineInput ] = [\n`
functionContent += ` const inputs: Array<PipelineInput> = [\n`
interfaceJson.inputs.forEach((input, index) => {
if (interfaceJsonTypeToInterfaceType.has(input.type)) {
const interfaceType = interfaceJsonTypeToInterfaceType.get(input.type)
Expand Down Expand Up @@ -456,7 +457,7 @@ function typescriptBindings(outputDir, buildDir, wasmBinaries, options, forNode=
} else {
// Image, Mesh, PolyData, JsonObject
functionContent += ` const inputCountString = inputs.length.toString()\n`
functionContent += ` inputs.push({ type: InterfaceTypes.${interfaceType}, data: options.${camel} })\n`
functionContent += ` inputs.push({ type: InterfaceTypes.${interfaceType}, data: options.${camel} as ${interfaceType}})\n`
functionContent += ` args.push('--${parameter.name}', inputCountString)\n`
}
} else {
Expand All @@ -466,12 +467,13 @@ function typescriptBindings(outputDir, buildDir, wasmBinaries, options, forNode=
functionContent += ` }\n`
})

const outputsVar = interfaceJson.outputs.length ? ' outputs\n' : ''
if (forNode) {
functionContent += `\n const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', '${moduleKebabCase}')\n\n`
functionContent += ` const {\n returnValue,\n stderr,\n outputs\n } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs)\n`
functionContent += ` const {\n returnValue,\n stderr,\n${outputsVar} } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs)\n`
} else {
functionContent += `\n const pipelinePath = '${moduleKebabCase}'\n\n`
functionContent += ` const {\n webWorker: usedWebWorker,\n returnValue,\n stderr,\n outputs\n } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() })\n`
functionContent += ` const {\n webWorker: usedWebWorker,\n returnValue,\n stderr,\n${outputsVar} } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() })\n`
}

functionContent += ' if (returnValue !== 0) {\n throw new Error(stderr)\n }\n\n'
Expand Down

0 comments on commit 90de509

Please sign in to comment.