Skip to content

Commit

Permalink
Converted to direct port of Rake syntax to allow namespaced tasks.
Browse files Browse the repository at this point in the history
  • Loading branch information
mde committed Jul 3, 2010
1 parent 8d4d38d commit 42fcf55
Showing 1 changed file with 50 additions and 3 deletions.
53 changes: 50 additions & 3 deletions lib/jake.js
Expand Up @@ -17,6 +17,7 @@
*/

var args = process.argv.slice(2);
var sys = require('sys');

var opts = {};
var optsReg = {
Expand Down Expand Up @@ -90,11 +91,25 @@ opts.jakefile = opts.jakefile || './Jakefile';
if (opts.directory) {
process.chdir(opts.directory);
}
var tasks = require(opts.jakefile).tasks;

var jake = new function () {
this.currentNamespace = 'default';
this.currentTaskDescription = null;
this.namespaceTasks = {
'default': {}
};
this.runTask = function (name, args) {
var task = tasks[name];
var nameArr = name.split(':');
var nsName, taskName;
if (nameArr.length > 1) {
nsName = nameArr[0];
taskName = nameArr[1];
}
else {
nsName = 'default';
taskName = name;
}
var task = this.namespaceTasks[nsName][taskName];
if (!task) {
throw new Error('Task "' + name + '" is not defined in the Jakefile.');
}
Expand All @@ -104,7 +119,7 @@ var jake = new function () {
this.runTask.call(this, deps[i], args);
}
}
task.task.apply(task, passArgs);
task.handler.apply(task, passArgs);
};

this.processArgs = function (args) {
Expand All @@ -120,4 +135,36 @@ var jake = new function () {

}();

jake.Task = function (name, deps, handler) {
this.name = name,
this.deps = deps,
this.handler = handler;
this.desription = null;
};

global.task = function (name, deps, handler) {
var task = new jake.Task(name, deps, handler);
if (jake.currentTaskDescription) {
task.description = jake.currentTaskDescription;
jake.currentTaskDescription = null;
}
jake.namespaceTasks[jake.currentNamespace][name] = task;
};

global.desc = function (str) {
jake.currentTaskDescription = str;
};

global.namespace = function (name, tasks) {
if (typeof jake.namespaceTasks[name] == 'undefined') {
jake.namespaceTasks[name] = {};
}
jake.currentNamespace = name;
tasks();
jake.currentNamespace = 'default';
};

var tasks = require(opts.jakefile).tasks;

jake.runTask(taskName, args);

0 comments on commit 42fcf55

Please sign in to comment.