node-pluginsmanager 2.3.6 → 2.3.9

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/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2021, Sébastien Vidal
1
+ Copyright (c) 2022, Sébastien Vidal
2
2
 
3
3
  Permission to use, copy, modify, and/or distribute this software for any
4
4
  purpose with or without fee is hereby granted, provided that the above
package/README.md CHANGED
@@ -35,211 +35,35 @@ $ npm install node-pluginsmanager
35
35
 
36
36
  ![Routes](./documentation/routes.jpg)
37
37
 
38
- ## Interfaces
38
+ ## Content
39
39
 
40
- ```typescript
41
- interface iPluginManagerOptions {
42
- "directory": string; // plugins location. default : join(homedir(), "node-pluginsmanager-plugins")
43
- "externalRessourcesDirectory": string; // external resources locations (sqlite, files, cache, etc...). default : join(homedir(), "node-pluginsmanager-resources")
44
- }
45
- ```
46
-
47
- ## Classes
48
-
49
- ### PluginManagerOptions (extends "Object")
50
-
51
- > can set optionnal options for "events" constructor
52
-
53
- -- Attributes --
54
-
55
- * ``` directory: string ``` used to set PluginsManager directory value
56
-
57
- ### PluginsManager (extends "events")
58
-
59
- -- Attributes --
60
-
61
- * ``` directory: string ``` plugins' directory path (must be writable, you can use [homedir](https://nodejs.org/api/os.html#os_os_homedir) for create specific directory)
62
- * ``` externalRessourcesDirectory: string ``` external resources locations (sqlite, files, cache, etc...) (must be writable, you can use [homedir](https://nodejs.org/api/os.html#os_os_homedir) for create specific directory)
63
- * ``` Array plugins: Array<[Orchestrator](https://github.com/Psychopoulet/node-pluginsmanager-plugin#orchestrator-extends-mediatoruser)> ``` plugins' orchestrators
64
-
65
- -- Constructor --
66
-
67
- * ``` constructor(options? : iPluginManagerOptions) ```
68
-
69
- -- Methods --
70
-
71
- > Please note that the "httpMiddleware" method was removed, you juste have to use "appMiddleware" with basic http request, and use "next" parameter as a callback to execute some stuff with the request if it is not managed by the plugins
40
+ [check the TypeScript definition file](https://github.com/Psychopoulet/node-pluginsmanager/blob/master/lib/index.d.ts)
72
41
 
73
- * ``` getPluginsNames(): Array<string> ``` return plugins' names
74
- * ``` setOrder(pluginsNames: Array<string>): Promise<void> ``` create a forced order to synchronously initialize plugins. not ordered plugins are asynchronously initialized after.
75
-
76
- * ``` checkAllModules(): Promise<void> ``` check all modules' versions for all plugins
77
- * ``` checkModules(plugin: [Orchestrator](https://github.com/Psychopoulet/node-pluginsmanager-plugin#orchestrator-extends-mediatoruser)): Promise<void> ``` check all modules' versions for a specific plugin
78
-
79
- * ``` appMiddleware(req: Request, res: Response, next: Function): void ``` used for execute all plugins' middlewares in app (express or other)
80
- * ``` socketMiddleware(server: WebSocketServer): void ``` middleware for socket to add bilateral push events
81
-
82
- * ``` beforeInitAll(callback: () => Promise<any>): Promise<void> ``` add a function executed before initializing all plugins
83
- * ``` initAll(data?: any): Promise<void> ``` initialize all plugins asynchronously, using "data" in arguments for "init" plugin's Orchestrator method
84
-
85
- * ``` releaseAll(data?: any): Promise<void> ``` release a plugin (keep package but destroy [Mediator](https://github.com/Psychopoulet/node-pluginsmanager-plugin#mediator-extends-bootable) & [Server](https://github.com/Psychopoulet/node-pluginsmanager-plugin#server-extends-mediatoruser)), using "data" in arguments for "release" plugin's [Orchestrator](https://github.com/Psychopoulet/node-pluginsmanager-plugin#orchestrator-extends-mediatoruser) method
86
- * ``` destroyAll(data?: any): Promise<void> ``` after releasing, destroy packages data & free "plugins" list, using "data" in arguments for "destroy" plugin's [Orchestrator](https://github.com/Psychopoulet/node-pluginsmanager-plugin#orchestrator-extends-mediatoruser) method
87
-
88
- * ``` installViaGithub(user: string, repo: string, data?: any): Promise<void> ``` install a plugin via github repo, using "data" in arguments for "install" and "init" plugin's [Orchestrator](https://github.com/Psychopoulet/node-pluginsmanager-plugin#orchestrator-extends-mediatoruser) methods
89
- * ``` updateViaGithub(plugin: [Orchestrator](https://github.com/Psychopoulet/node-pluginsmanager-plugin#orchestrator-extends-mediatoruser), data?: any): Promise<void> ``` update a plugin via its github repo, using "data" in arguments for "release", "update" and "init" plugin's methods
90
- * ``` uninstall(plugin: [Orchestrator](https://github.com/Psychopoulet/node-pluginsmanager-plugin#orchestrator-extends-mediatoruser), data?: any): Promise<string> ``` uninstall a plugin, using "data" in arguments for "release" and "uninstall" plugin's methods
91
-
92
- -- Events --
42
+ ## Events
93
43
 
94
44
  * ``` on("error", (err: Error) => void) : this ``` fires if an error occurs
95
45
 
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
46
+ * ``` on("loading", (plugin: Orchestrator, data?: any) => void) : this ``` fires if a plugin starts load
47
+ * ``` on("loaded", (plugin: Orchestrator, data?: any) => void) : this ``` fires if a plugin ends load
98
48
  * ``` on("allloaded", (data?: any) => void) : this ``` fires if all the plugins are loaded
99
49
 
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
50
+ * ``` on("initializing", (plugin: Orchestrator, data?: any) => void) : this ``` fires if a plugin starts init
51
+ * ``` on("initialized", (plugin: Orchestrator, data?: any) => void) : this ``` fires if a plugin ends init
102
52
  * ``` on("allinitialized", (data?: any) => void) : this ``` fires if all the plugins are initialized
103
53
 
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
54
+ * ``` on("released", (plugin: Orchestrator, data?: any) => void) : this ``` fires if a plugin is released
105
55
  * ``` on("allreleased", (data?: any) => void) : this ``` fires if all the plugins are released
106
56
 
107
57
  * ``` on("destroyed", (pluginName: string, data?: any) => void) : this ``` fires if a plugin is destroyed
108
58
  * ``` on("alldestroyed", (data?: any) => void) : this ``` fires if all the plugins are destroyed
109
59
 
110
60
  * ``` 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
61
+ * ``` on("updated", (plugin: Orchestrator, data?: any) => void) : this ``` fires if a plugin is updated
112
62
  * ``` on("uninstalled", (pluginName: string, data?: any) => void) : this ``` fires if a plugin is uninstalled
113
63
 
114
64
  ## Examples
115
65
 
116
- ### Use PluginsManager
117
-
118
- ```javascript
119
- "use strict";
120
-
121
- const { join } = require("path");
122
- const { homedir } = require("os");
123
- const PluginManager = require("node-pluginsmanager");
124
-
125
- const manager = new PluginManager({
126
- "directory": join(homedir(), "MySoftware", "plugins")
127
- });
128
-
129
- manager
130
-
131
- .on("error", (msg) => {
132
- console.log("--- [event/error] '" + msg.error + "' ---");
133
- })
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
-
146
- // init
147
-
148
- .on("initializing", (plugin) => {
149
- console.log("--- [event/initializing] '" + plugin.name + "' (v" + plugin.version + ") initialized ---");
150
- }).on("initialized", (plugin) => {
151
- console.log("--- [event/initialized] '" + plugin.name + "' (v" + plugin.version + ") initialized ---");
152
- })
153
- .on("allinitialized", () => {
154
- console.log("--- [event/initialized] all plugins initialized ---");
155
- })
156
-
157
- // release
158
-
159
- .on("released", (pluginName) => {
160
- console.log("--- [event/released] '" + pluginName + " released ---");
161
- })
162
- .on("allreleased", () => {
163
- console.log("--- [event/released] all plugins released ---");
164
- })
165
-
166
- // destroy
167
-
168
- .on("destroyed", (pluginName) => {
169
- console.log("--- [event/destroyed] '" + pluginName + " destroyed ---");
170
- })
171
- .on("alldestroyed", () => {
172
- console.log("--- [event/destroyed] all plugins destroyed ---");
173
- })
174
-
175
- // write
176
-
177
- .on("installed", (plugin) => {
178
- console.log("--- [event/installed] '" + plugin.name + "' (v" + plugin.version + ") installed ---");
179
- })
180
- .on("updated", (plugin) => {
181
- console.log("--- [event/updated] '" + plugin.name + "' (v" + plugin.version + ") updated ---");
182
- })
183
- .on("uninstalled", (pluginName) => {
184
- console.log("--- [event/uninstalled] '" + pluginName + "' uninstalled ---");
185
- })
186
-
187
- .beforeInitAll(() => { // optionnal
188
- return Promise.resolve();
189
- })
190
-
191
- .initAll(<optional data to pass to the 'init' plugins methods>).then(() => {
192
-
193
- console.log('all plugins initialized');
194
- console.log(manager.getPluginsNames());
195
-
196
- manager.installViaGithub(
197
- <account>,
198
- <plugin>,
199
- <optional data to pass to the 'install' && 'init' plugins methods>
200
- ).then((plugin) => {
201
- console.log(plugin.name + ' installed & initialized');
202
- }).catch((err) => {
203
- console.log(err);
204
- });
205
-
206
- manager.updateViaGithub( // use "github"'s plugin data if exists
207
- <plugin>,
208
- <optional data to pass to the 'release', 'update', && 'init' plugins methods>
209
- ).then((plugin) => {
210
- console.log(plugin.name + ' updated & initialized');
211
- }).catch((err) => {
212
- console.log(err);
213
- });
214
-
215
- manager.uninstall(
216
- <plugin>,
217
- <optional data to pass to the 'release' && 'uninstall' plugins methods>
218
- ).then((pluginName) => {
219
- console.log(pluginName + ' removed');
220
- }).catch((err) => {
221
- console.log(err);
222
- });
223
-
224
- }).catch((err) => {
225
- console.log(err);
226
- });
227
- ```
228
-
229
- ### Typescript
230
-
231
- ```typescript
232
- "use strict";
233
-
234
- import join from "path";
235
- import homedir from "os";
236
- import PluginManager = require('node-pluginsmanager');
237
-
238
- const manager = new PluginManager({
239
- "directory": join(homedir(), "MySoftware", "plugins")
240
- });
241
- // then, use it like before
242
- ```
66
+ [check the TypeScript compilation tests](https://github.com/Psychopoulet/node-pluginsmanager/blob/master/test/typescript/compilation.ts)
243
67
 
244
68
  ## Tests
245
69
 
@@ -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
 
@@ -28,7 +28,13 @@ module.exports = function createPluginByDirectory (directory, externalRessources
28
28
  return Promise.resolve().then(() => {
29
29
 
30
30
  Plugin = require(directory);
31
- Plugin = Plugin.Orchestrator ? Plugin.Orchestrator : Plugin;
31
+
32
+ if (Plugin.Orchestrator) {
33
+ Plugin = Plugin.Orchestrator;
34
+ }
35
+ else if (Plugin.default) {
36
+ Plugin = Plugin.default;
37
+ }
32
38
 
33
39
  return isFunction("createPluginByDirectory/function", Plugin);
34
40
 
package/lib/index.d.ts CHANGED
@@ -1,16 +1,16 @@
1
1
  /// <reference types="node" />
2
- /// <reference types="node-pluginsmanager-plugin" />
3
2
 
4
3
  declare module "node-pluginsmanager" {
5
4
 
6
5
  import { EventEmitter } from "events";
7
6
  import { Orchestrator } from "node-pluginsmanager-plugin";
8
7
  import { Server as WebSocketServer } from "ws";
8
+ import { Server as SocketIOServer } from "socket.io";
9
9
 
10
10
  interface iPluginManagerOptions {
11
- "directory": string; // plugins location. default : join(homedir(), "node-pluginsmanager-plugins")
12
- "externalRessourcesDirectory": string; // external resources locations (sqlite, files, cache, etc...). default : join(homedir(), "node-pluginsmanager-resources")
13
- "logger": Function | null;
11
+ "directory"?: string;
12
+ "externalRessourcesDirectory"?: string;
13
+ "logger"?: Function | null;
14
14
  }
15
15
 
16
16
  class PluginManager extends EventEmitter {
@@ -19,16 +19,16 @@ declare module "node-pluginsmanager" {
19
19
 
20
20
  // protected
21
21
 
22
- protected _beforeLoadAll: Function | null;
23
- protected _beforeInitAll: Function | null;
22
+ protected _beforeLoadAll: (data?: any) => Promise<void> | void | null;
23
+ protected _beforeInitAll: (data?: any) => Promise<void> | void | null;
24
24
 
25
25
  protected _orderedPluginsNames: Array<string>;
26
26
 
27
27
  // public
28
28
 
29
- public directory: string;
30
- public externalRessourcesDirectory: string;
31
- public plugins: Array<Orchestrator>;
29
+ public directory: string; // plugins location (must be writable). default : join(homedir(), "node-pluginsmanager-plugins")
30
+ public externalRessourcesDirectory: string; // external resources locations (sqlite, files, cache, etc...) (must be writable). default : join(homedir(), "node-pluginsmanager-resources")
31
+ public plugins: Array<Orchestrator>; // plugins' Orchestrators
32
32
 
33
33
  // constructor
34
34
 
@@ -44,7 +44,7 @@ declare module "node-pluginsmanager" {
44
44
 
45
45
  // setters
46
46
 
47
- public setOrder(pluginsNames: Array<string>): Promise<void>;
47
+ public setOrder(pluginsNames: Array<string>): Promise<void>; // create a forced order to synchronously initialize plugins. not ordered plugins are asynchronously initialized after.
48
48
 
49
49
  // checkers
50
50
 
@@ -53,26 +53,26 @@ declare module "node-pluginsmanager" {
53
53
 
54
54
  // network
55
55
 
56
- public appMiddleware(req: Request, res: Response, next: Function): void;
57
- public socketMiddleware(server: WebSocketServer): void;
56
+ public appMiddleware(req: Request, res: Response, next: Function): void; // used for execute all plugins' middlewares in app (express or other)
57
+ public socketMiddleware(server: WebSocketServer | SocketIOServer): void; // middleware for socket to add bilateral push events
58
58
 
59
59
  // load / destroy
60
60
 
61
- public beforeLoadAll(callback: () => Promise<any>): Promise<void>;
62
- public loadAll(data?: any): Promise<void>;
63
- public destroyAll(data?: any): Promise<void>;
61
+ public beforeLoadAll(callback: (data?: any) => Promise<void> | void): Promise<void>; // add a function executed before loading all plugins
62
+ public loadAll(data?: any): Promise<void>; // load all plugins asynchronously, using "data" in arguments for "load" plugin's Orchestrator method
63
+ public destroyAll(data?: any): Promise<void>; // after releasing, destroy packages data & free "plugins" list, using "data" in arguments for "destroy" plugin's Orchestrator method
64
64
 
65
65
  // init / release
66
66
 
67
- public beforeInitAll(callback: () => Promise<any>): Promise<void>;
68
- public initAll(data?: any): Promise<void>;
69
- public releaseAll(data?: any): Promise<void>;
67
+ public beforeInitAll(callback: (data?: any) => Promise<void> | void): Promise<void>; // add a function executed before initializing all plugins
68
+ public initAll(data?: any): Promise<void>; // initialize all plugins asynchronously, using "data" in arguments for "init" plugin's Orchestrator method
69
+ public releaseAll(data?: any): Promise<void>; // release a plugin (keep package but destroy Mediator & Server), using "data" in arguments for "release" plugin's Orchestrator method
70
70
 
71
71
  // write
72
72
 
73
- public installViaGithub(user: string, repo: string, data?: any): Promise<Orchestrator>;
74
- public updateViaGithub(plugin: Orchestrator, data?: any): Promise<Orchestrator>;
75
- public uninstall(plugin: Orchestrator, data?: any): Promise<string>;
73
+ public installViaGithub(user: string, repo: string, data?: any): Promise<Orchestrator>; // install a plugin via github repo, using "data" in arguments for "install" and "init" plugin's Orchestrator methods
74
+ public updateViaGithub(plugin: Orchestrator, data?: any): Promise<Orchestrator>; // update a plugin via its github repo, using "data" in arguments for "release", "update" and "init" plugin's methods
75
+ public uninstall(plugin: Orchestrator, data?: any): Promise<string>; // uninstall a plugin, using "data" in arguments for "release" and "uninstall" plugin's methods
76
76
 
77
77
  }
78
78
 
@@ -1,9 +1,5 @@
1
1
  "use strict";
2
2
 
3
- // consts
4
-
5
- const MAX_PARALLEL = 5;
6
-
7
3
  // private
8
4
 
9
5
  // methods
@@ -37,7 +33,7 @@
37
33
  * @param {number} i : stepper
38
34
  * @return {Promise} : result operation
39
35
  */
40
- function _initSortedPlugins (pluginsToInit, emit, data, i = 0) {
36
+ function _initPlugins (pluginsToInit, emit, data, i = 0) {
41
37
 
42
38
  return i < pluginsToInit.length ? Promise.resolve().then(() => {
43
39
 
@@ -46,29 +42,7 @@
46
42
  // loop
47
43
  }).then(() => {
48
44
 
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);
45
+ return _initPlugins(pluginsToInit, emit, data, i + 1);
72
46
 
73
47
  }) : Promise.resolve();
74
48
 
@@ -89,7 +63,7 @@ module.exports = function initSortedPlugins (plugins, orderedPluginsNames, emit,
89
63
 
90
64
  // first, sorted plugins
91
65
  return sortedPlugins.length ?
92
- _initSortedPlugins(sortedPlugins, emit, data) :
66
+ _initPlugins(sortedPlugins, emit, data) :
93
67
  Promise.resolve();
94
68
 
95
69
  }).then(() => {
@@ -97,12 +71,24 @@ module.exports = function initSortedPlugins (plugins, orderedPluginsNames, emit,
97
71
  const unsortedPlugin = [
98
72
  ...plugins.filter((plugin) => {
99
73
  return !orderedPluginsNames.includes(plugin.name);
74
+ }).sort((a, b) => {
75
+
76
+ if (a < b) {
77
+ return -1;
78
+ }
79
+ else if (a > b) {
80
+ return 1;
81
+ }
82
+ else {
83
+ return 0;
84
+ }
85
+
100
86
  })
101
87
  ];
102
88
 
103
89
  // then, all other plugins, asynchronously
104
90
  return unsortedPlugin.length ?
105
- _initUnSortedPlugins(unsortedPlugin, emit, data) :
91
+ _initPlugins(unsortedPlugin, emit, data) :
106
92
  Promise.resolve();
107
93
 
108
94
  });
@@ -12,10 +12,6 @@
12
12
  // locals
13
13
  const createPluginByDirectory = require(join(__dirname, "createPluginByDirectory.js"));
14
14
 
15
- // consts
16
-
17
- const MAX_PARALLEL = 5;
18
-
19
15
  // private
20
16
 
21
17
  // methods
@@ -71,7 +67,7 @@
71
67
  * @param {number} i : stepper
72
68
  * @return {Promise} : result operation
73
69
  */
74
- function _loadSortedPlugins (globalDirectory, externalRessourcesDirectory, pluginsToLoad, loadedPlugins, emit, logger, data, i = 0) {
70
+ function _loadPlugins (globalDirectory, externalRessourcesDirectory, pluginsToLoad, loadedPlugins, emit, logger, data, i = 0) {
75
71
 
76
72
  return i < pluginsToLoad.length ? Promise.resolve().then(() => {
77
73
 
@@ -80,33 +76,7 @@
80
76
  // loop
81
77
  }).then(() => {
82
78
 
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);
79
+ return _loadPlugins(globalDirectory, externalRessourcesDirectory, pluginsToLoad, loadedPlugins, emit, logger, data, i + 1);
110
80
 
111
81
  }) : Promise.resolve();
112
82
 
@@ -129,7 +99,7 @@ module.exports = function loadSortedPlugins (
129
99
 
130
100
  // first, sorted plugins
131
101
  return sortedPluginsNames.length ?
132
- _loadSortedPlugins(globalDirectory, externalRessourcesDirectory, sortedPluginsNames, loadedPlugins, emit, logger, data) :
102
+ _loadPlugins(globalDirectory, externalRessourcesDirectory, sortedPluginsNames, loadedPlugins, emit, logger, data) :
133
103
  Promise.resolve();
134
104
 
135
105
  }).then(() => {
@@ -137,12 +107,24 @@ module.exports = function loadSortedPlugins (
137
107
  const unsortedPluginsNames = [
138
108
  ...files.filter((pluginName) => {
139
109
  return !orderedPluginsNames.includes(pluginName);
110
+ }).sort((a, b) => {
111
+
112
+ if (a < b) {
113
+ return -1;
114
+ }
115
+ else if (a > b) {
116
+ return 1;
117
+ }
118
+ else {
119
+ return 0;
120
+ }
121
+
140
122
  })
141
123
  ];
142
124
 
143
125
  // then, all other plugins, asynchronously
144
126
  return unsortedPluginsNames.length ?
145
- _loadUnSortedPlugins(globalDirectory, externalRessourcesDirectory, unsortedPluginsNames, loadedPlugins, emit, logger, data) :
127
+ _loadPlugins(globalDirectory, externalRessourcesDirectory, unsortedPluginsNames, loadedPlugins, emit, logger, data) :
146
128
  Promise.resolve();
147
129
 
148
130
  });
package/lib/main.js CHANGED
@@ -13,9 +13,7 @@
13
13
 
14
14
  // externals
15
15
  const versionModulesChecker = require("check-version-modules");
16
- const {
17
- mkdirpProm, readdirProm, rmdirpProm
18
- } = require("node-promfs");
16
+ const { mkdirp, readdir, remove } = require("fs-extra");
19
17
 
20
18
  // locals
21
19
  const isAbsoluteDirectory = require(join(__dirname, "checkers", "isAbsoluteDirectory.js"));
@@ -229,7 +227,7 @@ module.exports = class PluginsManager extends Events {
229
227
  // create dir if not exist
230
228
  return isNonEmptyString("initAll/directory", this.directory).then(() => {
231
229
 
232
- return mkdirpProm(this.directory).then(() => {
230
+ return mkdirp(this.directory).then(() => {
233
231
  return isAbsoluteDirectory("initAll/directory", this.directory);
234
232
  });
235
233
 
@@ -238,7 +236,7 @@ module.exports = class PluginsManager extends Events {
238
236
 
239
237
  return isNonEmptyString("initAll/externalRessourcesDirectory", this.externalRessourcesDirectory).then(() => {
240
238
 
241
- return mkdirpProm(this.externalRessourcesDirectory).then(() => {
239
+ return mkdirp(this.externalRessourcesDirectory).then(() => {
242
240
  return isAbsoluteDirectory("initAll/externalRessourcesDirectory", this.externalRessourcesDirectory);
243
241
  });
244
242
 
@@ -256,7 +254,7 @@ module.exports = class PluginsManager extends Events {
256
254
 
257
255
  return "function" !== typeof this._beforeLoadAll ? Promise.resolve() : new Promise((resolve, reject) => {
258
256
 
259
- const fn = this._beforeLoadAll();
257
+ const fn = this._beforeLoadAll(data);
260
258
 
261
259
  if (!(fn instanceof Promise)) {
262
260
  resolve();
@@ -270,7 +268,7 @@ module.exports = class PluginsManager extends Events {
270
268
  // init plugins
271
269
  }).then(() => {
272
270
 
273
- return readdirProm(this.directory);
271
+ return readdir(this.directory);
274
272
 
275
273
  // load all
276
274
  }).then((files) => {
@@ -352,7 +350,7 @@ module.exports = class PluginsManager extends Events {
352
350
  // remove all external resources
353
351
  }).then(() => {
354
352
 
355
- return rmdirpProm(this.externalRessourcesDirectory);
353
+ return remove(this.externalRessourcesDirectory);
356
354
 
357
355
  });
358
356
 
@@ -383,7 +381,7 @@ module.exports = class PluginsManager extends Events {
383
381
  // execute _beforeInitAll
384
382
  return "function" !== typeof this._beforeInitAll ? Promise.resolve() : new Promise((resolve, reject) => {
385
383
 
386
- const fn = this._beforeInitAll();
384
+ const fn = this._beforeInitAll(data);
387
385
 
388
386
  if (!(fn instanceof Promise)) {
389
387
  resolve();
@@ -531,7 +529,7 @@ module.exports = class PluginsManager extends Events {
531
529
 
532
530
  isAbsoluteDirectory("installViaGithub/plugindirectory", directory).then(() => {
533
531
 
534
- return rmdirpProm(directory).then(() => {
532
+ return remove(directory).then(() => {
535
533
  reject(err);
536
534
  });
537
535
 
@@ -701,7 +699,7 @@ module.exports = class PluginsManager extends Events {
701
699
 
702
700
  return plugin.release(data).then(() => {
703
701
 
704
- return rmdirpProm(join(this.externalRessourcesDirectory, pluginName));
702
+ return remove(join(this.externalRessourcesDirectory, pluginName));
705
703
 
706
704
  }).then(() => {
707
705
 
@@ -730,7 +728,7 @@ module.exports = class PluginsManager extends Events {
730
728
 
731
729
  this.emit("uninstalled", pluginName, data);
732
730
 
733
- return rmdirpProm(directory);
731
+ return remove(directory);
734
732
 
735
733
  });
736
734
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-pluginsmanager",
3
- "version": "2.3.6",
3
+ "version": "2.3.9",
4
4
  "description": "A plugins manager",
5
5
  "main": "lib/main.js",
6
6
  "typings": "lib/index.d.ts",
@@ -36,21 +36,21 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "check-version-modules": "1.3.5",
39
- "node-promfs": "3.7.0"
39
+ "fs-extra": "10.1.0"
40
40
  },
41
41
  "devDependencies": {
42
- "@types/node": "16.11.10",
42
+ "@types/node": "17.0.38",
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.3.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.16.0",
47
+ "express": "4.18.1",
48
+ "husky": "8.0.1",
49
+ "mocha": "10.0.0",
50
+ "node-pluginsmanager-plugin": "4.8.8",
51
51
  "nyc": "15.1.0",
52
- "typescript": "4.5.2",
53
- "ws": "8.3.0"
52
+ "typescript": "4.7.2",
53
+ "ws": "8.7.0"
54
54
  },
55
55
  "homepage": "https://github.com/Psychopoulet/node-pluginsmanager#readme",
56
56
  "engines": {