Skip to content
Browse files

try this, it might be a fail.

  • Loading branch information...
1 parent ab0b591 commit e767f6185bf011defb28acc5c9a6419d332a2bdf @maxtaco committed with Dec 1, 2011
Showing with 91 additions and 39 deletions.
  1. +74 −32 lib/coffee-script/cake.js
  2. +17 −7 src/cake.coffee
View
106 lib/coffee-script/cake.js
@@ -1,6 +1,7 @@
-// Generated by CoffeeScript 1.2.1-pre
(function() {
- var CoffeeScript, cakefileDirectory, fatalError, 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;
+
+ tame = require("coffee-script").tame;
fs = require('fs');
@@ -14,35 +15,59 @@
tasks = {};
+ atasks = {};
+
options = {};
switches = [];
oparse = null;
helpers.extend(global, {
- task: function(name, description, action) {
+ task: function(name, description, action, async) {
var _ref;
if (!action) {
_ref = [description, action], action = _ref[0], description = _ref[1];
}
return tasks[name] = {
name: name,
description: description,
- action: action
+ action: action,
+ async: async
};
},
option: function(letter, flag, description) {
return switches.push([letter, flag, description]);
},
- invoke: function(name) {
- if (!tasks[name]) missingTask(name);
- return tasks[name].action(options);
+ invoke: function(name, cb) { /* TAMED */
+ var t;
+ if (!(t = tasks[name])) missingTask(name);
+ (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() {
+ if (cb) return cb();
+ });
}
});
- exports.run = function() {
- var arg, args, _i, _len, _ref, _results;
+ exports.run = function(cb) { /* TAMED */
+ var args;
global.__originalDirname = fs.realpathSync('.');
process.chdir(cakefileDirectory(__originalDirname));
args = process.argv.slice(2);
@@ -51,25 +76,47 @@
});
oparse = new optparse.OptionParser(switches);
if (!args.length) return printTasks();
- try {
- options = oparse.parse(args);
- } catch (e) {
- return fatalError("" + e);
- }
- _ref = options["arguments"];
- _results = [];
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
- arg = _ref[_i];
- _results.push(invoke(arg));
- }
- return _results;
+ options = oparse.parse(args);
+ (function(__tame_k) {
+ var arg, _i, _len, _ref, _results, _while;
+ _ref = options.arguments;
+ _len = _ref.length;
+ _i = 0;
+ _while = function(__tame_k) {
+ var _break, _continue, _kw;
+ _break = __tame_k;
+ _continue = function() {
+ ++_i;
+ return _while(__tame_k);
+ };
+ _kw = _continue;
+ 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 _kw();
+ });
+ } else {
+ return _break();
+ }
+ };
+ _while(__tame_k);
+ })(function() {
+ if (cb) return cb();
+ });
};
printTasks = function() {
- var cakefilePath, desc, name, relative, spaces, task;
- relative = path.relative || path.resolve;
- cakefilePath = path.join(relative(__originalDirname, process.cwd()), 'Cakefile');
- console.log("" + cakefilePath + " defines the following tasks:\n");
+ var desc, name, spaces, task;
+ console.log('');
for (name in tasks) {
task = tasks[name];
spaces = 20 - name.length;
@@ -80,14 +127,9 @@
if (switches.length) return console.log(oparse.help());
};
- fatalError = function(message) {
- console.error(message + '\n');
- console.log('To see a list of all tasks/options, run "cake"');
- return process.exit(1);
- };
-
missingTask = function(task) {
- return fatalError("No such task: " + task);
+ console.log("No such task: \"" + task + "\"");
+ return process.exit(1);
};
cakefileDirectory = function(dir) {
View
24 src/cake.coffee
@@ -15,6 +15,7 @@ CoffeeScript = require './coffee-script'
# Keep track of the list of defined tasks, the accepted options, and so on.
tasks = {}
+atasks = {}
options = {}
switches = []
oparse = null
@@ -24,9 +25,9 @@ helpers.extend global,
# 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) ->
+ task: (name, description, action, async) ->
[action, description] = [description, action] unless action
- tasks[name] = {name, description, action}
+ tasks[name] = {name, description, action, async}
# Define an option that the Cakefile accepts. The parsed options hash,
# containing all of the command-line options passed, will be made available
@@ -35,15 +36,19 @@ helpers.extend global,
switches.push [letter, flag, description]
# Invoke another task in the current Cakefile.
- invoke: (name) ->
- missingTask name unless tasks[name]
- tasks[name].action options
+ invoke: (name, cb) ->
+ missingTask name unless (t = tasks[name])
+ if t.async
+ await t.action options, defer()
+ else
+ t.action options
+ cb() if 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.
# If no tasks are passed, print the help screen. Keep a reference to the
# original directory name, when running Cake tasks from subdirectories.
-exports.run = ->
+exports.run = (cb) ->
global.__originalDirname = fs.realpathSync '.'
process.chdir cakefileDirectory __originalDirname
args = process.argv[2..]
@@ -54,7 +59,9 @@ exports.run = ->
options = oparse.parse(args)
catch e
return fatalError "#{e}"
- invoke arg for arg in options.arguments
+ for arg in options.arguments
+ await invoke arg, defer()
+ cb() if cb
# Display the list of Cake tasks in a format similar to `rake -T`
printTasks = ->
@@ -74,8 +81,11 @@ fatalError = (message) ->
console.log 'To see a list of all tasks/options, run "cake"'
process.exit 1
+<<<<<<< HEAD
missingTask = (task) -> fatalError "No such task: #{task}"
+=======
+>>>>>>> try this, it might be a fail.
# When `cake` is invoked, search in the current and all parent directories
# to find the relevant Cakefile.
cakefileDirectory = (dir) ->

0 comments on commit e767f61

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