plopjs/plop

[enhancement] Allow action function to return a Promise

Open

#242 opened on 2020年9月25日

GitHub で見る
 (7 comments) (0 reactions) (0 assignees)JavaScript (6,845 stars) (266 forks)batch import
enhancementhelp wanted

説明

Similar to #103, but an extension.

It would be great if a custom action could return a Promise that resolves to an array, rather than just an array.

I've been working on a moderately complicated workflow that is ~50 questions (but could be many more if I ever get a recursive prompt to work properly). With such complexity prompt bypassing is obviously MASSIVELY advantageous, and to facilitate that, one of the first actions to run captures the answers in a JSON file so they can be reused later. I have therefore found my application evolving into 2 distinct phases; part 1 to offer to load an old session file, part 2 to perform the meat of the plop. Having tried various approaches using a single plopfile, it seems I must double-plop. I can get the answers to the initial plop and then trigger the second plop using node-plop to load another file from a custom action, but there are drawbacks to this approach. I am currently having to return an empty action array from the custom action, because asynchronous work needs to be done to determine what will happen next. Instead if I could bundle that work into a promise that later resolves to an action array, that would be much neater!

There is also the potential question: would it be worth extending the plop API to add a concept of "phases", so that multiple plops could be handled by the same config-style plopfile? That way one plop phase could feed its answers and action results into the next plop phase.

コントリビューターガイド

[enhancement] Allow action function to return a Promise · plopjs/plop#242 | Good First Issue