Permalink
Browse files

Finished up file- and directory-task changes.

  • Loading branch information...
1 parent e2fd14d commit ae990e5bffd8a40e354bcd6365bf1ebbc1e2bd03 @mde mde committed Dec 30, 2011
Showing with 69 additions and 13 deletions.
  1. +69 −3 lib/task.js
  2. +0 −10 lib/task_visitor.js
View
@@ -64,10 +64,16 @@ TaskMixin = new (function () {
}
};
+ this.shouldRunAction = function () {
+ if (this.done || typeof this.action != 'function') {
+ return false
+ }
+ return true;
+ };
+
this.run = function () {
- var runAction = false;
- if (!this.done && typeof this.action == 'function') {
- runAction = true;
+ var runAction = this.shouldRunAction();
+ if (runAction) {
this.action.apply(this, this.args);
}
if (!(runAction && this.async)) {
@@ -87,6 +93,66 @@ for (var p in TaskMixin) {
FileDirectoryMixin = new (function () {
+
+ var isFileOrDirectory = function (t) {
+ return (t instanceof FileTask ||
+ t instanceof DirectoryTask);
+ }
+ , isFile = function (t) {
+ return t instanceof FileTask;
+ };
+
+ this.shouldRunAction = function () {
+ var runAction = false
+ , prereqs = this.prereqs
+ , prereqName
+ , prereqTask;
+
+ // No repeatsies
+ if (this.done) {
+ return false;
+ }
+
+ // We need either an existing file, or an action to create one.
+ // Try grabbing the actual mod-time of the file, then fall back
+ // to looking for an action
+ try {
+ this.updateModTime();
+ }
+ catch(e) {
+ if (typeof this.action == 'function') {
+ return true;
+ }
+ else {
+ throw new Error('File-task ' + this.fullName + ' has no ' +
+ 'existing file, and no action to create one.');
+ }
+ }
+
+ // Compare mod-time of all the prereqs with its mod-time
+ // If any prereqs are newer, need to run the action to update
+ if (prereqs.length) {
+ for (var i = 0, ii = prereqs.length; i < ii; i++) {
+ prereqName = prereqs[i];
+ prereqTask = jake.getTask(prereqName);
+ // Run the action if:
+ // 1. The prereq is a normal task (not file/dir)
+ // 2. The prereq is a file-task with a mod-date more recent than
+ // the one for this file/dir
+ if (prereqTask) {
+ if (!isFileOrDirectory(prereqTask) ||
+ (isFile(prereqTask) && prereqTask.modTime > this.modTime)) {
+ return true;
+ }
+ }
+ }
+ }
+ // File/dir has no prereqs, and exists -- no need to run
+ else {
+ return false;
+ }
+ };
+
this.updateModTime = function () {
var stats = fs.statSync(this.name);
this.modTime = stats.mtime;
View
@@ -14,16 +14,6 @@ var TaskVisitor = new (function () {
name: taskName
, args: taskArgs
};
- }
- , isFileOrDirectory = function (t) {
- return (t instanceof FileTask ||
- t instanceof DirectoryTask);
- }
- , isFile = function (t) {
- return t instanceof FileTask;
- }
- , prereqIsNewerThan = function (prereq, time) {
- return _modTimes[prereq.name] > time;
};
this.visit = function (task) {

0 comments on commit ae990e5

Please sign in to comment.