Skip to content

Commit

Permalink
REF: duration is formatted from shell-executor module
Browse files Browse the repository at this point in the history
  • Loading branch information
royriojas committed Jan 4, 2017
1 parent e2e2fc2 commit 1eb98c1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion fail.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
# enable bash fail-fast
set -e
echo 'start fail';
sleep 5
sleep 1
echo 'some text here'
exit 1
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [ ];
Expand Down Expand Up @@ -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 );
Expand All @@ -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 );
} );
Expand Down
19 changes: 13 additions & 6 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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 );
Expand Down Expand Up @@ -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
}
} );
Expand Down
4 changes: 2 additions & 2 deletions test.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1eb98c1

Please sign in to comment.