diff --git a/README.md b/README.md index 16a90241..f894b01a 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/bin/jscodeshift.js b/bin/jscodeshift.js index 8892ca2e..f5d77a92 100755 --- a/bin/jscodeshift.js +++ b/bin/jscodeshift.js @@ -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() { diff --git a/src/Runner.js b/src/Runner.js index d4b2e2ca..baebe8bf 100644 --- a/src/Runner.js +++ b/src/Runner.js @@ -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();