uetchy / create-create-app

⚡️ Create your own `create-something` app.
MIT License
94 stars 24 forks source link

feat: Access `answers` in `extras` for conditional prompts #59

Closed CobyPear closed 1 year ago

CobyPear commented 1 year ago

Hi, thanks for creating and maintaining this project, it's really neat!

There is one thing blocking me from using this project - I would like to be able to reference the answers object inside of subsequent questions, so that I can determine which prompts to ask based on the previous answers.

If there is a way to do this with the current API please let me know. If it would be possible to make prompt a function that returns the current answers, then the value of prompt can be determined programatically.

Example:

create('create-example-app', {
  templateRoot,
  extra: {
    firstPrompt: {
      type: 'list',
      describe: 'choose your answer',
      choices: ['One', 'Two'],
      prompt: 'if-no-arg',
    },
    conditionalPrompt: {
      type: 'list',
      describe: 'Choose the next answer if the first answer was One',
      choices: ['Three', 'Four'],
      prompt:  (answer) => {
        if (answer === 'One') {
          return 'if-no-arg'
        } else {
          return 'never'
        }
    },
  },
  after: ({ answers }) => console.log(`Ok you chose ${answers}.`),
  caveat,
});

Please let me know if this is something worth implementing, I would like to help implement it if possible. Thanks!

CobyPear commented 1 year ago

I did some poking around and it seems like without some changes to the underlying prompt library (yargs-interactive), or some wizardry out of my range, this is not easily achievable. Closing this!