diff --git a/fail.sh b/fail.sh index e6caeb6..3a86954 100755 --- a/fail.sh +++ b/fail.sh @@ -2,6 +2,6 @@ # enable bash fail-fast set -e echo 'start fail'; -sleep 5 +sleep 1 echo 'some text here' exit 1 \ No newline at end of file diff --git a/index.js b/index.js index 4621a9d..c5643dd 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,7 @@ var spawnly = require( 'spawnly' ); var extend = require( 'extend' ); var dispatchy = require( 'dispatchy' ); var Promise = require( 'es6-promise' ).Promise; +var pretty = require( 'pretty-time' ); function streamToString( stream ) { var chunks = [ ]; @@ -84,7 +85,8 @@ module.exports = { stderr: results[ 1 ], cmd: cmd, exitCode: exitCode, - duration: diff + duration: diff, + durationFormmated: pretty( diff, 'ms' ) }; me.fire( 'command:exit', args ); resolve( args ); @@ -95,6 +97,7 @@ module.exports = { cp.on( 'error', function ( err ) { err = err || { }; err.duration = timer.stop(); + err.durationFormmated = pretty( err.duration, 'ms' ); me.fire( 'command:error', err ); reject( err ); } ); diff --git a/src/main.js b/src/main.js index ae14aee..a476d99 100644 --- a/src/main.js +++ b/src/main.js @@ -1,8 +1,14 @@ var exec = require( 'child_process' ).exec; var path = require( 'path' ); -var pretty = require( 'pretty-time' ); var nodeProcess = require( './process' ); +var printFailed = function ( entries ) { + return entries.reduce( function ( seq, entry ) { + seq += ' - cmd: ' + entry.cmd + ', exitCode: ' + entry.exitCode + '\n'; + return seq; + }, '\n' ); +}; + module.exports = { _execute: function ( program, cmds ) { var cmdManager = require( '../index' ).create(); @@ -14,11 +20,12 @@ module.exports = { } ); cmdManager.on( 'command:error', function ( e, args ) { - program.subtle( 'command error', args, 'duration: ', pretty( args.duration, 'ms' ) ); + program.subtle( 'command error', args, 'duration: ', args.durationFormmated ); } ); cmdManager.on( 'command:exit', function ( e, args ) { - program.subtle( 'command', args.cmd, 'exited with code', args.exitCode + ', took: ', pretty( args.duration, 'ms' ) ); + var method = args.exitCode === 0 ? 'subtle' : 'warn'; + program[ method ]( 'command', args.cmd, 'exited with code', args.exitCode + ', took:', args.durationFormmated ); if ( opts.sortOutput ) { args.stdout && console.log( args.stdout ); args.stderr && console.error( args.stderr ); @@ -47,17 +54,17 @@ module.exports = { p.then( function ( args ) { var results = [ ]; - args.forEach( function ( result ) { if ( result.exitCode !== 0 ) { results.push( { - cmd: result.cmd, exitCode: result.exitCode + cmd: result.cmd, + exitCode: result.exitCode } ); } } ); if ( results.length > 0 ) { - program.error( 'Some commands failed', results ); + program.error( 'Some commands failed', '\n', printFailed( results ) ); process.exit( 1 ); // eslint-disable-line } } ); diff --git a/test.sh b/test.sh index 0730e83..45f77bb 100755 --- a/test.sh +++ b/test.sh @@ -1,6 +1,6 @@ #!/bin/bash # enable bash fail-fast echo 'start test.sh' -sleep 10 -echo 'after 10 seconds' +sleep 3 +echo 'after 3 seconds' exit 0 \ No newline at end of file