diff --git a/.gitignore b/.gitignore index 1039bd96583..9ff268fd909 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ .idea/ .vscode/ build +tree*.html coverage docs examples/dist diff --git a/build.mjs b/build.mjs new file mode 100644 index 00000000000..256aa38d2b2 --- /dev/null +++ b/build.mjs @@ -0,0 +1,38 @@ +/** + * Build helper scripts + * Usage: node build.mjs [options] -- [rollup options] + * + * Options: + * target:: - Specify the target module format and build type. Example: target:esm:release + * target: - Specify the target module format only. Example: target:esm + * target: - Specify the build type only. Example: target:release + * + * treemap - Enable treemap build visualization. + * treenet - Enable treenet build visualization. + * treesun - Enable treesun build visualization. + */ + +import { execSync } from 'child_process'; + +const args = process.argv.slice(2); + +const ENV_START_MATCHES = [ + 'target', + 'treemap', + 'treenet', + 'treesun' +]; + +const env = []; +for (let i = 0; i < args.length; i++) { + if (ENV_START_MATCHES.some(match => args[i].startsWith(match))) { + env.push(`--environment ${args[i]}`); + args.splice(i, 1); + i--; + continue; + } +} + +const cmd = `rollup -c ${args.join(' ')} ${env.join(' ')}`; +console.log(cmd); +execSync(cmd, { stdio: 'inherit' }); diff --git a/package.json b/package.json index 45feaab6ec5..d7cd61546a8 100644 --- a/package.json +++ b/package.json @@ -124,29 +124,29 @@ "xhr2": "^0.2.1" }, "scripts": { - "build": "rollup -c", - "build:release": "rollup -c --environment target:release", - "build:debug": "rollup -c --environment target:debug", - "build:profiler": "rollup -c --environment target:profiler", - "build:extras": "rollup -c --environment target:extras", - "build:types": "rollup -c --environment target:types", - "build:umd": "rollup -c --environment target:umd", - "build:esm": "rollup -c --environment target:esm", - "build:esm:release": "rollup -c --environment target:esm:release", - "build:esm:debug": "rollup -c --environment target:esm:debug", - "build:treemap": "npm run build:umd -- --environment treemap", - "build:treenet": "npm run build:umd -- --environment treenet", - "build:treesun": "npm run build:umd -- --environment treesun", + "build": "node build.mjs", + "build:release": "npm run build target:release", + "build:debug": "npm run build target:debug", + "build:profiler": "npm run build target:profiler", + "build:extras": "npm run build target:extras", + "build:types": "npm run build target:types", + "build:umd": "npm run build target:umd", + "build:esm": "npm run build target:esm", + "build:esm:release": "npm run build target:esm:release", + "build:esm:debug": "npm run build target:esm:debug", + "build:treemap": "npm run build target:umd treemap", + "build:treenet": "npm run build target:umd treenet", + "build:treesun": "npm run build target:umd treesun", "build:sourcemaps": "npm run build -- -m", - "build:publish": "npm run build && npm run build:types && npm run publint", + "build:publish": "npm run build && npm run publint", "watch": "npm run build -- -w", - "watch:release": "npm run build:release -- -w", - "watch:debug": "npm run build:debug -- -w", - "watch:profiler": "npm run build:profiler -- -w", - "watch:umd": "npm run build:umd -- -w", - "watch:esm": "npm run build:esm -- -w", - "watch:esm:release": "npm run build:esm:release -- -w", - "watch:esm:debug": "npm run build:esm:debug -- -w", + "watch:release": "npm run build target:release -- -w", + "watch:debug": "npm run build target:debug -- -w", + "watch:profiler": "npm run build target:profiler -- -w", + "watch:umd": "npm run build target:umd -- -w", + "watch:esm": "npm run build target:esm -- -w", + "watch:esm:release": "npm run build target:esm:release -- -w", + "watch:esm:debug": "npm run build target:esm:debug -- -w", "docs": "typedoc", "lint": "eslint --ext .js,.mjs extras scripts src test utils rollup.config.mjs", "publint": "publint",