diff --git a/index.js b/index.js index 9bebded..6e3ebbf 100644 --- a/index.js +++ b/index.js @@ -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 = [ ]; @@ -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 ); } ); diff --git a/package.json b/package.json index 5f2eb03..4a49ff2 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/src/main.js b/src/main.js index a8f6139..4ab195a 100644 --- a/src/main.js +++ b/src/main.js @@ -9,6 +9,8 @@ module.exports = { return; } + var pretty = require( 'pretty-time' ); + var nodeProcess = require( './process' ); var cmdManager = require( '../index' ).create(); @@ -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 ) { @@ -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(), '', '' ];