Skip to content

Commit

Permalink
feat(bindgen): Add output-options-check.js
Browse files Browse the repository at this point in the history
  • Loading branch information
thewtex committed Aug 2, 2023
1 parent f6f988f commit d7832d4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/bindgen/output-options-check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function outputOptionsCheck(interfaceJson) {
interfaceJson.parameters.forEach((parameter) => {
if (parameter.type.includes('OUTPUT')) {
console.error(`OUTPUT options are not supported`)
console.error(`Violating option: ${parameter.name}`)
process.exit(1)
}
})
}

export default outputOptionsCheck
4 changes: 3 additions & 1 deletion src/bindgen/typescript/typescript-bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import writeSupportFiles from './write-support-files.js'
import resultsModule from './results-module.js'
import optionsModule from './options-module.js'
import functionModule from './function-module.js'
import outputOptionsCheck from '../output-options-check.js'

// Array of types that will require an import from itk-wasm
function bindgenResource(filePath) {
Expand Down Expand Up @@ -92,6 +93,8 @@ function typescriptBindings (outputDir, buildDir, wasmBinaries, options, forNode

const { interfaceJson, parsedPath } = wasmBinaryInterfaceJson(outputDir, buildDir, wasmBinaryName)

outputOptionsCheck(interfaceJson)

const moduleKebabCase = parsedPath.name
const moduleCamelCase = camelCase(parsedPath.name)
const modulePascalCase = `${moduleCamelCase[0].toUpperCase()}${moduleCamelCase.substring(1)}`
Expand All @@ -117,7 +120,6 @@ function typescriptBindings (outputDir, buildDir, wasmBinaries, options, forNode
indexContent += `export type { ${modulePascalCase}${nodeTextCamel}Result }\n\n`

const filteredParameters = interfaceJson.parameters.filter(p => { return p.name !== 'memory-io' && p.name !== 'version'})
console.log(interfaceJson.outputs)
const haveOutputFile = interfaceJson.outputs.some(o => { return o.type.includes('FILE') })
const haveOptions = !!filteredParameters.length || haveOutputFile

Expand Down

0 comments on commit d7832d4

Please sign in to comment.