mirror of
https://github.com/flynx/colors.js.git
synced 2025-11-04 14:00:11 +00:00
Merge pull request #203 from jpap/settheme-webpack-warning
Remove setTheme dynamic require(...) that is problematic with webpack
This commit is contained in:
commit
5c84a86797
@ -60,7 +60,11 @@ console.log("this is an input".input);
|
|||||||
console.log('Generic logging theme as file'.green.bold.underline);
|
console.log('Generic logging theme as file'.green.bold.underline);
|
||||||
|
|
||||||
// Load a theme from file
|
// 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
|
// outputs red text
|
||||||
console.log("this is an error".error);
|
console.log("this is an error".error);
|
||||||
|
|||||||
@ -115,7 +115,14 @@ function applyStyle() {
|
|||||||
return str;
|
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) {
|
for (var style in theme) {
|
||||||
(function(style){
|
(function(style){
|
||||||
colors[style] = function(str){
|
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() {
|
function init() {
|
||||||
var ret = {};
|
var ret = {};
|
||||||
Object.keys(styles).forEach(function (name) {
|
Object.keys(styles).forEach(function (name) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user