2010-02-17 01:42:10 +00:00
|
|
|
(function(){
|
2010-06-12 23:05:13 +00:00
|
|
|
var CoffeeScript, fs, helpers, missingTask, oparse, options, optparse, path, printTasks, switches, tasks;
|
2010-02-17 01:42:10 +00:00
|
|
|
fs = require('fs');
|
|
|
|
path = require('path');
|
2010-03-16 05:53:25 +00:00
|
|
|
helpers = require('./helpers').helpers;
|
2010-03-16 03:39:46 +00:00
|
|
|
optparse = require('./optparse');
|
|
|
|
CoffeeScript = require('./coffee-script');
|
2010-02-17 01:42:10 +00:00
|
|
|
tasks = {};
|
2010-02-26 02:43:42 +00:00
|
|
|
options = {};
|
|
|
|
switches = [];
|
|
|
|
oparse = null;
|
2010-03-16 05:53:25 +00:00
|
|
|
helpers.extend(global, {
|
2010-05-15 03:40:04 +00:00
|
|
|
task: function(name, description, action) {
|
2010-03-26 09:25:17 +00:00
|
|
|
var _a;
|
2010-04-04 04:20:17 +00:00
|
|
|
if (!(action)) {
|
2010-03-26 09:25:17 +00:00
|
|
|
_a = [description, action];
|
|
|
|
action = _a[0];
|
|
|
|
description = _a[1];
|
|
|
|
}
|
2010-03-21 11:17:58 +00:00
|
|
|
tasks[name] = {
|
2010-02-17 01:42:10 +00:00
|
|
|
name: name,
|
|
|
|
description: description,
|
|
|
|
action: action
|
|
|
|
};
|
2010-03-21 11:17:58 +00:00
|
|
|
return tasks[name];
|
2010-02-17 01:42:10 +00:00
|
|
|
},
|
2010-05-15 03:40:04 +00:00
|
|
|
option: function(letter, flag, description) {
|
2010-02-26 02:43:42 +00:00
|
|
|
return switches.push([letter, flag, description]);
|
|
|
|
},
|
2010-05-15 03:40:04 +00:00
|
|
|
invoke: function(name) {
|
2010-02-18 01:37:30 +00:00
|
|
|
if (!(tasks[name])) {
|
2010-06-12 23:05:13 +00:00
|
|
|
missingTask(name);
|
2010-02-18 01:37:30 +00:00
|
|
|
}
|
2010-02-26 02:43:42 +00:00
|
|
|
return tasks[name].action(options);
|
2010-02-17 01:42:10 +00:00
|
|
|
}
|
|
|
|
});
|
2010-05-15 03:40:04 +00:00
|
|
|
exports.run = function() {
|
2010-02-17 01:42:10 +00:00
|
|
|
return path.exists('Cakefile', function(exists) {
|
2010-02-26 04:39:14 +00:00
|
|
|
var _a, _b, _c, _d, arg, args;
|
2010-02-17 01:42:10 +00:00
|
|
|
if (!(exists)) {
|
2010-04-04 06:59:44 +00:00
|
|
|
throw new Error(("Cakefile not found in " + (process.cwd())));
|
2010-02-17 01:42:10 +00:00
|
|
|
}
|
2010-03-31 00:06:44 +00:00
|
|
|
args = process.argv.slice(2, process.argv.length);
|
2010-05-15 04:34:14 +00:00
|
|
|
CoffeeScript.run(fs.readFileSync('Cakefile').toString(), {
|
2010-03-08 03:17:45 +00:00
|
|
|
source: 'Cakefile'
|
|
|
|
});
|
2010-02-26 02:53:42 +00:00
|
|
|
oparse = new optparse.OptionParser(switches);
|
|
|
|
if (!(args.length)) {
|
2010-06-12 23:05:13 +00:00
|
|
|
return printTasks();
|
2010-02-26 02:53:42 +00:00
|
|
|
}
|
|
|
|
options = oparse.parse(args);
|
2010-03-27 20:04:47 +00:00
|
|
|
_a = []; _c = options.arguments;
|
|
|
|
for (_b = 0, _d = _c.length; _b < _d; _b++) {
|
|
|
|
arg = _c[_b];
|
2010-02-26 02:53:42 +00:00
|
|
|
_a.push(invoke(arg));
|
|
|
|
}
|
|
|
|
return _a;
|
2010-02-17 01:42:10 +00:00
|
|
|
});
|
|
|
|
};
|
2010-06-12 23:05:13 +00:00
|
|
|
printTasks = function() {
|
2010-05-31 23:38:45 +00:00
|
|
|
var _a, _b, desc, i, name, spaces, task;
|
2010-02-26 02:43:42 +00:00
|
|
|
puts('');
|
|
|
|
_a = tasks;
|
2010-07-16 01:18:35 +00:00
|
|
|
for (name in _a) {
|
2010-02-26 02:43:42 +00:00
|
|
|
task = _a[name];
|
|
|
|
spaces = 20 - name.length;
|
|
|
|
spaces = spaces > 0 ? (function() {
|
2010-05-31 23:38:45 +00:00
|
|
|
_b = [];
|
|
|
|
for (i = 0; i <= spaces; i += 1) {
|
2010-02-26 02:43:42 +00:00
|
|
|
_b.push(' ');
|
|
|
|
}
|
|
|
|
return _b;
|
2010-04-10 18:40:05 +00:00
|
|
|
})().join('') : '';
|
2010-04-11 20:57:53 +00:00
|
|
|
desc = task.description ? ("# " + task.description) : '';
|
2010-06-28 03:55:18 +00:00
|
|
|
puts("cake " + name + spaces + " " + desc);
|
2010-07-16 01:18:35 +00:00
|
|
|
}
|
2010-02-26 02:43:42 +00:00
|
|
|
if (switches.length) {
|
2010-03-06 18:59:11 +00:00
|
|
|
return puts(oparse.help());
|
2010-02-26 02:43:42 +00:00
|
|
|
}
|
2010-02-25 06:17:43 +00:00
|
|
|
};
|
2010-06-12 23:05:13 +00:00
|
|
|
missingTask = function(task) {
|
2010-06-28 03:55:18 +00:00
|
|
|
puts("No such task: \"" + task + "\"");
|
2010-02-25 06:17:43 +00:00
|
|
|
return process.exit(1);
|
|
|
|
};
|
2010-02-24 23:56:32 +00:00
|
|
|
})();
|