plopjs / plop

Consistency Made Simple
http://plopjs.com
MIT License
7.06k stars 277 forks source link

Async follow up prompts #441

Open cduivis opened 3 months ago

cduivis commented 3 months ago

Disclaimer: Maybe not so much be an issue per se as an question / feature request.

Context: We have a folder structure in our project containing a lot of styles and variables for those styles. These styles are overwritable for different clients in the project. I want to use plop to create a wizard for other project members to automatically generate all or a part of those client styles (depending on their needs).

The problem: I need to have follow up questions based on previously made choices. In some of those follow up questions I want to first read a part of the file system structure which will enrich the options that are asked in the follow prompt. The problem with this is that I don't know how I can run async behavior before a prompt is running.

What I've tried:

  1. Creating my own async action which collects data and then tries to retrigger custom prompts by using await plop.inquirer.prompt(). Collection of data works perfectly but triggering the prompt does not sadly results in the cli to just shows a spinner and not the prompt I triggered.
  2. Registering an async function as a new Prompt in the hopes I can scaffold filesystem information there which then triggers a normal inquirer prompt. This errored before I even got to a breakpoint in the function.

Maybe I'm reaching beyond the capabilities of this framework. But I'm curious to learn if there are already ways to:

  1. trigger different follow up prompts based on the answer of the previous prompt;
  2. enrich an inquirer list prompt with async-ly gathered options.