Skip to content

Commit

Permalink
Rewatch on newly added extensions since grunt watch can't hotswap config
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjoelkemp committed Mar 14, 2014
1 parent a34ee88 commit 5bb154e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
22 changes: 22 additions & 0 deletions helpers/GruntHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Expand Down

0 comments on commit 5bb154e

Please sign in to comment.