Skip to content

Commit

Permalink
feat(bindgen): Generate Node build configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
thewtex committed Jan 18, 2023
1 parent 2c52310 commit 61f7415
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
29 changes: 29 additions & 0 deletions src/bindgen/rollup.node.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { nodeResolve } from '@rollup/plugin-node-resolve'
import typescript from '@rollup/plugin-typescript'
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import { terser } from 'rollup-plugin-terser'
import packageJson from './package.json' assert { type: 'json' }

export default {
input: './src/indexNode.ts',
output: [
{
file: `./dist/${packageJson.name}.node.js`,
format: 'es',
sourcemap: true,
plugins: [terser(),],
},
],
plugins: [
commonjs({
transformMixedEsModules: true
}),
nodeResolve({
preferBuiltins: true,
browser: false,
}),
typescript(),
json(),
],
}
7 changes: 7 additions & 0 deletions src/bindgen/template.package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"main": "./dist/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "npm run build:tsc && npm run build:node",
"build:node": "rollup -c ./rollup.node.config.js",
"build:tsc": "tsc --pretty"
},
"keywords": [
Expand All @@ -20,6 +22,11 @@
"itk-wasm": "^1.0.0-b.53"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^24.0.0",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-typescript": "^10.0.1",
"rollup": "^3.9.0",
"typescript": "^4.9.4"
}
}
13 changes: 10 additions & 3 deletions src/itk-wasm-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,19 @@ function typescriptBindings(outputDir, buildDir, wasmBinaries, options, forNode=
}
}

const tsConfigPath = path.join(outputDir, 'tsconfig.json')
if (!fs.existsSync(tsConfigPath)) {
fs.copyFileSync(bindgenResource('tsconfig.json'), tsConfigPath)
}

if (forNode) {
const rollupConfigPath = path.join(outputDir, 'rollup.node.config.js')
if (!fs.existsSync(rollupConfigPath)) {
fs.copyFileSync(bindgenResource('rollup.node.config.js'), rollupConfigPath)
}
}

const tsConfigPath = path.join(outputDir, 'tsconfig.json')
if (!fs.existsSync(tsConfigPath)) {
fs.copyFileSync(bindgenResource('tsconfig.json'), tsConfigPath)
}
wasmBinaries.forEach((wasmBinaryName) => {
let wasmBinaryRelativePath = `${buildDir}/${wasmBinaryName}`
if (!fs.existsSync(wasmBinaryRelativePath)) {
Expand Down

0 comments on commit 61f7415

Please sign in to comment.