Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How execute other prompt when prompt previous is true on Yeoman?

How execute prompt2 when prompt1 is true on Yeoman as shown below?

var prompts = [
  {name: 'prompt1', message: 'Ask 1?'},
  {name: 'prompt2', message: 'Ask 2?'}
];
like image 384
Fuechter Avatar asked Sep 08 '13 20:09

Fuechter


1 Answers

Yeoman uses a thing called Inquirer.js for the prompt system. Here's an example of how you can ask Question 2 if Question 1 was true:

inquirer.prompt([{
  name: 'movie',
  type: 'confirm',
  message: 'Have you seen a movie lately?'
}, {
  when: function (response) {
    return response.movie;
  },
  name: 'good-or-not',
  message: 'Sweet! Was it any good?'
}], function (response) {});

From the Inquirer.js documentation:

when: (Function) Receive the current user answers hash and should return true or false depending on wheter or not this question should be asked.

like image 142
Stephen Avatar answered Oct 31 '22 14:10

Stephen