Skip to content

Commit

Permalink
fix: restore file count in verbose mode
Browse files Browse the repository at this point in the history
  • Loading branch information
remy committed Sep 12, 2015
1 parent 0a8b986 commit 7250919
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 18 deletions.
5 changes: 2 additions & 3 deletions lib/config/index.js
Expand Up @@ -4,6 +4,7 @@
*
* This is *not* the user's config.
*/
var debug = require('debug')('nodemon');
var load = require('./load');
var rules = require('../rules');
var utils = require('../utils');
Expand All @@ -24,9 +25,6 @@ var config = {
run: false,
system: {
cwd: process.cwd(),
useFind: false,
useWatch: false,
useWatchFile: false,
},
required: false,
dirs: [],
Expand Down Expand Up @@ -70,6 +68,7 @@ config.load = function (settings, ready) {
options.monitor = rulesToMonitor(options.watch, options.ignore, config);

var cwd = process.cwd();
debug('config: dirs', config.dirs);
if (config.dirs.length === 0) {
config.dirs.unshift(cwd);
}
Expand Down
7 changes: 2 additions & 5 deletions lib/monitor/match.js
Expand Up @@ -61,11 +61,8 @@ function rulesToMonitor(watch, ignore, config) {
}
rule += '**/*';

// only needed for mac, because on mac we use `find` and it needs some
// narrowing down otherwise it tries to find on the entire drive...which
// is a bit batty.
// `!not` ... sorry.
if (config.system.useFind && !not) {
if (!not) {
config.dirs.push(dir);
}
} else {
Expand All @@ -75,7 +72,7 @@ function rulesToMonitor(watch, ignore, config) {
}
} catch (e) {
var base = tryBaseDir(dir);
if (config.system.useFind && !not && base) {
if (!not && base) {
if (config.dirs.indexOf(base) === -1) {
config.dirs.push(base);
}
Expand Down
40 changes: 31 additions & 9 deletions lib/monitor/watch.js
@@ -1,6 +1,7 @@
module.exports = watch;

var debug = require('debug')('nodemon');
var Promise = require('es6-promise').Promise; // jshint ignore:line
var chokidar = require('chokidar');
var undefsafe = require('undefsafe');
var config = require('../config');
Expand Down Expand Up @@ -29,19 +30,40 @@ function watch() {

debug('start watch on: %s', dirs.join(', '));

var promises = [];

dirs.forEach(function (dir) {
var watcher = chokidar.watch(dir, {
// ignore our files, but also ignore dotfiles
ignored: [config.options.ignore.re, /[\/\\]\./],
persistent: true,
});
var promise = new Promise(function (resolve) {
var watcher = chokidar.watch(dir, {
// ignore our files, but also ignore dotfiles
ignored: [config.options.ignore.re, /[\/\\]\./],
persistent: true,
});

var total = 0;

watcher.on('change', filterAndRestart);
watcher.on('addDir', function (arg) {
debug('watching dir: %s', arg);
watcher.on('change', filterAndRestart);
watcher.on('add', function (arg) {
total++;
debug('watching dir: %s', arg);
});
watcher.on('ready', function () {
resolve(total);
});

watchers.push(watcher);
});
watchers.push(watcher);
promises.push(promise);
});

Promise.all(promises).then(function (res) {
var total = res.reduce(function (acc, curr) {
acc += curr;
return acc;
}, 0);

var count = total.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
utils.log.detail('watching ' + count + ' files');
});
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -49,6 +49,7 @@
"dependencies": {
"chokidar": "^1.0.5",
"debug": "^2.2.0",
"es6-promise": "^3.0.2",
"lodash.defaults": "^3.1.2",
"minimatch": "~0.3.0",
"ps-tree": "~0.0.3",
Expand Down
2 changes: 1 addition & 1 deletion test/rules/index.test.js
Expand Up @@ -19,7 +19,7 @@ describe('nodemon rules', function () {
regexp: loadfixtures('regexp'),
default: loadfixtures('default'),
simple: loadfixtures('simple'),
simplejson: loadfixtures('simple.json')
simplejson: loadfixtures('simple.json'),
};

beforeEach(function (done) {
Expand Down

0 comments on commit 7250919

Please sign in to comment.