mirror of
https://github.com/SrIzan10/nodemon.git
synced 2026-05-01 10:55:09 +00:00
* chore: bump chokidar to latest * test: fix weird output on restart filename * test: skip old broken test * fix: node_modules watched off relative path Fixes #1294 Fixes #1305 (though couldn't confirm - just looks very similar) I've gone back and forth on this Chokidar option `cwd` and in this fix I've removed it from the config. I've checked the issues that were raised that caused me to add the option, and they still appear to pass in the tests, so I believe it's okay. However, it _might_ come back in - just a note for Future @remy.
83 lines
1.7 KiB
JavaScript
83 lines
1.7 KiB
JavaScript
var colour = require('./colour');
|
|
var bus = require('./bus');
|
|
var required = false;
|
|
var useColours = true;
|
|
|
|
var coding = {
|
|
log: 'black',
|
|
info: 'yellow',
|
|
status: 'green',
|
|
detail: 'yellow',
|
|
fail: 'red',
|
|
error: 'red',
|
|
};
|
|
|
|
function log(type, text) {
|
|
var msg = '[nodemon] ' + (text || '');
|
|
|
|
if (useColours) {
|
|
msg = colour(coding[type], msg);
|
|
}
|
|
|
|
// always push the message through our bus, using nextTick
|
|
// to help testing and get _out of_ promises.
|
|
process.nextTick(() => {
|
|
bus.emit('log', { type: type, message: text, colour: msg });
|
|
});
|
|
|
|
// but if we're running on the command line, also echo out
|
|
// question: should we actually just consume our own events?
|
|
if (!required) {
|
|
if (type === 'error') {
|
|
console.error(msg);
|
|
} else {
|
|
console.log(msg || '');
|
|
}
|
|
}
|
|
}
|
|
|
|
var Logger = function (r) {
|
|
if (!(this instanceof Logger)) {
|
|
return new Logger(r);
|
|
}
|
|
this.required(r);
|
|
return this;
|
|
};
|
|
|
|
Object.keys(coding).forEach(function (type) {
|
|
Logger.prototype[type] = log.bind(null, type);
|
|
});
|
|
|
|
// detail is for messages that are turned on during debug
|
|
Logger.prototype.detail = function (msg) {
|
|
if (this.debug) {
|
|
log('detail', msg);
|
|
}
|
|
};
|
|
|
|
Logger.prototype.required = function (val) {
|
|
required = val;
|
|
};
|
|
|
|
Logger.prototype.debug = false;
|
|
Logger.prototype._log = function (type, msg) {
|
|
if (required) {
|
|
bus.emit('log', { type: type, message: msg || '', colour: msg || '' });
|
|
} else if (type === 'error') {
|
|
console.error(msg);
|
|
} else {
|
|
console.log(msg || '');
|
|
}
|
|
};
|
|
|
|
Object.defineProperty(Logger.prototype, 'useColours', {
|
|
set: function (val) {
|
|
useColours = val;
|
|
},
|
|
get: function () {
|
|
return useColours;
|
|
},
|
|
});
|
|
|
|
module.exports = Logger;
|