From 0dce5bce085f44a8133773000ba66dc9b8188734 Mon Sep 17 00:00:00 2001 From: "Kent C. Dodds" Date: Fri, 8 Sep 2017 12:49:01 -0600 Subject: [PATCH] feat(build): support --watch and --environment flags --- package.json | 3 ++- src/scripts/build/rollup.js | 13 ++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index cb737633..e40d12fe 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,8 @@ "rollup-plugin-json": "^2.3.0", "rollup-plugin-node-resolve": "^3.0.0", "rollup-plugin-uglify": "^2.0.1", - "rollup-watch": "^4.3.1" + "rollup-watch": "^4.3.1", + "yargs-parser": "^7.0.0" }, "repository": { "type": "git", diff --git a/src/scripts/build/rollup.js b/src/scripts/build/rollup.js index 2e1565ae..d6e5f7b2 100644 --- a/src/scripts/build/rollup.js +++ b/src/scripts/build/rollup.js @@ -1,6 +1,7 @@ const path = require('path') const spawn = require('cross-spawn') const rimraf = require('rimraf') +const yargsParser = require('yargs-parser') const { hasFile, resolveBin, @@ -12,6 +13,7 @@ const crossEnv = resolveBin('cross-env') const rollup = resolveBin('rollup') const args = process.argv.slice(2) const here = p => path.join(__dirname, p) +const parsedArgs = yargsParser(args) const useBuiltinConfig = !args.includes('--config') && !hasFile('rollup.config.js') @@ -19,8 +21,17 @@ const config = useBuiltinConfig ? `--config ${here('../../config/rollup.config.js')}` : args.includes('--config') ? '' : '--config' // --config will pick up the rollup.config.js file +const environment = parsedArgs.environment + ? `--environment ${parsedArgs.environment}` + : '' +const watch = parsedArgs.watch ? '--watch' : '' + +const defaultEnv = 'BUILD_ROLLUP=true' + const getCommand = env => - `${crossEnv} BUILD_ROLLUP=true ${env} ${rollup} ${config}` + [crossEnv, defaultEnv, env, rollup, config, environment, watch] + .filter(Boolean) + .join(' ') const scripts = args.includes('--p-react') ? getPReactScripts()