From 34ccb24477ba3d094b9135395ff52cc7f8618309 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Ma=C5=82ecki?= Date: Mon, 5 Dec 2011 20:48:18 +0100 Subject: [PATCH] [refactor] Remove watching code from `forever.Monitor` --- lib/forever/monitor.js | 66 +----------------------------------------- 1 file changed, 1 insertion(+), 65 deletions(-) diff --git a/lib/forever/monitor.js b/lib/forever/monitor.js index 81ba6065..3be64702 100644 --- a/lib/forever/monitor.js +++ b/lib/forever/monitor.js @@ -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'), @@ -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. // @@ -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 @@ -430,3 +365,4 @@ Monitor.prototype._getEnv = function () { return merged; }; +