diff --git a/bin/plugin/cli.js b/bin/plugin/cli.js index dc3a8cf65e6204..054199ef4b4b10 100755 --- a/bin/plugin/cli.js +++ b/bin/plugin/cli.js @@ -5,6 +5,17 @@ */ const program = require( 'commander' ); +const catchException = ( command ) => { + return async ( ...args ) => { + try { + await command( ...args ); + } catch ( error ) { + console.error( error ); + process.exitCode = 1; + } + }; +}; + /** * Internal dependencies */ @@ -22,13 +33,13 @@ program .description( 'Release an RC version of the plugin (supports only rc.1 for now)' ) - .action( releaseRC ); + .action( catchException( releaseRC ) ); program .command( 'release-plugin-stable' ) .alias( 'stable' ) .description( 'Release a stable version of the plugin' ) - .action( releaseStable ); + .action( catchException( releaseStable ) ); program .command( 'prepare-packages-stable' ) @@ -36,7 +47,7 @@ program .description( 'Prepares the packages to be published to npm as stable (latest dist-tag, production version)' ) - .action( prepareLatestDistTag ); + .action( catchException( prepareLatestDistTag ) ); program .command( 'prepare-packages-rc' ) @@ -44,7 +55,7 @@ program .description( 'Prepares the packages to be published to npm as RC (next dist-tag, RC version)' ) - .action( prepareNextDistTag ); + .action( catchException( prepareNextDistTag ) ); program .command( 'release-plugin-changelog' ) @@ -52,7 +63,7 @@ program .option( '-m, --milestone ', 'Milestone' ) .option( '-t, --token ', 'Github token' ) .description( 'Generates a changelog from merged Pull Requests' ) - .action( getReleaseChangelog ); + .action( catchException( getReleaseChangelog ) ); program .command( 'performance-tests [branches...]' ) @@ -65,6 +76,6 @@ program .description( 'Runs performance tests on two separate branches and outputs the result' ) - .action( runPerformanceTests ); + .action( catchException( runPerformanceTests ) ); program.parse( process.argv );