I am trying to make it so if a --theme flag isn\'t specified it stops the gulp task and wondering the best way to do it in a DRY way.
I would like each individual task t
Some sort of async function might help you here. Maybe like this:
function processArgs(callback) {
if(typeof(args.theme) == 'undefined' || args.theme === true) {
return callback(new Error('Theme Not Defined'));
}
return callback();
}
gulp.task('test', function(done) {
processArgs(function(err) {
if(err) {
console.log(err);
return done(err);
}
//else run my task
})
});
You can simply stop the script with:
process.exit()
I think the easiest way would be to create a verifyArgs
function which throws an error when the requirements aren't met:
function verifyArgs() {
if(typeof(args.theme) == 'undefined' || args.theme === true) {
throw Error(msg.noTheme);
}
}
gulp.task('test', function() {
verifyArgs();
// run rest of task...
});
gulp.task('test-2', function() {
verifyArgs();
// run rest of task...
});
gulp.task('default', ['test-1', 'test-2']);