Skip to content

Commit

Permalink
[api] Add watchDirectory option
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalecki committed Sep 30, 2011
1 parent b9d9703 commit e2b3565
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions lib/forever/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ var Monitor = exports.Monitor = function (script, options) {
this.times = 0;


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

//
// Setup restart timing. These options control how quickly forever restarts
// a child process as well as when to kill a "spinning" process
Expand Down Expand Up @@ -73,6 +67,17 @@ 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 || false) {
this.watch();
}

//
// Setup log files and logger for this instance.
//
Expand Down Expand Up @@ -380,15 +385,17 @@ Monitor.prototype.kill = function (forceStop) {
Monitor.prototype.watch = function () {
var self = this;

fs.readFile('.foreverignore', 'utf8', function (err, data) {
if (err) {
return self.warn('Could not read .foreverignore file: ' + err.message);
}
Array.prototype.push.apply(self.watchIgnorePatterns, data.split('\n'));
fs.readFile(
this.watchDirectory + '/.foreverignore', 'utf8',
function (err, data) {
if (err) {
return self.warn('Could not read .foreverignore file: ' + err.message);
}
Array.prototype.push.apply(self.watchIgnorePatterns, data.split('\n'));
});

watch.createMonitor(
process.cwd(),
this.watchDirectory,
function (monitor) {
monitor.on('changed', function (f, curr, prev) {
if (self._watchFilter(f)) {
Expand All @@ -411,7 +418,8 @@ Monitor.prototype._watchFilter = function (fileName) {
return false;
}
for (var key in this.watchIgnorePatterns) {
if (minimatch(fileName, this.watchIgnorePatterns[key], {matchBase: process.cwd()})) {
if (minimatch(fileName, this.watchIgnorePatterns[key],
{matchBase: this.watchDirectory})) {
return false;
}
}
Expand Down

0 comments on commit e2b3565

Please sign in to comment.