From 4c3c2905f8aaa186f84bfdfb4d79d04dce7de7d3 Mon Sep 17 00:00:00 2001 From: BRIAN MUENZENMEYER Date: Thu, 8 Sep 2016 00:29:38 -0500 Subject: [PATCH] WIP loading plugin as part of #432 --- core/lib/patternlab.js | 27 +++++++++++++++++++++------ core/lib/plugin_manager.js | 2 +- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/core/lib/patternlab.js b/core/lib/patternlab.js index 99accaa15..2a3a82f0b 100644 --- a/core/lib/patternlab.js +++ b/core/lib/patternlab.js @@ -1,10 +1,10 @@ -/* - * patternlab-node - v2.4.4 - 2016 - * +/* + * patternlab-node - v2.4.4 - 2016 + * * Brian Muenzenmeyer, Geoff Pursell, and the web community. - * Licensed under the MIT license. - * - * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. + * Licensed under the MIT license. + * + * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. * */ @@ -84,12 +84,14 @@ var patternlab_engine = function (config) { lh = require('./lineage_hunter'), ui = require('./ui_builder'), sm = require('./starterkit_manager'), + pm = require('./plugin_manager'), patternlab = {}; patternlab.package = fs.readJSONSync(path.resolve(__dirname, '../../package.json')); patternlab.config = config || fs.readJSONSync(path.resolve(__dirname, '../../patternlab-config.json')); checkConfiguration(patternlab); + initializePlugins(patternlab); var paths = patternlab.config.paths; @@ -170,6 +172,19 @@ var patternlab_engine = function (config) { } } + function initializePlugins(patternlab) { + var plugin_manager = new pm(patternlab.config, path.resolve(__dirname, '../../patternlab-config.json')); + var foundPlugins = plugin_manager.detect_plugins(); + + if (foundPlugins && foundPlugins.length > 0) { + + for (var i = 0; i < foundPlugins.length; i++) { + var plugin = plugin_manager.load_plugin(foundPlugins[i]); + plugin(patternlab); + } + } + } + function setCacheBust() { if (patternlab.config.cacheBust) { if (patternlab.config.debug) { diff --git a/core/lib/plugin_manager.js b/core/lib/plugin_manager.js index 05f0defe3..3e26b98ba 100644 --- a/core/lib/plugin_manager.js +++ b/core/lib/plugin_manager.js @@ -59,7 +59,7 @@ var plugin_manager = function (config, configPath) { installPlugin(pluginName); }, load_plugin: function (pluginName) { - loadPlugin(pluginName); + return loadPlugin(pluginName); }, detect_plugins: function () { return detectPlugins();