Skip to content

Commit 0b17382

Browse files
committed
made some small improvements to plugin loading - which will move us toward a better state
1 parent f0fe98b commit 0b17382

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

core/lib/patternlab.js

+2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ function checkConfiguration(patternlab) {
9999
* Finds and calls the main method of any found plugins.
100100
* @param patternlab - global data store
101101
*/
102+
103+
//todo, move this to plugin_manager
102104
function initializePlugins(patternlab) {
103105

104106
if (!patternlab.config.plugins) { return; }

core/lib/plugin_manager.js

+19-4
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,25 @@ var plugin_manager = function (config, configPath) {
4242
if (!diskConfig.plugins) {
4343
diskConfig.plugins = {};
4444
}
45-
diskConfig.plugins[pluginName] = {
46-
enabled: true,
47-
initialized: false
48-
};
45+
46+
if (!diskConfig.plugins[pluginName]) {
47+
diskConfig.plugins[pluginName] = {
48+
enabled: true,
49+
initialized: false,
50+
options: {}
51+
};
52+
}
53+
54+
const pluginPathConfig = path.resolve(pluginPath, 'config.json');
55+
try {
56+
var pluginConfigJSON = require(pluginPathConfig);
57+
if (!diskConfig.plugins[pluginName].options) {
58+
59+
diskConfig.plugins[pluginName].options = pluginConfigJSON;
60+
}
61+
} catch (ex) {
62+
//a config.json file is not required at this time
63+
}
4964

5065
//write config entry back
5166
fs.outputFileSync(path.resolve(configPath), JSON.stringify(diskConfig, null, 2));

0 commit comments

Comments
 (0)