Skip to content

Commit

Permalink
feat: support SIGHUP to restart nodemon
Browse files Browse the repository at this point in the history
Also small linting tweaks and typos in comments.

Fixes #393
  • Loading branch information
remy committed Dec 15, 2017
1 parent a282afb commit 30f999a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 51 deletions.
19 changes: 0 additions & 19 deletions Dockerfile

This file was deleted.

1 change: 1 addition & 0 deletions lib/config/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = {
stdin: true,
runOnChangeOnly: false,
verbose: false,
signal: 'SIGUSR2',
// 'stdout' refers to the default behaviour of a required nodemon's child,
// but also includes stderr. If this is false, data is still dispatched via
// nodemon.on('stdout/stderr')
Expand Down
3 changes: 1 addition & 2 deletions lib/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ var config = {
dirs: [],
timeout: 1000,
options: {},
signal: 'SIGUSR2',
};

/**
Expand Down Expand Up @@ -59,7 +58,7 @@ config.load = function (settings, ready) {
}

config.watchInterval = options.watchInterval || null;
if (options['signal']) { // jshint ignore:line
if (options.signal) {
config.signal = options.signal;
}

Expand Down
60 changes: 32 additions & 28 deletions lib/nodemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,23 @@ function nodemon(settings) {
config.options.restartable + '`');
}

var none = function (v) {
return v;
};
if (!config.required) {
const restartSignal = config.options.signal === 'SIGUSR2' ? 'SIGHUP' : 'SIGUSR2';
process.on(restartSignal, nodemon.restart);
utils.log.detail((config.options.restartable ? 'or ' : '') + 'send ' +
restartSignal + ' to ' + process.pid + ' to restart');
}

utils.log.detail('ignoring: ' + config.options.monitor.map(function (rule) {
return rule.slice(0, 1) === '!' ? rule.slice(1) : false;
}).filter(none).join(' '));
}).filter(Boolean).join(' '));

utils.log.info('watching: ' + config.options.monitor.map(function (rule) {
return rule.slice(0, 1) !== '!' ? rule : false;
}).filter(none).join(' '));
}).filter(Boolean).join(' '));

utils.log.detail('watching extensions: ' + config.options.execOptions.ext);


if (config.options.dump) {
utils.log._log('log', '--------------');
utils.log._log('log', 'node: ' + process.version);
Expand All @@ -164,33 +166,35 @@ function nodemon(settings) {
process.exit();
}

} else {
config.run = true;
return;
}

if (config.options.stdout === false) {
nodemon.on('start', function () {
nodemon.stdout = bus.stdout;
nodemon.stderr = bus.stderr;
config.run = true;

bus.emit('readable');
});
}
if (config.options.stdout === false) {
nodemon.on('start', function () {
nodemon.stdout = bus.stdout;
nodemon.stderr = bus.stderr;

if (config.options.events && Object.keys(config.options.events).length) {
Object.keys(config.options.events).forEach(function (key) {
utils.log.detail('bind ' + key + ' -> `' +
config.options.events[key] + '`');
nodemon.on(key, function () {
if (config.options && config.options.events) {
spawn(config.options.events[key], config,
[].slice.apply(arguments));
}
});
});
}
bus.emit('readable');
});
}

monitor.run(config.options);
if (config.options.events && Object.keys(config.options.events).length) {
Object.keys(config.options.events).forEach(function (key) {
utils.log.detail('bind ' + key + ' -> `' +
config.options.events[key] + '`');
nodemon.on(key, function () {
if (config.options && config.options.events) {
spawn(config.options.events[key], config,
[].slice.apply(arguments));
}
});
});
}

monitor.run(config.options);

});

return nodemon;
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var reAsterisk = /\*/g;
module.exports = add;

/**
* Coverts file patterns or regular expressions to nodemon
* Converts file patterns or regular expressions to nodemon
* compatible RegExp matching rules. Note: the `rules` argument
* object is modified to include the new rule and new RegExp
*
Expand Down Expand Up @@ -86,4 +86,4 @@ function add(rules, which, rule) {
// used for the directory matching
rules[which].re = new RegExp(re);
}
}
}

0 comments on commit 30f999a

Please # to comment.