How to do a recursive prompt in Yeoman with promises?

Viewed 670

I'm trying to figure out how to do a recursive prompt with a yeoman generator using promises. I am trying to produce a form generator that will first ask for a name for the form component and then ask for a name (that will be used as an id) for each input (ie: firstName, lastName, username, etc.). I've found answers for this question using callbacks but I would like to stick with promises. Below is the code I have so far and what I am attempting to do for the recursion but is not working. Any help and advice is appreciated thank you in advance!

const Generator = require('yeoman-generator')

const questions = [
  { type: 'input',
    name: 'name',
    message: 'What is the name of this form?',
    default: 'someForm'
  },
  {
    type: 'input',
    name: 'input',
    message: 'What is the name of the input?'
  },
  {
    type: 'confirm',
    name: 'askAgain',
    message: 'Is there another input to add?'
  }

]

module.exports = class extends Generator {


  prompting() {
    return this.prompt(questions).then((answers) => {
      if (answers.askAgain) {
        this.prompting()
      }
       this.userOptions = answers
       this.log(this.userOptions)
    })
  }

}
1 Answers
Related