Update colors.js

Setting a theme using a dynamic require is bad practice and causes lots of problems.  In case anyone is using that "feature," though, we return a warning that very explicitly tells them the (very simple) change they need to make to their code.
This commit is contained in:
DABH 2018-02-16 14:32:59 -08:00 committed by GitHub
parent c018e0b1fb
commit 0da00b2e32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -116,6 +116,13 @@ function applyStyle() {
}
colors.setTheme = function (theme) {
if (typeof theme === 'string') {
console.log('colors.setTheme now only accepts an object, not a string. ' +
'If you are trying to set a theme from a file, it is now your (the caller\'s) responsibility to require the file. ' +
'The old syntax looked like colors.setTheme(__dirname + \'/../themes/generic-logging.js\'); ' +
'The new syntax looks like colors.setTheme(require(__dirname + \'/../themes/generic-logging.js\'));');
return;
}
for (var style in theme) {
(function(style){
colors[style] = function(str){
@ -169,4 +176,4 @@ for (var map in colors.maps) {
})(map)
}
defineProps(colors, init());
defineProps(colors, init());