Skip to content

Commit

Permalink
feat(bindgen): Output package.json with name, description
Browse files Browse the repository at this point in the history
  • Loading branch information
thewtex committed Jan 18, 2023
1 parent a3190c2 commit 531e7b6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src/bindgen/template.package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "package-name",
"version": "0.1.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"itk",
"wasm",
"webassembly",
"wasi"
],
"author": "",
"license": "Apache-2.0"
}
12 changes: 10 additions & 2 deletions src/itk-wasm-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,13 +543,20 @@ function bindgen(outputDir, wasmBinaries, options) {
}

let srcOutputDir = outputDir
if (options.package) {
if (options.packageName) {
srcOutputDir = path.join(outputDir, 'src')
try {
fs.mkdirSync(srcOutputDir, { recursive: true })
} catch (err) {
if (err.code !== 'EEXIST') throw err
}

const packageJson = JSON.parse(fs.readFileSync(path.join(path.dirname(import.meta.url.substring(7)), 'bindgen', 'template.package.json')))
packageJson.name = options.packageName
if (options.packageDescription) {
packageJson.description = options.packageDescription
}
fs.writeFileSync(path.join(outputDir, 'package.json'), JSON.stringify(packageJson, null, 2))
}

// Building for emscripten can generate duplicate .umd.wasm and .wasm binaries
Expand Down Expand Up @@ -589,7 +596,8 @@ program
.action(run)
program
.command('bindgen <outputDir> [wasmBinaries...]')
.option('-p, --package', 'Output a package configuration files')
.option('-p, --package-name <package-name>', 'Output a package configuration files with the given packages name')
.option('-d, --package-description <package-description>', 'Description for package')
.addOption(new Option('-l, --language <language>', 'language to generate bindings for, defaults to "typescript"').choices(['typescript',]))
.usage('[options] <outputDir> [wasmBinaries...]')
.description('Generate WASM module bindings for a language')
Expand Down

0 comments on commit 531e7b6

Please sign in to comment.