diff --git a/Gulpfile.js b/Gulpfile.js index 2bb0f43..b885ea2 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -36,10 +36,8 @@ gulp.task('test', ['lint'], function () { stream .on('restart', 'cssmin') .on('crash', function (){ - console.error('\nApplication has crashed!\n') - console.error('Restarting in 2 seconds...\n') - setTimeout(function () { - stream.emit('restart') - }, 2000) + console.error('\nApplication has crashed!') + console.error('Restarting in 3 seconds') + stream.nodemon.emit('restart', 3000) }) }) diff --git a/index.js b/index.js index 8c6d152..1056680 100644 --- a/index.js +++ b/index.js @@ -20,6 +20,7 @@ module.exports = function (options) { // Our script var script = nodemon(options) , originalOn = script.on + , originalEmit = script.emit , originalListeners = bus.listeners('restart') // Allow for injection of tasks on file change @@ -79,6 +80,28 @@ module.exports = function (options) { } } + script.nodemon = { + // Shim 'emit' for use with gulp + emit: function (event, timeout){ + if (typeof event !== 'string') + throw new Error('Event must be a string!') + + if (!timeout) { + console.info('Received event: ' + event) + originalEmit(event) + } + + else if (typeof timeout !== 'number') + throw new Error('Timeout must be a number!') + else { + console.info('Received event: ' + event) + setTimeout(function (){ + originalEmit(event) + }, timeout) + } + } + } + return script }