plopjs/plop

Set exit code to 1 when generator fails

Open

#210 opened on 2020年4月4日

GitHub で見る
 (2 comments) (4 reactions) (0 assignees)JavaScript (6,845 stars) (266 forks)batch import
buggood first issue

説明

Hi 👋

When one of the actions of a generator fails, by default, every following actions are aborted. But the process is in success (see the screenshot, the smiley on the last prompt line is green 😄 ).

image

I guess in many cases this is fine. But I use the generator in the CI, then run the tests of the generated code to make sure they pass. If plop is failing, the CI continues because the exit code was 0 and not 1.

During my investigation I noticed that when executing an action, if it fails it is stored in the failures collection. But nothing is done in the generator promise.

I suggest

  • to add an option in generators abortOnFail set to false by default to ensure BC for other users
  • add a check in the promise to exit with code 1 if failures.length > 1 and abortOnFail is true

It would look like this

return generator.runActions(answers, {onSuccess, onFailure, onComment})
  .then((generator) => {
    progress.stop();
    if (generator.failures.length > 1 && generator.abortOnFail) {
      process.exit(1);
    }
  });

Why do you think?

Thank you for your work by the way :)

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