Use prompt without pipe
Closed this issue · 5 comments
Hi, take a look @ this code:
gulp.task('install', function(){
gulp.src('config/db.js')
.pipe(
gp_prompt.prompt(
{ type: 'input'
, name: 'dbname'
, message: 'Type your DB name:'
},
function (res){
gulp.src('config./db.js')
.pipe(gp_replace('_DBNAME_', res.dbname))
.pipe(savefile())
}
)
)
});
There's a way to use gulp-prompt
without open 2 gulp.src('config/db.js')
?
I think that this Is not posible.
I use gulp.src('package.json') but it is ugly and slowing down the init.
I haven't really investigated why this works, but if you call .write()
on the prompt stream, it will work:
gulp.task('install', function(){
var prompter = gp_prompt.prompt(
{ type: 'input'
, name: 'dbname'
, message: 'Type your DB name:'
},
function (res){
gulp.src('config./db.js')
.pipe(gp_replace('_DBNAME_', res.dbname))
.pipe(savefile())
}
)
prompter.write()
return prompter()
});
This probably has something to do with gulp not liking the Stream that Inquirer is returning
I miss this feature too.
I tried a confirm question with write(), @codyrushing . It didn't work as expected for me. The task was finished and then the question shown up.
Solved with Inquirer.js which is the library used by gulp-prompt
Example:
Both stop the gulp execution when the answer is 'no'.
//gulp-prompt
gulp.task('prompt', () => {
const question = {
message : 'Do you want to continue?(no)',
default : false
};
return gulp.src('file')
.pipe(prompt.confirm(question));
});
//Inquirer.js
gulp.task('prompt', () => {
const question = [
{
type : 'confirm',
name : 'continue',
message : 'Do you want to continue?(no)',
default : false
}
];
return inquirer.prompt(question).then(answer => {
if (!answer.continue) {
return process.exit (2);
}
});
});
I am going to close this issue out since yuricamara seems to have provided a solution. If there is still any outstanding questions or concerns please let me know.