plopjs/plop

Set exit code to 1 when generator fails

Open

#210 创建于 2020年4月4日

在 GitHub 查看
 (2 评论) (4 反应) (0 负责人)JavaScript (6,845 star) (266 fork)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 :)

贡献者指南