I've got a UI project, with an automation workflow based on generator-gulp-angular. I added gulp-ng-config
, in order to perform builds differently based on an environment variable. I use the package 'yargs' to extract the environment flag, and make it available to that task. But even though the task should be encapsulated, my use of yargs to create requirements for it is now active on all gulp tasks in my whole project.
Here's the gulp task for ngconfig
:
var gulp = require('gulp');
var path = require('path');
var conf = require('./conf');
var gulpNgConfig = require('gulp-ng-config');
var argv = require('yargs')
.usage('This `build` or `serve` task includes an ngConfig task, whose requirements have not been met via arguments. \n LONG USAGE: <command> --environment <"production" or "sit" or "local">.\n SHORT USAGE <command> -e <"production" or "sit" or "local">')
.epilogue('For more information, see the iJoin client README.')
.demand(['e'])
.alias('e', 'environment')
.argv;
gulp.task('ngconfig', function() {
// default config:
var thisConfig = {
environment: argv.environment,
wrap: "(function () { \n 'use strict'; \n return <%= module %> \n })();"
};
gulp.src('gulp/server-config.json')
.pipe(gulpNgConfig('ijoin.apiConfig', thisConfig))
.pipe(gulp.dest(path.join(conf.paths.src, '/app/prebuild')));
});
And it's invoked as part of build
, here:
gulp.task('build', ['ngconfig', 'html', 'fonts', 'other']);
When we want to perform a build with our environment variable, we execute
gulp build -e local
And, it's all working fine! But it's spilling over into my other tasks. For instance, when I start up my local API mock server, with:
gulp stubby
It complains that I haven't included the necessary args:
This `build` or `serve` task includes an ngConfig task, whose requirements have not
been met via arguments.
LONG USAGE: <command> --environment <"production" or "sit" or "local">.
SHORT USAGE <command> -e <"production" or "sit" or "local">
Options:
-e, --environment [required]
For more information, see the iJoin client README.
Missing required arguments: e
But my intent was that those necessary args are required only on the ngconfig
task. (ngconfig
is definitely not a dependency of stubby
.) So, why the spill-over into other tasks, and how do I fix it?