node-pluginsmanager 2.3.2 → 2.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -93,17 +93,23 @@ interface iPluginManagerOptions {
93
93
 
94
94
  * ``` on("error", (err: Error) => void) : this ``` fires if an error occurs
95
95
 
96
- * ``` on("initialized", (plugin: [Orchestrator](https://github.com/Psychopoulet/node-pluginsmanager-plugin#orchestrator-extends-mediatoruser)) => void) : this ``` fires if a plugin is initialized
97
- * ``` on("allinitialized", () => void) : this ``` fires if all the plugins are initialized
96
+ * ``` on("loading", (plugin: [Orchestrator](https://github.com/Psychopoulet/node-pluginsmanager-plugin#orchestrator-extends-mediatoruser), data?: any) => void) : this ``` fires if a plugin starts load
97
+ * ``` on("loaded", (plugin: [Orchestrator](https://github.com/Psychopoulet/node-pluginsmanager-plugin#orchestrator-extends-mediatoruser), data?: any) => void) : this ``` fires if a plugin ends load
98
+ * ``` on("allloaded", (data?: any) => void) : this ``` fires if all the plugins are loaded
98
99
 
99
- * ``` on("released", (pluginName: string) => void) : this ``` fires if a plugin is released
100
- * ``` on("allreleased", (plugin: [Orchestrator](https://github.com/Psychopoulet/node-pluginsmanager-plugin#orchestrator-extends-mediatoruser)) => void) : this ``` fires if all the plugins are released
101
- * ``` on("destroyed", (pluginName: string) => void) : this ``` fires if a plugin is destroyed
102
- * ``` on("alldestroyed", (plugin: [Orchestrator](https://github.com/Psychopoulet/node-pluginsmanager-plugin#orchestrator-extends-mediatoruser)) => void) : this ``` fires if all the plugins are destroyed
100
+ * ``` on("initializing", (plugin: [Orchestrator](https://github.com/Psychopoulet/node-pluginsmanager-plugin#orchestrator-extends-mediatoruser), data?: any) => void) : this ``` fires if a plugin starts init
101
+ * ``` on("initialized", (plugin: [Orchestrator](https://github.com/Psychopoulet/node-pluginsmanager-plugin#orchestrator-extends-mediatoruser), data?: any) => void) : this ``` fires if a plugin ends init
102
+ * ``` on("allinitialized", (data?: any) => void) : this ``` fires if all the plugins are initialized
103
103
 
104
- * ``` on("installed", (plugin: [Orchestrator](https://github.com/Psychopoulet/node-pluginsmanager-plugin#orchestrator-extends-mediatoruser)) => void) : this ``` fires if a plugin is installed
105
- * ``` on("updated", (plugin: [Orchestrator](https://github.com/Psychopoulet/node-pluginsmanager-plugin#orchestrator-extends-mediatoruser)) => void) : this ``` fires if a plugin is updated
106
- * ``` on("uninstalled", (pluginName: string) => void) : this ``` fires if a plugin is uninstalled
104
+ * ``` on("released", (plugin: [Orchestrator](https://github.com/Psychopoulet/node-pluginsmanager-plugin#orchestrator-extends-mediatoruser), data?: any) => void) : this ``` fires if a plugin is released
105
+ * ``` on("allreleased", (data?: any) => void) : this ``` fires if all the plugins are released
106
+
107
+ * ``` on("destroyed", (pluginName: string, data?: any) => void) : this ``` fires if a plugin is destroyed
108
+ * ``` on("alldestroyed", (data?: any) => void) : this ``` fires if all the plugins are destroyed
109
+
110
+ * ``` on("installed", (pluginName: string, data?: any) => void) : this ``` fires if a plugin is installed
111
+ * ``` on("updated", (plugin: [Orchestrator](https://github.com/Psychopoulet/node-pluginsmanager-plugin#orchestrator-extends-mediatoruser), data?: any) => void) : this ``` fires if a plugin is updated
112
+ * ``` on("uninstalled", (pluginName: string, data?: any) => void) : this ``` fires if a plugin is uninstalled
107
113
 
108
114
  ## Examples
109
115
 
@@ -126,9 +132,22 @@ manager
126
132
  console.log("--- [event/error] '" + msg.error + "' ---");
127
133
  })
128
134
 
135
+ // load
136
+
137
+ .on("loading", (pluginName) => {
138
+ console.log("--- [event/loading] '" + pluginName + "' loading ---");
139
+ }).on("loaded", (plugin) => {
140
+ console.log("--- [event/loaded] '" + plugin.name + "' (v" + plugin.version + ") loaded ---");
141
+ })
142
+ .on("allloaded", () => {
143
+ console.log("--- [event/allloaded] all plugins allloaded ---");
144
+ })
145
+
129
146
  // init
130
147
 
131
- .on("initialized", (plugin) => {
148
+ .on("initializing", (plugin) => {
149
+ console.log("--- [event/initializing] '" + plugin.name + "' (v" + plugin.version + ") initialized ---");
150
+ }).on("initialized", (plugin) => {
132
151
  console.log("--- [event/initialized] '" + plugin.name + "' (v" + plugin.version + ") initialized ---");
133
152
  })
134
153
  .on("allinitialized", () => {
@@ -143,6 +162,9 @@ manager
143
162
  .on("allreleased", () => {
144
163
  console.log("--- [event/released] all plugins released ---");
145
164
  })
165
+
166
+ // destroy
167
+
146
168
  .on("destroyed", (pluginName) => {
147
169
  console.log("--- [event/destroyed] '" + pluginName + " destroyed ---");
148
170
  })
@@ -1,9 +1,9 @@
1
- /*
2
- eslint max-params: 0
3
- */
4
-
5
1
  "use strict";
6
2
 
3
+ // consts
4
+
5
+ const MAX_PARALLEL = 5;
6
+
7
7
  // private
8
8
 
9
9
  // methods
@@ -17,6 +17,8 @@
17
17
  */
18
18
  function _initPlugin (plugin, emit, data) {
19
19
 
20
+ emit("initializing", plugin, data);
21
+
20
22
  return plugin.init(data).then(() => {
21
23
 
22
24
  emit("initialized", plugin, data);
@@ -29,22 +31,44 @@
29
31
 
30
32
  /**
31
33
  * Load plugins with sort conditions
32
- * @param {object} toLoad : plugins to init
34
+ * @param {object} pluginsToInit : plugins to init
33
35
  * @param {function} emit : emit data function
34
36
  * @param {object} data : data to send
35
37
  * @param {number} i : stepper
36
38
  * @return {Promise} : result operation
37
39
  */
38
- function _initSortedPlugins (toLoad, emit, data, i = 0) {
40
+ function _initSortedPlugins (pluginsToInit, emit, data, i = 0) {
39
41
 
40
- return i < toLoad.length ? Promise.resolve().then(() => {
42
+ return i < pluginsToInit.length ? Promise.resolve().then(() => {
41
43
 
42
- return _initPlugin(toLoad[i], emit, data);
44
+ return _initPlugin(pluginsToInit[i], emit, data);
43
45
 
44
46
  // loop
45
47
  }).then(() => {
46
48
 
47
- return _initSortedPlugins(toLoad, emit, data, i + 1);
49
+ return _initSortedPlugins(pluginsToInit, emit, data, i + 1);
50
+
51
+ }) : Promise.resolve();
52
+
53
+ }
54
+
55
+ /**
56
+ * Load plugins without sort conditions
57
+ * @param {object} pluginsToInit : plugins to init
58
+ * @param {function} emit : emit data function
59
+ * @param {object} data : data to send
60
+ * @return {Promise} : result operation
61
+ */
62
+ function _initUnSortedPlugins (pluginsToInit, emit, data) {
63
+
64
+ return pluginsToInit.length ? Promise.all(pluginsToInit.splice(0, MAX_PARALLEL).map((p) => {
65
+
66
+ return _initPlugin(p, emit, data);
67
+
68
+ // loop
69
+ })).then(() => {
70
+
71
+ return _initUnSortedPlugins(pluginsToInit, emit, data);
48
72
 
49
73
  }) : Promise.resolve();
50
74
 
@@ -52,30 +76,34 @@
52
76
 
53
77
  // module
54
78
 
55
- module.exports = (plugins, orderedPluginsNames, emit, data) => {
79
+ module.exports = function initSortedPlugins (plugins, orderedPluginsNames, emit, data) {
56
80
 
57
81
  // if no plugins, does not run
58
82
  return !plugins.length ? Promise.resolve() : Promise.resolve().then(() => {
59
83
 
60
- // first, sorted plugins
61
- return _initSortedPlugins(orderedPluginsNames.map((pluginName) => {
84
+ const sortedPlugins = [
85
+ ...plugins.filter((plugin) => {
86
+ return orderedPluginsNames.includes(plugin.name);
87
+ })
88
+ ];
62
89
 
63
- return plugins.find((plugin) => {
64
- return plugin.name === pluginName;
65
- });
66
-
67
- }), emit, data);
90
+ // first, sorted plugins
91
+ return sortedPlugins.length ?
92
+ _initSortedPlugins(sortedPlugins, emit, data) :
93
+ Promise.resolve();
68
94
 
69
95
  }).then(() => {
70
96
 
71
- // then, all other plugins, asynchronously
72
- return Promise.all(plugins.filter((plugin) => {
73
- return !orderedPluginsNames.includes(plugin.name);
74
- }).map((plugin) => {
75
-
76
- return _initPlugin(plugin, emit, data);
97
+ const unsortedPlugin = [
98
+ ...plugins.filter((plugin) => {
99
+ return !orderedPluginsNames.includes(plugin.name);
100
+ })
101
+ ];
77
102
 
78
- }));
103
+ // then, all other plugins, asynchronously
104
+ return unsortedPlugin.length ?
105
+ _initUnSortedPlugins(unsortedPlugin, emit, data) :
106
+ Promise.resolve();
79
107
 
80
108
  });
81
109
 
@@ -12,6 +12,10 @@
12
12
  // locals
13
13
  const createPluginByDirectory = require(join(__dirname, "createPluginByDirectory.js"));
14
14
 
15
+ // consts
16
+
17
+ const MAX_PARALLEL = 5;
18
+
15
19
  // private
16
20
 
17
21
  // methods
@@ -20,24 +24,26 @@
20
24
  * Load plugins with sort conditions
21
25
  * @param {string} globalDirectory : get plugins directory
22
26
  * @param {string} externalRessourcesDirectory : get ressources directory
23
- * @param {string} pluginName : get ressources directory
24
- * @param {object} plugins : already loaded plugins
27
+ * @param {string} pluginFileName : get ressources directory
28
+ * @param {object} loadedPlugins : already loaded plugins
25
29
  * @param {function} emit : emit data function
26
30
  * @param {function|null} logger : if logger, send it to plugin
27
31
  * @param {object} data : data to send
28
32
  * @return {Promise} : result operation
29
33
  */
30
- function _loadPlugin (globalDirectory, externalRessourcesDirectory, pluginName, plugins, emit, logger, data) {
34
+ function _loadPlugin (globalDirectory, externalRessourcesDirectory, pluginFileName, loadedPlugins, emit, logger, data) {
31
35
 
32
36
  // is already loaded ?
33
- const plugin = plugins.find((p) => {
34
- return pluginName === p.name;
37
+ const plugin = loadedPlugins.find((p) => {
38
+ return pluginFileName === p.name;
35
39
  });
36
40
 
37
41
  // is already exists ?
38
42
  return plugin ? Promise.resolve() : Promise.resolve().then(() => {
39
43
 
40
- const directory = join(globalDirectory, pluginName);
44
+ emit("loading", pluginFileName, data);
45
+
46
+ const directory = join(globalDirectory, pluginFileName);
41
47
 
42
48
  return createPluginByDirectory(directory, externalRessourcesDirectory, logger, data);
43
49
 
@@ -45,7 +51,7 @@
45
51
  }).then((createdPlugin) => {
46
52
 
47
53
  emit("loaded", createdPlugin, data);
48
- plugins.push(createdPlugin);
54
+ loadedPlugins.push(createdPlugin);
49
55
 
50
56
  return Promise.resolve();
51
57
 
@@ -57,24 +63,50 @@
57
63
  * Load plugins with sort conditions
58
64
  * @param {string} globalDirectory : get plugins directory
59
65
  * @param {string} externalRessourcesDirectory : get ressources directory
60
- * @param {Array} toLoad : plugins to load
61
- * @param {object} plugins : already loaded plugins
66
+ * @param {Array} pluginsToLoad : plugins to load
67
+ * @param {object} loadedPlugins : already loaded plugins
62
68
  * @param {function} emit : emit data function
63
69
  * @param {function|null} logger : if logger, send it to plugin
64
70
  * @param {object} data : data to send
65
71
  * @param {number} i : stepper
66
72
  * @return {Promise} : result operation
67
73
  */
68
- function _loadSortedPlugins (globalDirectory, externalRessourcesDirectory, toLoad, plugins, emit, logger, data, i = 0) {
74
+ function _loadSortedPlugins (globalDirectory, externalRessourcesDirectory, pluginsToLoad, loadedPlugins, emit, logger, data, i = 0) {
69
75
 
70
- return i < toLoad.length ? Promise.resolve().then(() => {
76
+ return i < pluginsToLoad.length ? Promise.resolve().then(() => {
71
77
 
72
- return _loadPlugin(globalDirectory, externalRessourcesDirectory, toLoad[i], plugins, emit, logger, data);
78
+ return _loadPlugin(globalDirectory, externalRessourcesDirectory, pluginsToLoad[i], loadedPlugins, emit, logger, data);
73
79
 
74
80
  // loop
75
81
  }).then(() => {
76
82
 
77
- return _loadSortedPlugins(globalDirectory, externalRessourcesDirectory, toLoad, plugins, emit, logger, data, i + 1);
83
+ return _loadSortedPlugins(globalDirectory, externalRessourcesDirectory, pluginsToLoad, loadedPlugins, emit, logger, data, i + 1);
84
+
85
+ }) : Promise.resolve();
86
+
87
+ }
88
+
89
+ /**
90
+ * Load plugins without sort conditions
91
+ * @param {string} globalDirectory : get plugins directory
92
+ * @param {string} externalRessourcesDirectory : get ressources directory
93
+ * @param {Array} pluginsToLoad : plugins to load
94
+ * @param {object} loadedPlugins : already loaded plugins
95
+ * @param {function} emit : emit data function
96
+ * @param {function|null} logger : if logger, send it to plugin
97
+ * @param {object} data : data to send
98
+ * @return {Promise} : result operation
99
+ */
100
+ function _loadUnSortedPlugins (globalDirectory, externalRessourcesDirectory, pluginsToLoad, loadedPlugins, emit, logger, data) {
101
+
102
+ return pluginsToLoad.length ? Promise.all(pluginsToLoad.splice(0, MAX_PARALLEL).map((p) => {
103
+
104
+ return _loadPlugin(globalDirectory, externalRessourcesDirectory, p, loadedPlugins, emit, logger, data);
105
+
106
+ // loop
107
+ })).then(() => {
108
+
109
+ return _loadUnSortedPlugins(globalDirectory, externalRessourcesDirectory, pluginsToLoad, loadedPlugins, emit, logger, data);
78
110
 
79
111
  }) : Promise.resolve();
80
112
 
@@ -82,24 +114,36 @@
82
114
 
83
115
  // module
84
116
 
85
- module.exports = (globalDirectory, externalRessourcesDirectory, files, plugins, orderedPluginsNames, emit, logger, data) => {
117
+ module.exports = function loadSortedPlugins (
118
+ globalDirectory, externalRessourcesDirectory, files, loadedPlugins, orderedPluginsNames, emit, logger, data
119
+ ) {
86
120
 
87
121
  // if no files, does not run
88
122
  return !files.length ? Promise.resolve() : Promise.resolve().then(() => {
89
123
 
124
+ const sortedPluginsNames = [
125
+ ...files.filter((pluginName) => {
126
+ return orderedPluginsNames.includes(pluginName);
127
+ })
128
+ ];
129
+
90
130
  // first, sorted plugins
91
- return _loadSortedPlugins(globalDirectory, externalRessourcesDirectory, orderedPluginsNames, plugins, emit, logger, data);
131
+ return sortedPluginsNames.length ?
132
+ _loadSortedPlugins(globalDirectory, externalRessourcesDirectory, sortedPluginsNames, loadedPlugins, emit, logger, data) :
133
+ Promise.resolve();
92
134
 
93
135
  }).then(() => {
94
136
 
95
- // then, all other plugins, asynchronously
96
- return Promise.all(files.filter((pluginName) => {
97
- return !orderedPluginsNames.includes(pluginName);
98
- }).map((file) => {
99
-
100
- return _loadPlugin(globalDirectory, externalRessourcesDirectory, file, plugins, emit, logger, data);
137
+ const unsortedPluginsNames = [
138
+ ...files.filter((pluginName) => {
139
+ return !orderedPluginsNames.includes(pluginName);
140
+ })
141
+ ];
101
142
 
102
- }));
143
+ // then, all other plugins, asynchronously
144
+ return unsortedPluginsNames.length ?
145
+ _loadUnSortedPlugins(globalDirectory, externalRessourcesDirectory, unsortedPluginsNames, loadedPlugins, emit, logger, data) :
146
+ Promise.resolve();
103
147
 
104
148
  });
105
149
 
package/lib/main.js CHANGED
@@ -77,7 +77,7 @@ module.exports = class PluginsManager extends Events {
77
77
 
78
78
  getPluginsNames () {
79
79
 
80
- return this.plugins.map((plugin) => {
80
+ return [ ...this.plugins ].map((plugin) => {
81
81
  return plugin.name;
82
82
  });
83
83
 
@@ -118,6 +118,12 @@ module.exports = class PluginsManager extends Events {
118
118
 
119
119
  }
120
120
 
121
+ getOrder () {
122
+
123
+ return [ ...this._orderedPluginsNames ];
124
+
125
+ }
126
+
121
127
  // checkers
122
128
 
123
129
  checkAllModules () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-pluginsmanager",
3
- "version": "2.3.2",
3
+ "version": "2.3.6",
4
4
  "description": "A plugins manager",
5
5
  "main": "lib/main.js",
6
6
  "typings": "lib/index.d.ts",
@@ -35,25 +35,25 @@
35
35
  "url": "https://github.com/Psychopoulet/node-pluginsmanager/issues"
36
36
  },
37
37
  "dependencies": {
38
- "check-version-modules": "1.3.2",
38
+ "check-version-modules": "1.3.5",
39
39
  "node-promfs": "3.7.0"
40
40
  },
41
41
  "devDependencies": {
42
- "@types/node": "15.12.2",
42
+ "@types/node": "16.11.10",
43
43
  "@types/socket.io": "3.0.2",
44
- "@types/ws": "7.4.5",
45
- "coveralls": "3.1.0",
46
- "eslint": "7.28.0",
44
+ "@types/ws": "8.2.0",
45
+ "coveralls": "3.1.1",
46
+ "eslint": "8.3.0",
47
47
  "express": "4.17.1",
48
- "husky": "6.0.0",
49
- "mocha": "9.0.0",
50
- "node-pluginsmanager-plugin": "4.4.0",
48
+ "husky": "7.0.4",
49
+ "mocha": "9.1.3",
50
+ "node-pluginsmanager-plugin": "4.7.2",
51
51
  "nyc": "15.1.0",
52
- "typescript": "4.3.3",
53
- "ws": "7.5.0"
52
+ "typescript": "4.5.2",
53
+ "ws": "8.3.0"
54
54
  },
55
55
  "homepage": "https://github.com/Psychopoulet/node-pluginsmanager#readme",
56
56
  "engines": {
57
- "node": ">=10.0.0"
57
+ "node": ">=12.0.0"
58
58
  }
59
59
  }