Skip to content

Commit

Permalink
Merge pull request #416 from atlassian-forks/addAFailOnErrorFlag
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel15 authored Jun 23, 2021
2 parents 57a9d9c + 64bb8e7 commit f6ec09f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ All options are also passed to the transformer, which means you can supply custo
-v, --verbose=0|1|2 show more information about the transform process
(default: 0)
--version print version and exit
--fail-on-error return a 1 exit code when errors were found during execution of codemods
```

This passes the source of all passed through the transform module specified
Expand Down
6 changes: 6 additions & 0 deletions bin/jscodeshift.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ const parser = require('../src/argsParser')
metavar: 'FILE',
process: file => JSON.parse(fs.readFileSync(file)),
},
failOnError: {
flag: true,
help: 'Return a non-zero code when there are errors',
full: 'fail-on-error',
default: false,
},
version: {
help: 'print version and exit',
callback: function() {
Expand Down
4 changes: 4 additions & 0 deletions src/Runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@ function run(transformFile, paths, options) {
process.stdout.write(
'Time elapsed: ' + timeElapsed + 'seconds \n'
);

if (options.failOnError && fileCounters.error > 0) {
process.exit(1);
}
}
if (usedRemoteScript) {
temp.cleanupSync();
Expand Down

0 comments on commit f6ec09f

Please sign in to comment.