Skip to content

Commit

Permalink
[refactor] Remove watching code from forever.Monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalecki committed Dec 9, 2011
1 parent 0e6ea8f commit 34ccb24
Showing 1 changed file with 1 addition and 65 deletions.
66 changes: 1 addition & 65 deletions lib/forever/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ var util = require('util'),
path = require('path'),
spawn = require('child_process').spawn,
winston = require('winston'),
watch = require('watch'),
minimatch = require('minimatch'),
broadway = require('broadway'),
psTree = require('ps-tree'),
utile = require('utile'),
Expand Down Expand Up @@ -69,17 +67,6 @@ var Monitor = exports.Monitor = function (script, options) {
self._hideEnv[key] = true;
});

//
// Setup watch configuration options
//
this.watchIgnoreDotFiles = options.watchIgnoreDotFiles || true;
this.watchIgnorePatterns = options.watchIgnorePatterns || [];
this.watchDirectory = options.watchDirectory || this.sourceDir;

if (options.watch) {
this.watch();
}

//
// Setup logger for this instance.
//
Expand Down Expand Up @@ -349,58 +336,6 @@ Monitor.prototype.kill = function (forceStop) {
return this;
};

//
// ### function watch ()
// Starts watching directory tree for changes.
//
Monitor.prototype.watch = function () {
var self = this;

fs.readFile(path.join(this.watchDirectory, '.foreverignore'), 'utf8', function (err, data) {
if (err) {
forever.log.warn('Could not read .foreverignore file.');
return forever.log.silly(err.message);
}

Array.prototype.push.apply(self.watchIgnorePatterns, data.split('\n'));
});

watch.watchTree(this.watchDirectory, function (f, curr, prev) {
if (!(curr === null && prev === null && typeof f === 'object')) {
//
// `curr` == null && `prev` == null && typeof f == "object" when watch
// finishes walking the tree to add listeners. We don't need to know
// about it, so we simply ignore it (anything different means that
// some file changed/was removed/created - that's what we want to know).
//
if (self._watchFilter(f)) {
self.info('restaring script because ' + f + ' changed');
self.restart();
}
}
});
};

//
// ### @private function _watchFilter
// #### @file {string} File name
// Determines whether we should restart if `file` change (@mikeal's filtering
// is pretty messed up).
//
Monitor.prototype._watchFilter = function (fileName) {
if (this.watchIgnoreDotFiles && path.basename(fileName)[0] === '.') {
return false;
}

for (var key in this.watchIgnorePatterns) {
if (minimatch(fileName, this.watchIgnorePatterns[key], { matchBase: this.watchDirectory })) {
return false;
}
}

return true;
};

//
// ### @private function _getEnv ()
// Returns the environment variables that should be passed along
Expand Down Expand Up @@ -430,3 +365,4 @@ Monitor.prototype._getEnv = function () {

return merged;
};

0 comments on commit 34ccb24

Please sign in to comment.