Skip to content
Browse files

more work, got cakefiles runnins, can now think about how to test!

  • Loading branch information...
1 parent 332fff2 commit af3668218f432a8978c21176ce77f329f183033f @maxtaco committed Dec 2, 2011
Showing with 106 additions and 14 deletions.
  1. +6 −0 Cakefile
  2. +90 −11 lib/coffee-script/cake.js
  3. +10 −3 src/cake.coffee
View
6 Cakefile
@@ -246,3 +246,9 @@ task 'test:browser', 'run the test suite against the merged browser script', ->
global.testingBrowser = yes
(-> eval source).call result
runTests result.CoffeeScript
+
+atask 'test:acake', 'run a test for Cakefile async', (opts,cb) ->
+ console.log "start sleep"
+ await setTimeout defer(), 1000
+ console.log "end sleep"
+ cb()
View
101 lib/coffee-script/cake.js
@@ -1,5 +1,38 @@
(function() {
- var CoffeeScript, atasks, cakefileDirectory, fs, helpers, missingTask, oparse, options, optparse, path, printTasks, switches, tasks;
+ var CoffeeScript, atasks, cakefileDirectory, fs, helpers, missingTask, oparse, options, optparse, path, printTasks, switches, tame, tasks;
+ var __slice = Array.prototype.slice;
+
+ tame = {
+ Deferrals: (function() {
+
+ function _Class(_arg) {
+ this.continuation = _arg;
+ this.count = 1;
+ }
+
+ _Class.prototype._fulfill = function() {
+ if (!--this.count) return this.continuation();
+ };
+
+ _Class.prototype.defer = function(defer_params) {
+ var _this = this;
+ ++this.count;
+ return function() {
+ var inner_params, _ref;
+ inner_params = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
+ if (defer_params != null) {
+ if ((_ref = defer_params.assign_fn) != null) {
+ _ref.apply(null, inner_params);
+ }
+ }
+ return _this._fulfill();
+ };
+ };
+
+ return _Class;
+
+ })()
+ };
fs = require('fs');
@@ -34,18 +67,41 @@
async: async
};
},
+ atask: function(name, description, action) {
+ return task(name, description, action, true);
+ },
option: function(letter, flag, description) {
return switches.push([letter, flag, description]);
},
- invoke: function(name) {
+ invoke: function(name, cb) { /* TAMED */
var t;
if (!(t = tasks[name])) missingTask(name);
- return t.action(options);
+ (function(__tame_k) {
+ if (t.async) {
+ (function(__tame_k) {
+ var __tame_deferrals;
+ __tame_deferrals = new tame.Deferrals(__tame_k);
+ t.action(options, __tame_deferrals.defer({
+ assign_fn: (function() {
+ return function() {};
+ })()
+ }));
+ __tame_deferrals._fulfill();
+ })(function() {
+ return __tame_k();
+ });
+ } else {
+ t.action(options);
+ return __tame_k();
+ }
+ })(function() {
+ return cb();
+ });
}
});
- exports.run = function(cb) {
- var arg, args, _i, _len, _ref, _results;
+ exports.run = function(cb) { /* TAMED */
+ var arg, args, __tame_k, _i, _len, _ref, _results, _while;
global.__originalDirname = fs.realpathSync('.');
process.chdir(cakefileDirectory(__originalDirname));
args = process.argv.slice(2);
@@ -55,13 +111,36 @@
oparse = new optparse.OptionParser(switches);
if (!args.length) return printTasks();
options = oparse.parse(args);
+ __tame_k = function() {};
_ref = options.arguments;
- _results = [];
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
- arg = _ref[_i];
- _results.push(invoke(arg));
- }
- return _results;
+ _len = _ref.length;
+ _i = 0;
+ _while = function(__tame_k) {
+ var _break, _continue;
+ _break = __tame_k;
+ _continue = function() {
+ ++_i;
+ return _while(__tame_k);
+ };
+ if (_i < _len) {
+ arg = _ref[_i];
+ (function(__tame_k) {
+ var __tame_deferrals;
+ __tame_deferrals = new tame.Deferrals(__tame_k);
+ invoke(arg, __tame_deferrals.defer({
+ assign_fn: (function() {
+ return function() {};
+ })()
+ }));
+ __tame_deferrals._fulfill();
+ })(function() {
+ return _continue();
+ });
+ } else {
+ return _break();
+ }
+ };
+ _while(__tame_k);
};
printTasks = function() {
View
13 src/cake.coffee
@@ -29,16 +29,23 @@ helpers.extend global,
[action, description] = [description, action] unless action
tasks[name] = {name, description, action, async}
+ atask: (name, description, action) ->
+ task name, description, action, true
+
# Define an option that the Cakefile accepts. The parsed options hash,
# containing all of the command-line options passed, will be made available
# as the first argument to the action.
option: (letter, flag, description) ->
switches.push [letter, flag, description]
# Invoke another task in the current Cakefile.
- invoke: (name) ->
+ invoke: (name, cb) ->
missingTask name unless (t = tasks[name])
- t.action options
+ if t.async
+ await t.action(options, defer())
+ else
+ t.action options
+ cb()
# 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.
@@ -56,7 +63,7 @@ exports.run = (cb) ->
catch e
return fatalError "#{e}"
for arg in options.arguments
- invoke arg
+ await invoke(arg,defer())
# Display the list of Cake tasks in a format similar to `rake -T`
printTasks = ->

0 comments on commit af36682

Please sign in to comment.
Something went wrong with that request. Please try again.