node-pluginsmanager 2.3.4 → 2.3.7

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.
@@ -40,7 +40,7 @@ module.exports = function gitinstall (directory, user, repo) {
40
40
  "--recursive",
41
41
  "--depth",
42
42
  "1",
43
- "git://github.com/" + user + "/" + repo + ".git",
43
+ "https://github.com/" + user + "/" + repo + "/",
44
44
  directory
45
45
  ]);
46
46
 
@@ -1,7 +1,3 @@
1
- /*
2
- eslint max-params: 0
3
- */
4
-
5
1
  "use strict";
6
2
 
7
3
  // private
@@ -31,22 +27,22 @@
31
27
 
32
28
  /**
33
29
  * Load plugins with sort conditions
34
- * @param {object} toLoad : plugins to init
30
+ * @param {object} pluginsToInit : plugins to init
35
31
  * @param {function} emit : emit data function
36
32
  * @param {object} data : data to send
37
33
  * @param {number} i : stepper
38
34
  * @return {Promise} : result operation
39
35
  */
40
- function _initSortedPlugins (toLoad, emit, data, i = 0) {
36
+ function _initPlugins (pluginsToInit, emit, data, i = 0) {
41
37
 
42
- return i < toLoad.length ? Promise.resolve().then(() => {
38
+ return i < pluginsToInit.length ? Promise.resolve().then(() => {
43
39
 
44
- return _initPlugin(toLoad[i], emit, data);
40
+ return _initPlugin(pluginsToInit[i], emit, data);
45
41
 
46
42
  // loop
47
43
  }).then(() => {
48
44
 
49
- return _initSortedPlugins(toLoad, emit, data, i + 1);
45
+ return _initPlugins(pluginsToInit, emit, data, i + 1);
50
46
 
51
47
  }) : Promise.resolve();
52
48
 
@@ -54,30 +50,46 @@
54
50
 
55
51
  // module
56
52
 
57
- module.exports = (plugins, orderedPluginsNames, emit, data) => {
53
+ module.exports = function initSortedPlugins (plugins, orderedPluginsNames, emit, data) {
58
54
 
59
55
  // if no plugins, does not run
60
56
  return !plugins.length ? Promise.resolve() : Promise.resolve().then(() => {
61
57
 
62
- // first, sorted plugins
63
- return _initSortedPlugins(orderedPluginsNames.map((pluginName) => {
64
-
65
- return plugins.find((plugin) => {
66
- return plugin.name === pluginName;
67
- });
58
+ const sortedPlugins = [
59
+ ...plugins.filter((plugin) => {
60
+ return orderedPluginsNames.includes(plugin.name);
61
+ })
62
+ ];
68
63
 
69
- }), emit, data);
64
+ // first, sorted plugins
65
+ return sortedPlugins.length ?
66
+ _initPlugins(sortedPlugins, emit, data) :
67
+ Promise.resolve();
70
68
 
71
69
  }).then(() => {
72
70
 
73
- // then, all other plugins, asynchronously
74
- return Promise.all(plugins.filter((plugin) => {
75
- return !orderedPluginsNames.includes(plugin.name);
76
- }).map((plugin) => {
71
+ const unsortedPlugin = [
72
+ ...plugins.filter((plugin) => {
73
+ return !orderedPluginsNames.includes(plugin.name);
74
+ }).sort((a, b) => {
77
75
 
78
- return _initPlugin(plugin, emit, data);
76
+ if (a < b) {
77
+ return -1;
78
+ }
79
+ else if (a > b) {
80
+ return 1;
81
+ }
82
+ else {
83
+ return 0;
84
+ }
79
85
 
80
- }));
86
+ })
87
+ ];
88
+
89
+ // then, all other plugins, asynchronously
90
+ return unsortedPlugin.length ?
91
+ _initPlugins(unsortedPlugin, emit, data) :
92
+ Promise.resolve();
81
93
 
82
94
  });
83
95
 
@@ -20,26 +20,26 @@
20
20
  * Load plugins with sort conditions
21
21
  * @param {string} globalDirectory : get plugins directory
22
22
  * @param {string} externalRessourcesDirectory : get ressources directory
23
- * @param {string} pluginName : get ressources directory
24
- * @param {object} plugins : already loaded plugins
23
+ * @param {string} pluginFileName : get ressources directory
24
+ * @param {object} loadedPlugins : already loaded plugins
25
25
  * @param {function} emit : emit data function
26
26
  * @param {function|null} logger : if logger, send it to plugin
27
27
  * @param {object} data : data to send
28
28
  * @return {Promise} : result operation
29
29
  */
30
- function _loadPlugin (globalDirectory, externalRessourcesDirectory, pluginName, plugins, emit, logger, data) {
30
+ function _loadPlugin (globalDirectory, externalRessourcesDirectory, pluginFileName, loadedPlugins, emit, logger, data) {
31
31
 
32
32
  // is already loaded ?
33
- const plugin = plugins.find((p) => {
34
- return pluginName === p.name;
33
+ const plugin = loadedPlugins.find((p) => {
34
+ return pluginFileName === p.name;
35
35
  });
36
36
 
37
37
  // is already exists ?
38
38
  return plugin ? Promise.resolve() : Promise.resolve().then(() => {
39
39
 
40
- emit("loading", pluginName, data);
40
+ emit("loading", pluginFileName, data);
41
41
 
42
- const directory = join(globalDirectory, pluginName);
42
+ const directory = join(globalDirectory, pluginFileName);
43
43
 
44
44
  return createPluginByDirectory(directory, externalRessourcesDirectory, logger, data);
45
45
 
@@ -47,7 +47,7 @@
47
47
  }).then((createdPlugin) => {
48
48
 
49
49
  emit("loaded", createdPlugin, data);
50
- plugins.push(createdPlugin);
50
+ loadedPlugins.push(createdPlugin);
51
51
 
52
52
  return Promise.resolve();
53
53
 
@@ -59,24 +59,24 @@
59
59
  * Load plugins with sort conditions
60
60
  * @param {string} globalDirectory : get plugins directory
61
61
  * @param {string} externalRessourcesDirectory : get ressources directory
62
- * @param {Array} toLoad : plugins to load
63
- * @param {object} plugins : already loaded plugins
62
+ * @param {Array} pluginsToLoad : plugins to load
63
+ * @param {object} loadedPlugins : already loaded plugins
64
64
  * @param {function} emit : emit data function
65
65
  * @param {function|null} logger : if logger, send it to plugin
66
66
  * @param {object} data : data to send
67
67
  * @param {number} i : stepper
68
68
  * @return {Promise} : result operation
69
69
  */
70
- function _loadSortedPlugins (globalDirectory, externalRessourcesDirectory, toLoad, plugins, emit, logger, data, i = 0) {
70
+ function _loadPlugins (globalDirectory, externalRessourcesDirectory, pluginsToLoad, loadedPlugins, emit, logger, data, i = 0) {
71
71
 
72
- return i < toLoad.length ? Promise.resolve().then(() => {
72
+ return i < pluginsToLoad.length ? Promise.resolve().then(() => {
73
73
 
74
- return _loadPlugin(globalDirectory, externalRessourcesDirectory, toLoad[i], plugins, emit, logger, data);
74
+ return _loadPlugin(globalDirectory, externalRessourcesDirectory, pluginsToLoad[i], loadedPlugins, emit, logger, data);
75
75
 
76
76
  // loop
77
77
  }).then(() => {
78
78
 
79
- return _loadSortedPlugins(globalDirectory, externalRessourcesDirectory, toLoad, plugins, emit, logger, data, i + 1);
79
+ return _loadPlugins(globalDirectory, externalRessourcesDirectory, pluginsToLoad, loadedPlugins, emit, logger, data, i + 1);
80
80
 
81
81
  }) : Promise.resolve();
82
82
 
@@ -84,24 +84,48 @@
84
84
 
85
85
  // module
86
86
 
87
- module.exports = (globalDirectory, externalRessourcesDirectory, files, plugins, orderedPluginsNames, emit, logger, data) => {
87
+ module.exports = function loadSortedPlugins (
88
+ globalDirectory, externalRessourcesDirectory, files, loadedPlugins, orderedPluginsNames, emit, logger, data
89
+ ) {
88
90
 
89
91
  // if no files, does not run
90
92
  return !files.length ? Promise.resolve() : Promise.resolve().then(() => {
91
93
 
94
+ const sortedPluginsNames = [
95
+ ...files.filter((pluginName) => {
96
+ return orderedPluginsNames.includes(pluginName);
97
+ })
98
+ ];
99
+
92
100
  // first, sorted plugins
93
- return _loadSortedPlugins(globalDirectory, externalRessourcesDirectory, orderedPluginsNames, plugins, emit, logger, data);
101
+ return sortedPluginsNames.length ?
102
+ _loadPlugins(globalDirectory, externalRessourcesDirectory, sortedPluginsNames, loadedPlugins, emit, logger, data) :
103
+ Promise.resolve();
94
104
 
95
105
  }).then(() => {
96
106
 
97
- // then, all other plugins, asynchronously
98
- return Promise.all(files.filter((pluginName) => {
99
- return !orderedPluginsNames.includes(pluginName);
100
- }).map((file) => {
107
+ const unsortedPluginsNames = [
108
+ ...files.filter((pluginName) => {
109
+ return !orderedPluginsNames.includes(pluginName);
110
+ }).sort((a, b) => {
101
111
 
102
- return _loadPlugin(globalDirectory, externalRessourcesDirectory, file, plugins, emit, logger, data);
112
+ if (a < b) {
113
+ return -1;
114
+ }
115
+ else if (a > b) {
116
+ return 1;
117
+ }
118
+ else {
119
+ return 0;
120
+ }
103
121
 
104
- }));
122
+ })
123
+ ];
124
+
125
+ // then, all other plugins, asynchronously
126
+ return unsortedPluginsNames.length ?
127
+ _loadPlugins(globalDirectory, externalRessourcesDirectory, unsortedPluginsNames, loadedPlugins, emit, logger, data) :
128
+ Promise.resolve();
105
129
 
106
130
  });
107
131
 
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.4",
3
+ "version": "2.3.7",
4
4
  "description": "A plugins manager",
5
5
  "main": "lib/main.js",
6
6
  "typings": "lib/index.d.ts",
@@ -39,18 +39,18 @@
39
39
  "node-promfs": "3.7.0"
40
40
  },
41
41
  "devDependencies": {
42
- "@types/node": "16.11.7",
42
+ "@types/node": "17.0.31",
43
43
  "@types/socket.io": "3.0.2",
44
- "@types/ws": "8.2.0",
44
+ "@types/ws": "8.5.3",
45
45
  "coveralls": "3.1.1",
46
- "eslint": "8.2.0",
47
- "express": "4.17.1",
48
- "husky": "7.0.4",
49
- "mocha": "9.1.3",
50
- "node-pluginsmanager-plugin": "4.7.2",
46
+ "eslint": "8.15.0",
47
+ "express": "4.18.1",
48
+ "husky": "8.0.1",
49
+ "mocha": "10.0.0",
50
+ "node-pluginsmanager-plugin": "4.8.4",
51
51
  "nyc": "15.1.0",
52
- "typescript": "4.4.4",
53
- "ws": "8.2.3"
52
+ "typescript": "4.6.4",
53
+ "ws": "8.6.0"
54
54
  },
55
55
  "homepage": "https://github.com/Psychopoulet/node-pluginsmanager#readme",
56
56
  "engines": {