Skip to content

Commit

Permalink
refactor: add debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
remy committed Sep 10, 2015
1 parent 6da471b commit f7a9476
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 18 deletions.
20 changes: 10 additions & 10 deletions bin/nodemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
'use strict';
var cli = require('../lib/cli');
var nodemon = require('../lib/');
var updateNotifier = require('update-notifier');
var pkg = require('../package.json');
// checks for available update and returns an instance
var notifier = updateNotifier({ pkg: pkg });
var options = cli.parse(process.argv);

if (notifier.update) {
// notify using the built-in convenience method
notifier.notify();
}
nodemon(options);

var options = cli.parse(process.argv);
var fs = require('fs');

// checks for available update and returns an instance
var defaults = require('lodash.defaults');
var pkg = JSON.parse(fs.readFileSync(__dirname + '/../package.json'));

nodemon(options);
require('update-notifier')({
pkg: defaults(pkg, { version: '0.0.0' }),
}).notify();
1 change: 1 addition & 0 deletions lib/monitor/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ function run(options) {
});
}

debug('about to watch');
watch();
}

Expand Down
9 changes: 8 additions & 1 deletion lib/monitor/watch.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = watch;

var debug = require('debug');
var debug = require('debug')('nodemon');
var chokidar = require('chokidar');
var undefsafe = require('undefsafe');
var config = require('../config');
Expand All @@ -21,19 +21,26 @@ bus.on('reset', function () {

function watch() {
if (watchers.length) {
debug('early exit on watch, still watching (%s)', watchers.length);
return;
}

var dirs = [].slice.call(config.dirs);

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

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


watcher.on('change', filterAndRestart);
watcher.on('addDir', function (arg) {
debug('watching dir: %s', arg);
});
watchers.push(watcher);
});
}
Expand Down
2 changes: 1 addition & 1 deletion lib/version.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
var version = require('../package.json').version || 'development';
module.exports = 'v' + version;
module.exports = version === 'development' ? version + ' version' : 'v' + version;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"dependencies": {
"chokidar": "^1.0.5",
"debug": "^2.2.0",
"lodash.defaults": "^3.1.2",
"minimatch": "~0.3.0",
"ps-tree": "~0.0.3",
"touch": "~1.0.0",
Expand Down
12 changes: 6 additions & 6 deletions test/monitor/ignore.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ var assert = require('assert'),

function ignore(rule, done, file) {
var p = run((rule ? ('-i ' + rule + ' ') : '') + appjs, {
// output: function (data) {
// console.log(data.trim());
// },
output: function (data) {
// console.log(data.trim());
},
error: function (data) {
p.send('quit');
cleanup(p, done, new Error(data));
}
},
});

p.on('message', function (event) {
Expand Down Expand Up @@ -54,8 +54,8 @@ function ignore(rule, done, file) {

describe('nodemon ignore', function () {
after(function (done) {
files.forEach(function(file) {
fs.unlink(file, function() {});
files.forEach(function (file) {
fs.unlink(file, function () {});
});
done();
});
Expand Down

0 comments on commit f7a9476

Please sign in to comment.