plopjs / plop

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

Set exit code to 1 when generator fails #210

Open benja-M-1 opened 4 years ago

benja-M-1 commented 4 years ago

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

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

crutchcorn commented 4 years ago

I like this idea a lot! Since it seems like you already have a lot of the code handled, would you feel comfortable making a PR? :)

Jasperrr91 commented 1 year ago

Can we get this in there? I'm also running into an issue where a tailwind.config.js file might not be created in case our design tokens are faulty, and currently the only workaround seems to write a shell script to check if all files are properly created and if not return exit 1