Skip to content

Commit

Permalink
feat(bindgen): export used interface types
Browse files Browse the repository at this point in the history
Closes #920
  • Loading branch information
thewtex committed Sep 6, 2023
1 parent a0009d0 commit 3d15608
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 4 deletions.
5 changes: 4 additions & 1 deletion packages/compare-images/typescript/src/index-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ import compareDoubleImagesNode from './compare-double-images-node.js'
export { compareDoubleImagesNode }

import compareImagesNode from './compare-images-node.js'
export { compareImagesNode }
export { compareImagesNode }

export type { Image } from 'itk-wasm'
export type { JsonCompatible } from 'itk-wasm'
5 changes: 4 additions & 1 deletion packages/compare-images/typescript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ import compareDoubleImages from './compare-double-images.js'
export { compareDoubleImages }

import compareImages from './compare-images.js'
export { compareImages }
export { compareImages }

export type { Image } from 'itk-wasm'
export type { JsonCompatible } from 'itk-wasm'
2 changes: 2 additions & 0 deletions packages/compress-stringify/typescript/src/index-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ export type { ParseStringDecompressOptions }

import parseStringDecompressNode from './parse-string-decompress-node.js'
export { parseStringDecompressNode }

export type { BinaryStream } from 'itk-wasm'
2 changes: 2 additions & 0 deletions packages/compress-stringify/typescript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ export type { ParseStringDecompressOptions }

import parseStringDecompress from './parse-string-decompress.js'
export { parseStringDecompress }

export type { BinaryStream } from 'itk-wasm'
5 changes: 5 additions & 0 deletions packages/dicom/typescript/src/index-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,8 @@ export type { ReadImageDicomFileSeriesOptions }

import readImageDicomFileSeriesNode from './read-image-dicom-file-series-node.js'
export { readImageDicomFileSeriesNode }

export type { JsonCompatible } from 'itk-wasm'
export type { Image } from 'itk-wasm'
export type { BinaryStream } from 'itk-wasm'
export type { TextStream } from 'itk-wasm'
5 changes: 5 additions & 0 deletions packages/dicom/typescript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,8 @@ export { readImageDicomFileSeries }

import readImageDicomFileSeriesWorkerFunction from './read-image-dicom-file-series-worker-function.js'
export { readImageDicomFileSeriesWorkerFunction }

export type { JsonCompatible } from 'itk-wasm'
export type { Image } from 'itk-wasm'
export type { BinaryStream } from 'itk-wasm'
export type { TextStream } from 'itk-wasm'
2 changes: 1 addition & 1 deletion src/bindgen/typescript/function-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ function functionModule (srcOutputDir, forNode, interfaceJson, modulePascalCase,
functionContent += `}\n\nexport default ${moduleCamelCase}${nodeTextCamel}\n`
writeIfOverrideNotPresent(path.join(srcOutputDir, `${moduleKebabCase}${nodeTextKebab}.ts`), functionContent)

return { readmeFunction }
return { readmeFunction, usedInterfaceTypes }
}

export default functionModule
9 changes: 8 additions & 1 deletion src/bindgen/typescript/typescript-bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function typescriptBindings (outputDir, buildDir, wasmBinaries, options, forNode
let demoFunctionsHtml = ''
let pipelinesFunctionsTabs = ''
let demoFunctionsTypeScript = ''
const allUsedInterfaceTypes = new Set()

const packageName = options.packageName
const bundleName = packageToBundleName(packageName)
Expand Down Expand Up @@ -129,7 +130,8 @@ function typescriptBindings (outputDir, buildDir, wasmBinaries, options, forNode
indexContent += `export type { ${modulePascalCase}Options }\n\n`
}

const { readmeFunction } = functionModule(srcOutputDir, forNode, interfaceJson, modulePascalCase, moduleKebabCase, moduleCamelCase, nodeTextCamel, nodeTextKebab, haveOptions)
const { readmeFunction, usedInterfaceTypes } = functionModule(srcOutputDir, forNode, interfaceJson, modulePascalCase, moduleKebabCase, moduleCamelCase, nodeTextCamel, nodeTextKebab, haveOptions)
usedInterfaceTypes.forEach(iType => allUsedInterfaceTypes.add(iType))

indexContent += `import ${moduleCamelCase}${nodeTextCamel} from './${moduleKebabCase}${nodeTextKebab}.js'\n`
indexContent += `export { ${moduleCamelCase}${nodeTextCamel} }\n`
Expand All @@ -139,6 +141,11 @@ function typescriptBindings (outputDir, buildDir, wasmBinaries, options, forNode
readmePipelines += readmeResult
})

if (allUsedInterfaceTypes.size > 0) {
indexContent += '\n'
allUsedInterfaceTypes.forEach(iType => indexContent += `export type { ${iType} } from 'itk-wasm'\n`)
}

readmeInterface += ` setPipelinesBaseUrl,
getPipelinesBaseUrl,
setPipelineWorkerUrl,
Expand Down

0 comments on commit 3d15608

Please sign in to comment.