Skip to content

Commit

Permalink
REF: Add duration for the execution of each command
Browse files Browse the repository at this point in the history
  • Loading branch information
royriojas committed Jan 2, 2017
1 parent 6aab527 commit 660866c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
20 changes: 19 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ var spawnly = require( 'spawnly' );
var extend = require( 'extend' );
var dispatchy = require( 'dispatchy' );

var timeManager = {
start: function () {
var start = process.hrtime();
return {
stop: function () {
var diff = process.hrtime( start );
return (diff[ 0 ] * 1e9) + diff[ 1 ];
}
};
}
};

module.exports = {
create: function () {
var commands = [ ];
Expand All @@ -18,19 +30,25 @@ module.exports = {
run: function ( cmd ) {
var me = this;

var timer = timeManager.start();

var cp = spawnly( cmd, { stdio: 'inherit' } );

me.fire( 'command:start', { cp: cp, cmd: cmd } );

cp.on( 'exit', function ( exitCode ) {
var diff = timer.stop();
me.fire( 'command:exit', {
cp: cp,
cmd: cmd,
exitCode: exitCode
exitCode: exitCode,
duration: diff
} );
} );

cp.on( 'error', function ( err ) {
err = err || { };
err.duration = timer.stop();
me.fire( 'command:error', err );
} );

Expand Down
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,22 @@
"onDirtyState": "stash"
},
"devDependencies": {
"changelogx": "^1.0.16",
"changelogx": "2.0.1",
"esbeautifier": "^4.0.1",
"eslinter": "^2.1.0",
"istanbul": "^0.3.17",
"mocha-runner": "^1.0.8",
"precommit": "^1.1.0",
"prepush": "^3.1.2",
"precommit": "1.2.2",
"prepush": "3.1.11",
"proxyquire": "^1.6.0",
"watch-spawn": "^1.0.3"
"watch-spawn": "2.0.0"
},
"dependencies": {
"clix": "^2.0.13",
"clix": "2.0.16",
"dispatchy": "^1.0.3",
"extend": "^3.0.0",
"spawnly": "^1.0.0"
"pretty-time": "0.2.0",
"spawnly": "1.0.1"
},
"bugs": {
"url": "https://github.com/royriojas/shell-executor/issues"
Expand Down
14 changes: 10 additions & 4 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ module.exports = {
return;
}

var pretty = require( 'pretty-time' );

var nodeProcess = require( './process' );

var cmdManager = require( '../index' ).create();
Expand All @@ -17,8 +19,12 @@ module.exports = {
program.subtle( 'starting command', args.cmd );
} );

cmdManager.on( 'command:error', function ( e, args ) {
program.subtle( 'command error', args, 'duration: ', pretty( args.duration, 's' ) );
} );

cmdManager.on( 'command:exit', function ( e, args ) {
program.subtle( 'command exited', args.exitCode );
program.subtle( 'command', args.cmd, 'exited with code', args.exitCode + ', took: ', pretty( args.duration ) );
} );

cmdManager.on( 'command:killed', function ( e, args ) {
Expand All @@ -34,11 +40,11 @@ module.exports = {
cmdManager.runCmds( cmds );

var lines = [
'Executing commands done',
'To kill commands from the shell In case I become a zombie, execute:',
'Commands execution started',
'',
' To kill commands from the shell In case I become a zombie, execute:',
'',
cmdManager.getKillCommand(),
' ' + cmdManager.getKillCommand(),
'',
''
];
Expand Down

0 comments on commit 660866c

Please sign in to comment.