11'use strict' ;
22
33const plugin_manager = function ( ) {
4- const path = require ( 'path' ) ;
54 const logger = require ( './log' ) ;
65
7- const pluginMatcher = / ^ p l u g i n - ( .* ) $ / ;
8-
9- /**
10- * Loads a plugin
11- *
12- * @param modulePath {string} the path to the plugin
13- * @return {object } the loaded plugin
14- */
15- function loadPlugin ( modulePath ) {
16- return require ( modulePath ) ;
17- }
18-
19- /**
20- * Given a path: return the plugin name if the path points to a valid plugin
21- * module directory, or false if it doesn't.
22- * @param filePath
23- * @returns Plugin name if exists or FALSE
24- */
25- function isPlugin ( filePath ) {
26- const baseName = path . basename ( filePath ) ;
27- const pluginMatch = baseName . match ( pluginMatcher ) ;
28-
29- if ( pluginMatch ) {
30- return pluginMatch [ 1 ] ;
31- }
32- return false ;
33- }
34-
356 /**
367 * Looks for installed plugins, loads them, and invokes them
378 * @param {object } patternlab
@@ -41,7 +12,7 @@ const plugin_manager = function() {
4112 foundPlugins . forEach ( plugin => {
4213 logger . info ( `Found plugin: ${ plugin } ` ) ;
4314 logger . info ( `Attempting to load and initialize plugin.` ) ;
44- const pluginModule = loadPlugin ( plugin ) ;
15+ const pluginModule = require ( plugin ) ;
4516 pluginModule ( patternlab ) ;
4617 } ) ;
4718 }
@@ -61,12 +32,6 @@ const plugin_manager = function() {
6132 intialize_plugins : patternlab => {
6233 initializePlugins ( patternlab ) ;
6334 } ,
64- load_plugin : modulePath => {
65- return loadPlugin ( modulePath ) ;
66- } ,
67- is_plugin : filePath => {
68- return isPlugin ( filePath ) ;
69- } ,
7035 raiseEvent : async ( patternlab , eventName , ...args ) => {
7136 await raiseEvent ( patternlab , eventName , args ) ;
7237 } ,
0 commit comments