diff --git a/helpers/GruntHelper.js b/helpers/GruntHelper.js index 6697cc6..dcd2d04 100644 --- a/helpers/GruntHelper.js +++ b/helpers/GruntHelper.js @@ -164,6 +164,9 @@ module.exports.prototype.runTask = function (taskName) { // Triggers grunt's watch task // Note: We don't use runTask to get access to the child process module.exports.prototype.watch = function () { + // Prevent multiple watch calls + if (this.watchChild) return; + console.log('Starting grunt watch'); var d = q.defer(), @@ -199,9 +202,28 @@ module.exports.prototype.watch = function () { }.bind(this)); + this.watchChild = child; + return d.promise; }; +// Restarts the existing watch process +module.exports.prototype.rewatch = function () { + var cb = function () { + this.watchChild = null; + this.watch(); + }.bind(this); + + // Kill the existing watch + if (this.watchChild) { + this.watchChild.on('close', cb); + + this.watchChild.kill('SIGHUP'); + } else { + cb(); + } +}; + // Triggers the compile tasks to precompile any existing files // Precond: the configuration object supplied to grunt's initConfig module.exports.prototype.compileTasks = function (config) { diff --git a/index.js b/index.js index 1cbd633..901c550 100644 --- a/index.js +++ b/index.js @@ -146,7 +146,11 @@ Ya.prototype.processAdditionalExtension = function (ext) { .then(function () { return this.grunt.compileTasks(config); }.bind(this)); - }.bind(this)) + }.bind(this)) + + .then(function () { + this.grunt.rewatch(); + }.bind(this)) .done(); };