From 432ecb5a895513956d6f512586268a33b3eb99e4 Mon Sep 17 00:00:00 2001 From: MenTaLguY Date: Thu, 3 Nov 2011 17:31:39 -0700 Subject: [PATCH 1/3] add callbacks for async chaining of tasks --- lib/coffee-script/cake.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/coffee-script/cake.js b/lib/coffee-script/cake.js index a1d3693958..661fb02065 100644 --- a/lib/coffee-script/cake.js +++ b/lib/coffee-script/cake.js @@ -34,9 +34,9 @@ option: function(letter, flag, description) { return switches.push([letter, flag, description]); }, - invoke: function(name) { + invoke: function(name, cb) { if (!tasks[name]) missingTask(name); - return tasks[name].action(options); + return tasks[name].action(options, cb); } }); From 0e4479e53dd296824a11b6429ccf1901b1bc5dad Mon Sep 17 00:00:00 2001 From: MenTaLguY Date: Thu, 3 Nov 2011 17:44:46 -0700 Subject: [PATCH 2/3] task + asyncTask for backwards compat --- lib/coffee-script/cake.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/coffee-script/cake.js b/lib/coffee-script/cake.js index 661fb02065..a1d3693958 100644 --- a/lib/coffee-script/cake.js +++ b/lib/coffee-script/cake.js @@ -34,9 +34,9 @@ option: function(letter, flag, description) { return switches.push([letter, flag, description]); }, - invoke: function(name, cb) { + invoke: function(name) { if (!tasks[name]) missingTask(name); - return tasks[name].action(options, cb); + return tasks[name].action(options); } }); From eba05f1a617466582582445024110818d0eeffde Mon Sep 17 00:00:00 2001 From: MenTaLguY Date: Thu, 3 Nov 2011 17:49:47 -0700 Subject: [PATCH 3/3] do things the proper way --- lib/coffee-script/cake.js | 12 +++++++++--- src/cake.coffee | 16 ++++++++++++---- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/lib/coffee-script/cake.js b/lib/coffee-script/cake.js index a1d3693958..1af40a4b61 100644 --- a/lib/coffee-script/cake.js +++ b/lib/coffee-script/cake.js @@ -20,7 +20,7 @@ oparse = null; helpers.extend(global, { - task: function(name, description, action) { + asyncTask: function(name, description, action) { var _ref; if (!action) { _ref = [description, action], action = _ref[0], description = _ref[1]; @@ -31,12 +31,18 @@ action: action }; }, + task: function(name, description, action) { + return global.asyncTask(name, description, function(options, cb) { + action(options); + return cb(); + }); + }, option: function(letter, flag, description) { return switches.push([letter, flag, description]); }, - invoke: function(name) { + invoke: function(name, cb) { if (!tasks[name]) missingTask(name); - return tasks[name].action(options); + return tasks[name].action(options, cb || (function() {})); } }); diff --git a/src/cake.coffee b/src/cake.coffee index be5e71a945..47e2997888 100644 --- a/src/cake.coffee +++ b/src/cake.coffee @@ -22,11 +22,19 @@ oparse = null # Mixin the top-level Cake functions for Cakefiles to use directly. helpers.extend global, + # Define an asynchronous Cake task with a short name, an optional sentence + # description, and the function to run as the action itself. The function + # takes an additional callback argument to call when it completes. + asyncTask: (name, description, action) -> + [action, description] = [description, action] unless action + tasks[name] = {name, description, action} + # Define a Cake task with a short name, an optional sentence description, # and the function to run as the action itself. task: (name, description, action) -> - [action, description] = [description, action] unless action - tasks[name] = {name, description, action} + global.asyncTask name, description, (options, cb) -> + action(options) + cb() # Define an option that the Cakefile accepts. The parsed options hash, # containing all of the command-line options passed, will be made available @@ -35,9 +43,9 @@ helpers.extend global, switches.push [letter, flag, description] # Invoke another task in the current Cakefile. - invoke: (name) -> + invoke: (name, cb) -> missingTask name unless tasks[name] - tasks[name].action options + tasks[name].action options, cb or (->) # Run `cake`. Executes all of the tasks you pass, in order. Note that Node's # asynchrony may cause tasks to execute in a different order than you'd expect.