Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

feat: add support for passing params via --env to webpack #204

Merged
merged 1 commit into from
Jun 29, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions bin/ns-bundle
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -51,7 +52,7 @@ function execute(options) {
() => cleanApp(platform),
() => cleanSnapshotArtefacts(),
() => cleanBuildArtifacts(platform),
() => webpack(platform),
() => webpack(platform, options.env),
];
}

Expand Down Expand Up @@ -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}...`);

Expand All @@ -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`
];
Expand All @@ -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!"});
Expand Down