From 94bcbdd366afb2d27f41372cab70aa843975bb6c Mon Sep 17 00:00:00 2001 From: Rowan de Haas Date: Thu, 29 Jun 2017 09:07:21 +1000 Subject: [PATCH] Add support for passing params via --env to webpack --- bin/ns-bundle | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/bin/ns-bundle b/bin/ns-bundle index afc00541..3304ffb7 100644 --- a/bin/ns-bundle +++ b/bin/ns-bundle @@ -15,6 +15,7 @@ if (!process.env.npm_config_argv) { const escape = arg => `"${arg}"`; const isTnsCommand = flag => flag.endsWith("-app"); +const isEnvCommand = flag => flag.indexOf("env.") > -1; const shouldUglify = () => process.env.npm_config_uglify; const shouldSnapshot = (platform) => platform == "android" && require("os").type() != "Windows_NT" && process.env.npm_config_snapshot; @@ -34,7 +35,7 @@ function getTnsArgs(args) { "--nobundle", ]; - return args.filter(a => !other.includes(a) && !isTnsCommand(a)); + return args.filter(a => !other.includes(a) && !isTnsCommand(a) && !isEnvCommand(a)); } execute(options); @@ -51,7 +52,7 @@ function execute(options) { () => cleanApp(platform), () => cleanSnapshotArtefacts(), () => cleanBuildArtifacts(platform), - () => webpack(platform), + () => webpack(platform, options.env), ]; } @@ -139,7 +140,7 @@ function cleanApp(platform) { }); } -function webpack(platform) { +function webpack(platform, env) { return new Promise(function (resolve, reject) { console.log(`Running webpack for ${platform}...`); @@ -148,6 +149,7 @@ function webpack(platform) { `--config=webpack.config.js`, `--progress`, `--env.${platform}`, + ...env.map(item => `--${item}`), shouldUglify() && `--env.uglify`, shouldSnapshot(platform) && `--env.snapshot` ]; @@ -172,11 +174,16 @@ function getOptions(flags) { let options = {}; options.platform = getPlatform(flags); options.command = getCommand(flags); + options.env = getEnv(flags); options.bundle = !flags.includes("nobundle"); return options; } +function getEnv(flags) { + return flags.filter(item => isEnvCommand(item)); +} + function getPlatform(flags) { if (flags.includes("android") && flags.includes("ios")) { throwError({message: "You cannot use both --android and --ios flags!"});