node-pluginsmanager 2.3.7 → 2.4.0

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.
Files changed (59) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +10 -186
  3. package/lib/cjs/PluginsManager.d.ts +38 -0
  4. package/lib/cjs/PluginsManager.js +442 -0
  5. package/lib/cjs/checkers/checkAbsoluteDirectory.d.ts +1 -0
  6. package/lib/cjs/checkers/checkAbsoluteDirectory.js +20 -0
  7. package/lib/cjs/checkers/checkDirectory.d.ts +1 -0
  8. package/lib/cjs/checkers/checkDirectory.js +24 -0
  9. package/lib/cjs/checkers/checkFunction.d.ts +1 -0
  10. package/lib/cjs/checkers/checkFunction.js +16 -0
  11. package/lib/cjs/checkers/checkNonEmptyArray.d.ts +1 -0
  12. package/lib/cjs/checkers/checkNonEmptyArray.js +19 -0
  13. package/lib/cjs/checkers/checkNonEmptyString.d.ts +1 -0
  14. package/lib/cjs/checkers/checkNonEmptyString.js +19 -0
  15. package/lib/cjs/checkers/checkOrchestrator.d.ts +1 -0
  16. package/lib/cjs/checkers/checkOrchestrator.js +36 -0
  17. package/lib/cjs/cmd/cmd.d.ts +1 -0
  18. package/lib/cjs/cmd/cmd.js +37 -0
  19. package/lib/cjs/cmd/git/gitInstall.d.ts +1 -0
  20. package/lib/cjs/cmd/git/gitInstall.js +42 -0
  21. package/lib/cjs/cmd/git/gitUpdate.d.ts +1 -0
  22. package/lib/cjs/cmd/git/gitUpdate.js +18 -0
  23. package/lib/cjs/cmd/npm/npmCmd.d.ts +1 -0
  24. package/lib/cjs/cmd/npm/npmCmd.js +18 -0
  25. package/lib/cjs/cmd/npm/npmInstall.d.ts +1 -0
  26. package/lib/cjs/cmd/npm/npmInstall.js +14 -0
  27. package/lib/cjs/cmd/npm/npmUpdate.d.ts +1 -0
  28. package/lib/cjs/cmd/npm/npmUpdate.js +14 -0
  29. package/lib/cjs/cmd/stdToString.d.ts +1 -0
  30. package/lib/cjs/cmd/stdToString.js +16 -0
  31. package/lib/cjs/createPluginByDirectory.d.ts +2 -0
  32. package/lib/cjs/createPluginByDirectory.js +61 -0
  33. package/lib/cjs/extractGithub.d.ts +1 -0
  34. package/lib/cjs/extractGithub.js +20 -0
  35. package/lib/cjs/initSortedPlugins.d.ts +2 -0
  36. package/lib/cjs/initSortedPlugins.js +56 -0
  37. package/lib/cjs/loadSortedPlugins.d.ts +2 -0
  38. package/lib/cjs/loadSortedPlugins.js +74 -0
  39. package/lib/cjs/main.cjs +8 -0
  40. package/lib/cjs/main.d.cts +2 -0
  41. package/package.json +31 -13
  42. package/lib/checkers/isAbsoluteDirectory.js +0 -27
  43. package/lib/checkers/isDirectory.js +0 -34
  44. package/lib/checkers/isFunction.js +0 -18
  45. package/lib/checkers/isNonEmptyArray.js +0 -21
  46. package/lib/checkers/isNonEmptyString.js +0 -21
  47. package/lib/checkers/isOrchestrator.js +0 -41
  48. package/lib/cmd/cmd.js +0 -44
  49. package/lib/cmd/git/install.js +0 -49
  50. package/lib/cmd/git/update.js +0 -23
  51. package/lib/cmd/npm/cmd.js +0 -23
  52. package/lib/cmd/npm/install.js +0 -15
  53. package/lib/cmd/npm/update.js +0 -15
  54. package/lib/cmd/stdToString.js +0 -17
  55. package/lib/createPluginByDirectory.js +0 -64
  56. package/lib/index.d.ts +0 -81
  57. package/lib/initSortedPlugins.js +0 -96
  58. package/lib/loadSortedPlugins.js +0 -132
  59. package/lib/main.js +0 -745
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
 
@@ -0,0 +1,38 @@
1
+ /// <reference types="node" />
2
+ import EventEmitter from "events";
3
+ import { Orchestrator, tLogger, iIncomingMessage, iServerResponse } from "node-pluginsmanager-plugin";
4
+ import { Server as WebSocketServer } from "ws";
5
+ import { Server as SocketIOServer } from "socket.io";
6
+ interface iPluginManagerOptions {
7
+ "directory"?: string;
8
+ "externalRessourcesDirectory"?: string;
9
+ "logger"?: tLogger | null;
10
+ }
11
+ declare type tBeforeAllMethodCallback = (...data: any) => Promise<void> | void;
12
+ export default class PluginsManager extends EventEmitter {
13
+ protected _beforeLoadAll: tBeforeAllMethodCallback | null;
14
+ protected _beforeInitAll: tBeforeAllMethodCallback | null;
15
+ protected _logger: tLogger | null;
16
+ protected _orderedPluginsNames: Array<string>;
17
+ directory: string;
18
+ externalRessourcesDirectory: string;
19
+ plugins: Array<Orchestrator>;
20
+ constructor(options: iPluginManagerOptions);
21
+ getPluginsNames(): Array<string>;
22
+ setOrder(pluginsNames: Array<string>): Promise<void>;
23
+ getOrder(): Array<string>;
24
+ checkAllModules(): Promise<void>;
25
+ checkModules(plugin: Orchestrator): Promise<void>;
26
+ appMiddleware(req: iIncomingMessage, res: iServerResponse, next: Function): void;
27
+ socketMiddleware(server: WebSocketServer | SocketIOServer): void;
28
+ beforeLoadAll(callback: tBeforeAllMethodCallback): Promise<void>;
29
+ loadAll(...data: any): Promise<void>;
30
+ destroyAll(...data: any): Promise<void>;
31
+ beforeInitAll(callback: tBeforeAllMethodCallback): Promise<void>;
32
+ initAll(...data: any): Promise<void>;
33
+ releaseAll(...data: any): Promise<void>;
34
+ installViaGithub(user: string, repo: string, ...data: any): Promise<Orchestrator>;
35
+ updateViaGithub(plugin: Orchestrator, ...data: any): Promise<Orchestrator>;
36
+ uninstall(plugin: Orchestrator, ...data: any): Promise<string>;
37
+ }
38
+ export {};