From c018e0b1fbe87af8fa1bcde0d901a36e3d5f26a0 Mon Sep 17 00:00:00 2001 From: John Papandriopoulos Date: Fri, 29 Sep 2017 15:49:30 -0700 Subject: [PATCH] Remove setTheme dynamic require(...) that is problematic with webpack --- examples/normal-usage.js | 6 +++++- lib/colors.js | 17 +---------------- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/examples/normal-usage.js b/examples/normal-usage.js index 2818741..3ceabd0 100644 --- a/examples/normal-usage.js +++ b/examples/normal-usage.js @@ -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); diff --git a/lib/colors.js b/lib/colors.js index 790ffd4..96ed4a7 100644 --- a/lib/colors.js +++ b/lib/colors.js @@ -115,7 +115,7 @@ function applyStyle() { return str; } -function applyTheme (theme) { +colors.setTheme = function (theme) { for (var style in theme) { (function(style){ colors[style] = function(str){ @@ -132,21 +132,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) {