2010-02-17 01:42:10 +00:00
|
|
|
(function(){
|
2010-02-18 01:37:30 +00:00
|
|
|
var coffee, fs, no_such_task, path, print_tasks, tasks;
|
2010-02-17 01:42:10 +00:00
|
|
|
var __hasProp = Object.prototype.hasOwnProperty;
|
|
|
|
// `cake` is a simplified version of Make (Rake, Jake) for CoffeeScript.
|
|
|
|
fs = require('fs');
|
|
|
|
path = require('path');
|
|
|
|
coffee = require('coffee-script');
|
|
|
|
tasks = {};
|
2010-02-18 01:37:30 +00:00
|
|
|
no_such_task = function no_such_task(task) {
|
|
|
|
process.stdio.writeError('No such task: "' + task + '"\n');
|
|
|
|
return process.exit(1);
|
|
|
|
};
|
2010-02-17 01:42:10 +00:00
|
|
|
// Mixin the Cake functionality.
|
|
|
|
process.mixin({
|
|
|
|
// Define a task with a name, a description, and the action itself.
|
|
|
|
task: function task(name, description, action) {
|
|
|
|
return tasks[name] = {
|
|
|
|
name: name,
|
|
|
|
description: description,
|
|
|
|
action: action
|
|
|
|
};
|
|
|
|
},
|
|
|
|
// Invoke another task in the Cakefile.
|
|
|
|
invoke: function invoke(name) {
|
2010-02-18 01:37:30 +00:00
|
|
|
if (!(tasks[name])) {
|
|
|
|
no_such_task(name);
|
|
|
|
}
|
2010-02-17 01:42:10 +00:00
|
|
|
return tasks[name].action();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// Display the list of Cake tasks.
|
|
|
|
print_tasks = function print_tasks() {
|
|
|
|
var _a, _b, _c, _d, _e, _f, _g, i, name, spaces, task;
|
|
|
|
_a = []; _b = tasks;
|
|
|
|
for (name in _b) if (__hasProp.call(_b, name)) {
|
|
|
|
task = _b[name];
|
|
|
|
_a.push((function() {
|
|
|
|
spaces = 20 - name.length;
|
2010-02-18 00:19:51 +00:00
|
|
|
spaces = spaces > 0 ? (function() {
|
2010-02-17 01:42:10 +00:00
|
|
|
_c = []; _f = 0; _g = spaces;
|
|
|
|
for (_e=0, i=_f; (_f <= _g ? i <= _g : i >= _g); (_f <= _g ? i += 1 : i -= 1), _e++) {
|
|
|
|
_c.push(' ');
|
|
|
|
}
|
|
|
|
return _c;
|
2010-02-18 00:19:51 +00:00
|
|
|
}).call(this).join('') : '';
|
2010-02-17 01:42:10 +00:00
|
|
|
return puts("cake " + name + spaces + ' # ' + task.description);
|
|
|
|
}).call(this));
|
|
|
|
}
|
|
|
|
return _a;
|
|
|
|
};
|
2010-02-17 04:23:43 +00:00
|
|
|
// Running `cake` runs the tasks you pass asynchronously (node-style), or
|
|
|
|
// prints them out, with no arguments.
|
2010-02-17 01:42:10 +00:00
|
|
|
exports.run = function run() {
|
|
|
|
return path.exists('Cakefile', function(exists) {
|
|
|
|
var args;
|
|
|
|
if (!(exists)) {
|
|
|
|
throw new Error('Cakefile not found in ' + process.cwd());
|
|
|
|
}
|
|
|
|
args = process.ARGV.slice(2, process.ARGV.length);
|
2010-02-17 13:51:27 +00:00
|
|
|
return fs.readFile('Cakefile').addCallback(function(source) {
|
2010-02-17 01:42:10 +00:00
|
|
|
var _a, _b, _c, arg;
|
|
|
|
eval(coffee.compile(source));
|
|
|
|
if (!(args.length)) {
|
|
|
|
return print_tasks();
|
|
|
|
}
|
|
|
|
_a = []; _b = args;
|
|
|
|
for (_c = 0; _c < _b.length; _c++) {
|
|
|
|
arg = _b[_c];
|
2010-02-18 01:37:30 +00:00
|
|
|
_a.push((function() {
|
|
|
|
if (!(tasks[arg])) {
|
|
|
|
no_such_task(arg);
|
|
|
|
}
|
|
|
|
return tasks[arg].action();
|
|
|
|
}).call(this));
|
2010-02-17 01:42:10 +00:00
|
|
|
}
|
|
|
|
return _a;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
})();
|