diff --git a/src/bindgen/template.package.json b/src/bindgen/template.package.json new file mode 100644 index 000000000..ee65ad0e7 --- /dev/null +++ b/src/bindgen/template.package.json @@ -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" +} diff --git a/src/itk-wasm-cli.js b/src/itk-wasm-cli.js index a4bc13e79..160076844 100755 --- a/src/itk-wasm-cli.js +++ b/src/itk-wasm-cli.js @@ -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 @@ -589,7 +596,8 @@ program .action(run) program .command('bindgen [wasmBinaries...]') - .option('-p, --package', 'Output a package configuration files') + .option('-p, --package-name ', 'Output a package configuration files with the given packages name') + .option('-d, --package-description ', 'Description for package') .addOption(new Option('-l, --language ', 'language to generate bindings for, defaults to "typescript"').choices(['typescript',])) .usage('[options] [wasmBinaries...]') .description('Generate WASM module bindings for a language')