plopjs/plop

Set exit code to 1 when generator fails

开放

#210 创建于 2020年4月4日

 (2 条评论) (4 个反应) (0 位负责人)JavaScript (266 个派生)batch import
buggood first issue

仓库指标

星标
 (6,845 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

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 :)

贡献者指南