Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions Gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
23 changes: 23 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down