Skip to content

Commit

Permalink
Issue jakejs#32 Need to manipulate the invocation-chain, not replace it.
Browse files Browse the repository at this point in the history
  • Loading branch information
mde committed May 29, 2011
1 parent 763d356 commit ecf9c7c
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions lib/jake.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ jake = new function () {
// =================
// Local reference for scopage
var _this = this

, _taskIndex = 0
, _workingTaskList = []
// The list of tasks/prerequisites to run, parsed recursively
// and run bottom-up, so prerequisites run first
, _taskList = []
Expand Down Expand Up @@ -116,7 +119,7 @@ jake = new function () {
maxTime = (maxTime == null || maxTime < ctime) ? ctime : maxTime;
if (prereqsLeft == 0) {
if (maxTime > stats.ctime) {
_taskList.push(name);
_workingTaskList.push(name);
}
callback(maxTime);
}
Expand All @@ -129,7 +132,7 @@ jake = new function () {
else if (err) {
// File not found
if (err.errno == 2) {
_taskList.push(name);
_workingTaskList.push(name);
callback(new Date());
}
// Errors are rethrown.
Expand Down Expand Up @@ -204,15 +207,15 @@ jake = new function () {
_parseDeps(prereqs[i], subOpts, function () {
ctr -= 1;
if (ctr == 0) {
_taskList.push(name);
_workingTaskList.push(name);
callback(new Date());
}
});
}
}
// If the task does not have prerequisites, just push it.
else {
_taskList.push(name);
_workingTaskList.push(name);
callback(new Date());
}
}
Expand Down Expand Up @@ -255,6 +258,12 @@ jake = new function () {
*/
this.runTask = function (name, args, includeDeps) {
this.populateAndProcessTaskList(name, includeDeps, function () {

var args = [_taskIndex, 0];
args = args.concat(_workingTaskList);
_taskList.splice.apply(_taskList, args);
_workingTaskList = [];

if (!_taskList.length) {
fail('No tasks to run.');
}
Expand All @@ -268,15 +277,20 @@ jake = new function () {
this.populateAndProcessTaskList(name, includeDeps, function () {
var name
, task;
if (!_taskList.length) {

if (!_workingTaskList.length) {
fail('No tasks to reenable.');
}
else {
while (name = (_taskList.shift())) {
for (var i = 0, ii = _workingTaskList.length; i < ii; i++) {
name = _workingTaskList[i];
task = self.getTask(name);
task.done = false;
}
}

_workingTaskList = [];

});
};

Expand Down Expand Up @@ -321,8 +335,10 @@ jake = new function () {
* indefinitely
*/
this.runNextTask = function (args) {
var name = _taskList.shift()
, task
var name = _taskList[_taskIndex]
, task;

_taskIndex++;
// If there are still tasks to run, do it
if (name) {
task = this.getTask(name);
Expand Down

0 comments on commit ecf9c7c

Please sign in to comment.