Skip to content

Commit

Permalink
fixes #429, update to latest chokidar, capture 'ready' event and chec…
Browse files Browse the repository at this point in the history
…k if no files processed at all
  • Loading branch information
dbashford committed Jan 28, 2015
1 parent 07940f7 commit a02ac97
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 120 deletions.
3 changes: 2 additions & 1 deletion lib/util/cleaner.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ Cleaner = (function() {
usePolling: this.config.watch.usePolling
};
this.watcher = watch.watch(this.config.watch.sourceDir, watchConfig);
return this.watcher.on("add", this.workflow.clean);
this.watcher.on("add", this.workflow.clean);
return this.watcher.on("ready", this.workflow.ready);
};

Cleaner.prototype._cleanDone = function() {
Expand Down
1 change: 1 addition & 0 deletions lib/util/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Watcher = (function() {
return _this._fileUpdated('update', f);
});
watcher.on("unlink", this.workflow.remove);
watcher.on("ready", this.workflow.ready);
watcher.on("add", function(f) {
if (_this.throttle > 0) {
return _this.adds.push(f);
Expand Down
163 changes: 88 additions & 75 deletions lib/util/workflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,17 @@ module.exports = WorkflowManager = (function() {
this._buildDone = __bind(this._buildDone, this);
this._buildExtensions = __bind(this._buildExtensions, this);
this._finishedWithFile = __bind(this._finishedWithFile, this);
this._initialFileProcessingDone = __bind(this._initialFileProcessingDone, this);
this._cleanUpRegistration = __bind(this._cleanUpRegistration, this);
this._determineFileCount = __bind(this._determineFileCount, this);
this._init = __bind(this._init, this);
this.register = __bind(this.register, this);
this.add = __bind(this.add, this);
this.remove = __bind(this.remove, this);
this.update = __bind(this.update, this);
this.clean = __bind(this.clean, this);
this.register = __bind(this.register, this);
this.cleanUpRegistration = __bind(this.cleanUpRegistration, this);
this.ready = __bind(this.ready, this);
this.postClean = __bind(this.postClean, this);
this.determineFileCount = __bind(this.determineFileCount, this);
this.initBuild = __bind(this.initBuild, this);
this.initClean = __bind(this.initClean, this);
compilers.setupCompilers(this.config);
Expand All @@ -66,75 +69,51 @@ module.exports = WorkflowManager = (function() {
this.allExtensions = [];
for (_j = 0, _len1 = modules.length; _j < _len1; _j++) {
module = modules[_j];
if (module.registration != null) {
if (module.registration) {
module.registration(this.config, this.register);
}
}
this.allExtensions = _.uniq(this.allExtensions);
this.cleanUpRegistration();
this.determineFileCount();
this._cleanUpRegistration();
}

WorkflowManager.prototype.initClean = function(cb) {
return this._executeWorkflowStep({}, 'preClean', cb);
return this._init("preClean", cb);
};

WorkflowManager.prototype.initBuild = function(cb) {
var _this = this;
return this._executeWorkflowStep({}, 'preBuild', function() {
_this.determineFileCount();
return cb();
});
};

WorkflowManager.prototype.determineFileCount = function() {
var files, w,
_this = this;
w = this.config.watch;
files = fileUtils.readdirSyncRecursive(w.sourceDir, w.exclude, w.excludeRegex, true).filter(function(f) {
var ext;
ext = path.extname(f).substring(1);
return ext.length >= 1 && _this.allExtensions.indexOf(ext) >= 0;
});
return this.initialFileCount = files.length;
return this._init("preBuild", cb);
};

WorkflowManager.prototype.postClean = function(cb) {
return this._executeWorkflowStep({}, 'postClean', cb);
};

WorkflowManager.prototype.cleanUpRegistration = function() {
var i, st, step, stepReg, type, typeReg, _ref, _results;
logger.debug("Cleaning up unused workflow steps");
_ref = this.registration;
_results = [];
for (type in _ref) {
typeReg = _ref[type];
_results.push((function() {
var _i, _len, _ref1, _results1;
_results1 = [];
for (step in typeReg) {
stepReg = typeReg[step];
if (Object.keys(stepReg).length === 0) {
i = 0;
_ref1 = this.types[type];
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
st = _ref1[_i];
if (st === step) {
this.types[type].splice(i, 1);
break;
}
i++;
}
_results1.push(delete typeReg[step]);
} else {
_results1.push(void 0);
}
}
return _results1;
}).call(this));
WorkflowManager.prototype.ready = function() {
if (this.initialFileCount === 0) {
logger.info("No files to be processed");
return this._initialFileProcessingDone();
}
};

WorkflowManager.prototype.clean = function(fileName) {
return this._executeWorkflowStep(this._buildAssetOptions(fileName), 'cleanFile');
};

WorkflowManager.prototype.update = function(fileName) {
return this._executeWorkflowStep(this._buildAssetOptions(fileName), 'update');
};

WorkflowManager.prototype.remove = function(fileName) {
return this._executeWorkflowStep(this._buildAssetOptions(fileName), 'remove');
};

WorkflowManager.prototype.add = function(fileName) {
if (this.startup) {
return this._executeWorkflowStep(this._buildAssetOptions(fileName), 'buildFile');
} else {
return this._executeWorkflowStep(this._buildAssetOptions(fileName), 'add');
}
return _results;
};

WorkflowManager.prototype.register = function(types, step, callback, extensions) {
Expand Down Expand Up @@ -182,23 +161,66 @@ module.exports = WorkflowManager = (function() {
}
};

WorkflowManager.prototype.clean = function(fileName) {
return this._executeWorkflowStep(this._buildAssetOptions(fileName), 'cleanFile');
WorkflowManager.prototype._init = function(step, cb) {
var _this = this;
return this._executeWorkflowStep({}, step, function() {
_this._determineFileCount();
return cb();
});
};

WorkflowManager.prototype.update = function(fileName) {
return this._executeWorkflowStep(this._buildAssetOptions(fileName), 'update');
WorkflowManager.prototype._determineFileCount = function() {
var files, w,
_this = this;
w = this.config.watch;
files = fileUtils.readdirSyncRecursive(w.sourceDir, w.exclude, w.excludeRegex, true).filter(function(f) {
var ext;
ext = path.extname(f).substring(1);
return ext.length >= 1 && _this.allExtensions.indexOf(ext) >= 0;
});
return this.initialFileCount = files.length;
};

WorkflowManager.prototype.remove = function(fileName) {
return this._executeWorkflowStep(this._buildAssetOptions(fileName), 'remove');
WorkflowManager.prototype._cleanUpRegistration = function() {
var i, st, step, stepReg, type, typeReg, _ref, _results;
_ref = this.registration;
_results = [];
for (type in _ref) {
typeReg = _ref[type];
_results.push((function() {
var _i, _len, _ref1, _results1;
_results1 = [];
for (step in typeReg) {
stepReg = typeReg[step];
if (Object.keys(stepReg).length === 0) {
i = 0;
_ref1 = this.types[type];
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
st = _ref1[_i];
if (st === step) {
this.types[type].splice(i, 1);
break;
}
i++;
}
_results1.push(delete typeReg[step]);
} else {
_results1.push(void 0);
}
}
return _results1;
}).call(this));
}
return _results;
};

WorkflowManager.prototype.add = function(fileName) {
if (this.startup) {
return this._executeWorkflowStep(this._buildAssetOptions(fileName), 'buildFile');
WorkflowManager.prototype._initialFileProcessingDone = function() {
if (this.config.isClean) {
if (this.buildDoneCallback != null) {
return this.buildDoneCallback();
}
} else {
return this._executeWorkflowStep(this._buildAssetOptions(fileName), 'add');
return this._buildExtensions();
}
};

Expand Down Expand Up @@ -284,21 +306,12 @@ module.exports = WorkflowManager = (function() {
return next();
};

WorkflowManager.prototype.hash = {};

WorkflowManager.prototype._finishedWithFile = function(options) {
if (logger.isDebug()) {
logger.debug("Finished with file [[ " + options.inputFile + " ]]");
}
this._writeTime(options);
if (this.startup && ++this.initialFilesHandled === this.initialFileCount) {
if (this.config.isClean) {
if (this.buildDoneCallback != null) {
return this.buildDoneCallback();
}
} else {
return this._buildExtensions();
}
return this._initialFileProcessingDone();
}
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"ansi-color": "0.2.1",
"wrench": "1.5.8",
"commander": "1.3.2",
"chokidar": "0.6.3",
"chokidar": "0.12.6",
"request": "2.33.0",
"logmimosa": "1.0.4",
"skelmimosa": "1.2.0",
Expand Down
2 changes: 2 additions & 0 deletions src/util/cleaner.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Cleaner

@watcher = watch.watch @config.watch.sourceDir, watchConfig
@watcher.on "add", @workflow.clean
@watcher.on "ready", @workflow.ready


_cleanDone: =>
@workflow.postClean =>
Expand Down
1 change: 1 addition & 0 deletions src/util/watcher.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Watcher
watcher.on "error", (error) -> logger.warn "File watching error: #{error}"
watcher.on "change", (f) => @_fileUpdated('update', f)
watcher.on "unlink", @workflow.remove
watcher.on "ready", @workflow.ready
watcher.on "add", (f) =>
if @throttle > 0
@adds.push(f)
Expand Down
Loading

0 comments on commit a02ac97

Please sign in to comment.