Skip to content

Commit

Permalink
Merge 94de185 into 7050836
Browse files Browse the repository at this point in the history
  • Loading branch information
ringods committed Aug 19, 2020
2 parents 7050836 + 94de185 commit b834bdc
Showing 1 changed file with 1 addition and 36 deletions.
37 changes: 1 addition & 36 deletions packages/core/src/lib/plugin_manager.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,8 @@
'use strict';

const plugin_manager = function() {
const path = require('path');
const logger = require('./log');

const pluginMatcher = /^plugin-(.*)$/;

/**
* Loads a plugin
*
* @param modulePath {string} the path to the plugin
* @return {object} the loaded plugin
*/
function loadPlugin(modulePath) {
return require(modulePath);
}

/**
* Given a path: return the plugin name if the path points to a valid plugin
* module directory, or false if it doesn't.
* @param filePath
* @returns Plugin name if exists or FALSE
*/
function isPlugin(filePath) {
const baseName = path.basename(filePath);
const pluginMatch = baseName.match(pluginMatcher);

if (pluginMatch) {
return pluginMatch[1];
}
return false;
}

/**
* Looks for installed plugins, loads them, and invokes them
* @param {object} patternlab
Expand All @@ -41,7 +12,7 @@ const plugin_manager = function() {
foundPlugins.forEach(plugin => {
logger.info(`Found plugin: ${plugin}`);
logger.info(`Attempting to load and initialize plugin.`);
const pluginModule = loadPlugin(plugin);
const pluginModule = require(plugin);
pluginModule(patternlab);
});
}
Expand All @@ -61,12 +32,6 @@ const plugin_manager = function() {
intialize_plugins: patternlab => {
initializePlugins(patternlab);
},
load_plugin: modulePath => {
return loadPlugin(modulePath);
},
is_plugin: filePath => {
return isPlugin(filePath);
},
raiseEvent: async (patternlab, eventName, ...args) => {
await raiseEvent(patternlab, eventName, args);
},
Expand Down

0 comments on commit b834bdc

Please sign in to comment.