From d32b68da1b13b34a4a682f1d26020b80fdb5e2b4 Mon Sep 17 00:00:00 2001 From: Dan Tyler Date: Fri, 25 Apr 2014 16:38:58 -0400 Subject: [PATCH 1/3] Emit an event when gaze has finished setting up --- tasks/watch.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tasks/watch.js b/tasks/watch.js index e309d1c..ff9965c 100644 --- a/tasks/watch.js +++ b/tasks/watch.js @@ -165,6 +165,11 @@ module.exports = function(grunt) { taskrun.run(); }); + // Emit ready event once gaze is ready if anyone is listening + if (grunt.event.listeners('watch-ready').length > 0) { + grunt.event.emit('watch-ready'); + } + // On watcher error this.on('error', function(err) { if (typeof err === 'string') { err = new Error(err); } From 835475b65e1ced4729e5a387bb44b32ceb15244d Mon Sep 17 00:00:00 2001 From: Dan Tyler Date: Tue, 20 May 2014 09:06:58 -0400 Subject: [PATCH 2/3] watch ready event fires after all targets processed --- tasks/watch.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tasks/watch.js b/tasks/watch.js index ff9965c..f3a95b1 100644 --- a/tasks/watch.js +++ b/tasks/watch.js @@ -165,11 +165,6 @@ module.exports = function(grunt) { taskrun.run(); }); - // Emit ready event once gaze is ready if anyone is listening - if (grunt.event.listeners('watch-ready').length > 0) { - grunt.event.emit('watch-ready'); - } - // On watcher error this.on('error', function(err) { if (typeof err === 'string') { err = new Error(err); } @@ -178,5 +173,9 @@ module.exports = function(grunt) { })); }); + // Emit ready event once gaze is ready if anyone is listening + if (grunt.event.listeners('watch-ready').length > 0) { + grunt.event.emit('watch-ready'); + } }); }; From 9c24a7c2d92aeb84496bf4ae2a89fe3c53371a4e Mon Sep 17 00:00:00 2001 From: Dan Tyler Date: Thu, 5 Jun 2014 10:08:40 -0400 Subject: [PATCH 3/3] Handle async of Gaze --- tasks/watch.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/tasks/watch.js b/tasks/watch.js index f3a95b1..aa2e106 100644 --- a/tasks/watch.js +++ b/tasks/watch.js @@ -82,6 +82,18 @@ module.exports = function(grunt) { // initialize taskrun var targets = taskrun.init(name, {target: target}); + var targetsReady = targets.length; + function watcherIsReady() { + targetsReady--; + + // Take action when all Gaze tasks report ready + if(targetsReady < 1) { + // Emit ready event if anyone is listening + if (grunt.event.listeners('watch-ready').length > 0) { + grunt.event.emit('watch-ready'); + } + } + } targets.forEach(function(target, i) { if (typeof target.files === 'string') { target.files = [target.files]; } @@ -170,12 +182,11 @@ module.exports = function(grunt) { if (typeof err === 'string') { err = new Error(err); } grunt.log.error(err.message); }); + + // + watcherIsReady(); })); }); - // Emit ready event once gaze is ready if anyone is listening - if (grunt.event.listeners('watch-ready').length > 0) { - grunt.event.emit('watch-ready'); - } }); };