NodeJs Gulp - Validate Before Running Task
I have a very heavy gulp task that I want to ask the user if they really want to run the task.
I've already seen gulp-confirm and gulp-prompt, but it doesn't help me:
I don't want to send "confirmation", I just don't want to run a heavy task before confirming the user.
I am trying to achieve something like this:
gulp.task('confirm', [], function ()
{
//Ask the confirm question here and cancel all task if the user abort
prompt.confirm({
message: 'This task will create a new tag version\n. Are you sure you want to continue?',
default: true
});
});
gulp.task('Build Release QA', ['confirm'], function ()//use this task to make release to QA
{
//very heavy task, don't start it if user abort it from 'confirm' task
});
Any ideas?
source to share
No need for a Gulp plugin, in fact the package of these two wrappers - inquirer
- does everything you need:
var inquirer = require('inquirer');
gulp.task('default', function(done) {
inquirer.prompt([{
type: 'confirm',
message: 'Do you really want to start?',
default: true,
name: 'start'
}], function(answers) {
if(answers.start) {
gulp.start('your-gulp-task');
}
done();
});
});
It is important that you pass the callback done
and call it when you are in the callback function inquirer
, so your task does not finish prematurely.
This is one of the best things about Gulp: you may not need these plugins; -)
source to share