Merge pull request #203 from jpap/settheme-webpack-warning

Remove setTheme dynamic require(...) that is problematic with webpack
This commit is contained in:
DABH 2018-02-16 14:38:45 -08:00 committed by GitHub
commit 5c84a86797
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 17 deletions

View File

@ -60,7 +60,11 @@ console.log("this is an input".input);
console.log('Generic logging theme as file'.green.bold.underline);
// Load a theme from file
colors.setTheme(__dirname + '/../themes/generic-logging.js');
try {
colors.setTheme(require(__dirname + '/../themes/generic-logging.js'));
} catch (err) {
console.log(err);
}
// outputs red text
console.log("this is an error".error);

View File

@ -115,7 +115,14 @@ function applyStyle() {
return str;
}
function applyTheme (theme) {
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){
@ -132,21 +139,6 @@ function applyTheme (theme) {
}
}
colors.setTheme = function (theme) {
if (typeof theme === 'string') {
try {
colors.themes[theme] = require(theme);
applyTheme(colors.themes[theme]);
return colors.themes[theme];
} catch (err) {
console.log(err);
return err;
}
} else {
applyTheme(theme);
}
};
function init() {
var ret = {};
Object.keys(styles).forEach(function (name) {