node-pluginsmanager 2.3.9 → 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.
- package/lib/cjs/PluginsManager.d.ts +38 -0
- package/lib/cjs/PluginsManager.js +442 -0
- package/lib/cjs/checkers/checkAbsoluteDirectory.d.ts +1 -0
- package/lib/cjs/checkers/checkAbsoluteDirectory.js +20 -0
- package/lib/cjs/checkers/checkDirectory.d.ts +1 -0
- package/lib/cjs/checkers/checkDirectory.js +24 -0
- package/lib/cjs/checkers/checkFunction.d.ts +1 -0
- package/lib/cjs/checkers/checkFunction.js +16 -0
- package/lib/cjs/checkers/checkNonEmptyArray.d.ts +1 -0
- package/lib/cjs/checkers/checkNonEmptyArray.js +19 -0
- package/lib/cjs/checkers/checkNonEmptyString.d.ts +1 -0
- package/lib/cjs/checkers/checkNonEmptyString.js +19 -0
- package/lib/cjs/checkers/checkOrchestrator.d.ts +1 -0
- package/lib/cjs/checkers/checkOrchestrator.js +36 -0
- package/lib/cjs/cmd/cmd.d.ts +1 -0
- package/lib/cjs/cmd/cmd.js +37 -0
- package/lib/cjs/cmd/git/gitInstall.d.ts +1 -0
- package/lib/cjs/cmd/git/gitInstall.js +42 -0
- package/lib/cjs/cmd/git/gitUpdate.d.ts +1 -0
- package/lib/cjs/cmd/git/gitUpdate.js +18 -0
- package/lib/cjs/cmd/npm/npmCmd.d.ts +1 -0
- package/lib/cjs/cmd/npm/npmCmd.js +18 -0
- package/lib/cjs/cmd/npm/npmInstall.d.ts +1 -0
- package/lib/cjs/cmd/npm/npmInstall.js +14 -0
- package/lib/cjs/cmd/npm/npmUpdate.d.ts +1 -0
- package/lib/cjs/cmd/npm/npmUpdate.js +14 -0
- package/lib/cjs/cmd/stdToString.d.ts +1 -0
- package/lib/cjs/cmd/stdToString.js +16 -0
- package/lib/cjs/createPluginByDirectory.d.ts +2 -0
- package/lib/cjs/createPluginByDirectory.js +61 -0
- package/lib/cjs/extractGithub.d.ts +1 -0
- package/lib/cjs/extractGithub.js +20 -0
- package/lib/cjs/initSortedPlugins.d.ts +2 -0
- package/lib/cjs/initSortedPlugins.js +56 -0
- package/lib/cjs/loadSortedPlugins.d.ts +2 -0
- package/lib/cjs/loadSortedPlugins.js +74 -0
- package/lib/cjs/main.cjs +8 -0
- package/lib/cjs/main.d.cts +2 -0
- package/package.json +30 -12
- package/lib/checkers/isAbsoluteDirectory.js +0 -27
- package/lib/checkers/isDirectory.js +0 -34
- package/lib/checkers/isFunction.js +0 -18
- package/lib/checkers/isNonEmptyArray.js +0 -21
- package/lib/checkers/isNonEmptyString.js +0 -21
- package/lib/checkers/isOrchestrator.js +0 -41
- package/lib/cmd/cmd.js +0 -44
- package/lib/cmd/git/install.js +0 -49
- package/lib/cmd/git/update.js +0 -23
- package/lib/cmd/npm/cmd.js +0 -23
- package/lib/cmd/npm/install.js +0 -15
- package/lib/cmd/npm/update.js +0 -15
- package/lib/cmd/stdToString.js +0 -17
- package/lib/createPluginByDirectory.js +0 -70
- package/lib/index.d.ts +0 -81
- package/lib/initSortedPlugins.js +0 -96
- package/lib/loadSortedPlugins.js +0 -132
- package/lib/main.js +0 -743
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
// deps
|
|
4
|
-
|
|
5
|
-
// natives
|
|
6
|
-
const { join } = require("path");
|
|
7
|
-
const Events = require("events");
|
|
8
|
-
|
|
9
|
-
// locals
|
|
10
|
-
const isFunction = require(join(__dirname, "isFunction.js"));
|
|
11
|
-
|
|
12
|
-
// module
|
|
13
|
-
|
|
14
|
-
module.exports = function isOrchestrator (dataName, data) {
|
|
15
|
-
|
|
16
|
-
if ("undefined" === typeof data) {
|
|
17
|
-
return Promise.reject(new ReferenceError("\"" + dataName + "\" parameter is missing"));
|
|
18
|
-
}
|
|
19
|
-
else if ("object" !== typeof data || !(data instanceof Events)) {
|
|
20
|
-
return Promise.reject(new TypeError("\"" + dataName + "\" parameter is not an Event"));
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
else {
|
|
24
|
-
|
|
25
|
-
return isFunction("isOrchestrator/load", data.load).then(() => {
|
|
26
|
-
return isFunction("isOrchestrator/destroy", data.destroy);
|
|
27
|
-
}).then(() => {
|
|
28
|
-
return isFunction("isOrchestrator/init", data.init);
|
|
29
|
-
}).then(() => {
|
|
30
|
-
return isFunction("isOrchestrator/release", data.release);
|
|
31
|
-
}).then(() => {
|
|
32
|
-
return isFunction("isOrchestrator/install", data.install);
|
|
33
|
-
}).then(() => {
|
|
34
|
-
return isFunction("isOrchestrator/update", data.update);
|
|
35
|
-
}).then(() => {
|
|
36
|
-
return isFunction("isOrchestrator/uninstall", data.uninstall);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
};
|
package/lib/cmd/cmd.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
// deps
|
|
4
|
-
|
|
5
|
-
// natives
|
|
6
|
-
const { join } = require("path");
|
|
7
|
-
const { spawn } = require("child_process");
|
|
8
|
-
|
|
9
|
-
// locals
|
|
10
|
-
const isDirectory = require(join(__dirname, "..", "checkers", "isDirectory.js"));
|
|
11
|
-
const isNonEmptyArray = require(join(__dirname, "..", "checkers", "isNonEmptyArray.js"));
|
|
12
|
-
const isNonEmptyString = require(join(__dirname, "..", "checkers", "isNonEmptyString.js"));
|
|
13
|
-
const stdToString = require(join(__dirname, "stdToString.js"));
|
|
14
|
-
|
|
15
|
-
// module
|
|
16
|
-
|
|
17
|
-
module.exports = function cmd (directory, command, params) {
|
|
18
|
-
|
|
19
|
-
return isDirectory("cmd/directory", directory).then(() => {
|
|
20
|
-
return isNonEmptyString("cmd/command", command);
|
|
21
|
-
}).then(() => {
|
|
22
|
-
return isNonEmptyArray("cmd/params", params);
|
|
23
|
-
}).then(() => {
|
|
24
|
-
|
|
25
|
-
return new Promise((resolve, reject) => {
|
|
26
|
-
|
|
27
|
-
let result = "";
|
|
28
|
-
const mySpawn = spawn(command, params, {
|
|
29
|
-
"cwd": directory
|
|
30
|
-
}).on("error", (err) => {
|
|
31
|
-
result += stdToString(err);
|
|
32
|
-
}).on("close", (code) => {
|
|
33
|
-
return code ? reject(new Error(result)) : resolve();
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
mySpawn.stderr.on("data", (msg) => {
|
|
37
|
-
result += stdToString(msg);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
};
|
package/lib/cmd/git/install.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
// deps
|
|
4
|
-
|
|
5
|
-
// natives
|
|
6
|
-
const { join, dirname } = require("path");
|
|
7
|
-
|
|
8
|
-
// locals
|
|
9
|
-
const isDirectory = require(join(__dirname, "..", "..", "checkers", "isDirectory.js"));
|
|
10
|
-
const isNonEmptyString = require(join(__dirname, "..", "..", "checkers", "isNonEmptyString.js"));
|
|
11
|
-
const cmd = require(join(__dirname, "..", "cmd.js"));
|
|
12
|
-
|
|
13
|
-
// module
|
|
14
|
-
|
|
15
|
-
module.exports = function gitinstall (directory, user, repo) {
|
|
16
|
-
|
|
17
|
-
return isNonEmptyString("cmd/git/install/directory", directory).then(() => {
|
|
18
|
-
|
|
19
|
-
return new Promise((resolve, reject) => {
|
|
20
|
-
|
|
21
|
-
isDirectory("cmd/git/install/directory", directory).then(() => {
|
|
22
|
-
reject(new Error("\"" + directory + "\" aldready exists"));
|
|
23
|
-
}).catch(() => {
|
|
24
|
-
resolve();
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
}).then(() => {
|
|
30
|
-
return isNonEmptyString("cmd/git/install/user", user);
|
|
31
|
-
}).then(() => {
|
|
32
|
-
return isNonEmptyString("cmd/git/install/repo", repo);
|
|
33
|
-
}).then(() => {
|
|
34
|
-
|
|
35
|
-
// git clone
|
|
36
|
-
return cmd(dirname(directory), "git", [
|
|
37
|
-
"-c",
|
|
38
|
-
"core.quotepath=false",
|
|
39
|
-
"clone",
|
|
40
|
-
"--recursive",
|
|
41
|
-
"--depth",
|
|
42
|
-
"1",
|
|
43
|
-
"https://github.com/" + user + "/" + repo + "/",
|
|
44
|
-
directory
|
|
45
|
-
]);
|
|
46
|
-
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
};
|
package/lib/cmd/git/update.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
// deps
|
|
4
|
-
|
|
5
|
-
// natives
|
|
6
|
-
const { join } = require("path");
|
|
7
|
-
|
|
8
|
-
// locals
|
|
9
|
-
const isDirectory = require(join(__dirname, "..", "..", "checkers", "isDirectory.js"));
|
|
10
|
-
const cmd = require(join(__dirname, "..", "cmd.js"));
|
|
11
|
-
|
|
12
|
-
// module
|
|
13
|
-
|
|
14
|
-
module.exports = function gitupdate (directory) {
|
|
15
|
-
|
|
16
|
-
return isDirectory("cmd/git/update/directory", directory).then(() => {
|
|
17
|
-
|
|
18
|
-
// git update
|
|
19
|
-
return cmd(directory, "git", [ "pull" ]);
|
|
20
|
-
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
};
|
package/lib/cmd/npm/cmd.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
// deps
|
|
4
|
-
|
|
5
|
-
// natives
|
|
6
|
-
const { join } = require("path");
|
|
7
|
-
|
|
8
|
-
// locals
|
|
9
|
-
const isDirectory = require(join(__dirname, "..", "..", "checkers", "isDirectory.js"));
|
|
10
|
-
const cmd = require(join(__dirname, "..", "cmd.js"));
|
|
11
|
-
|
|
12
|
-
// module
|
|
13
|
-
|
|
14
|
-
module.exports = function npmcmd (directory, params) {
|
|
15
|
-
|
|
16
|
-
return isDirectory("cmd/npm/cmd/directory", directory).then(() => {
|
|
17
|
-
|
|
18
|
-
// npm install
|
|
19
|
-
return cmd(directory, (/^win/).test((0, process).platform) ? "npm.cmd" : "npm", params);
|
|
20
|
-
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
};
|
package/lib/cmd/npm/install.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
// deps
|
|
4
|
-
|
|
5
|
-
// natives
|
|
6
|
-
const { join } = require("path");
|
|
7
|
-
|
|
8
|
-
// locals
|
|
9
|
-
const cmd = require(join(__dirname, "cmd.js"));
|
|
10
|
-
|
|
11
|
-
// module
|
|
12
|
-
|
|
13
|
-
module.exports = function npminstall (directory) {
|
|
14
|
-
return cmd(directory, [ "install", "--prod" ]);
|
|
15
|
-
};
|
package/lib/cmd/npm/update.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
// deps
|
|
4
|
-
|
|
5
|
-
// natives
|
|
6
|
-
const { join } = require("path");
|
|
7
|
-
|
|
8
|
-
// locals
|
|
9
|
-
const cmd = require(join(__dirname, "cmd.js"));
|
|
10
|
-
|
|
11
|
-
// module
|
|
12
|
-
|
|
13
|
-
module.exports = function npmupdate (directory) {
|
|
14
|
-
return cmd(directory, [ "update", "--prod" ]);
|
|
15
|
-
};
|
package/lib/cmd/stdToString.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
// module
|
|
4
|
-
|
|
5
|
-
module.exports = (msg) => {
|
|
6
|
-
|
|
7
|
-
if ("object" !== typeof msg) {
|
|
8
|
-
return String(msg);
|
|
9
|
-
}
|
|
10
|
-
else if (msg instanceof Buffer) {
|
|
11
|
-
return msg.toString("utf8");
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
return msg.message ? msg.message : String(msg);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
};
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
// deps
|
|
4
|
-
|
|
5
|
-
// natives
|
|
6
|
-
const { join, basename } = require("path");
|
|
7
|
-
|
|
8
|
-
// locals
|
|
9
|
-
const isAbsoluteDirectory = require(join(__dirname, "checkers", "isAbsoluteDirectory.js"));
|
|
10
|
-
const isFunction = require(join(__dirname, "checkers", "isFunction.js"));
|
|
11
|
-
const isOrchestrator = require(join(__dirname, "checkers", "isOrchestrator.js"));
|
|
12
|
-
|
|
13
|
-
// module
|
|
14
|
-
|
|
15
|
-
module.exports = function createPluginByDirectory (directory, externalRessourcesDirectory, logger, data) {
|
|
16
|
-
|
|
17
|
-
return isAbsoluteDirectory("createPluginByDirectory/directory", directory).then(() => {
|
|
18
|
-
|
|
19
|
-
return isAbsoluteDirectory("createPluginByDirectory/externalRessourcesDirectory", externalRessourcesDirectory);
|
|
20
|
-
|
|
21
|
-
}).then(() => {
|
|
22
|
-
|
|
23
|
-
let Plugin = null;
|
|
24
|
-
let plugin = null;
|
|
25
|
-
|
|
26
|
-
const pluginBaseNameDirectory = basename(directory);
|
|
27
|
-
|
|
28
|
-
return Promise.resolve().then(() => {
|
|
29
|
-
|
|
30
|
-
Plugin = require(directory);
|
|
31
|
-
|
|
32
|
-
if (Plugin.Orchestrator) {
|
|
33
|
-
Plugin = Plugin.Orchestrator;
|
|
34
|
-
}
|
|
35
|
-
else if (Plugin.default) {
|
|
36
|
-
Plugin = Plugin.default;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return isFunction("createPluginByDirectory/function", Plugin);
|
|
40
|
-
|
|
41
|
-
}).then(() => {
|
|
42
|
-
|
|
43
|
-
plugin = new Plugin({
|
|
44
|
-
"externalRessourcesDirectory": join(externalRessourcesDirectory, pluginBaseNameDirectory),
|
|
45
|
-
"logger": logger
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
return isOrchestrator("createPluginByDirectory/orchestrator", plugin);
|
|
49
|
-
|
|
50
|
-
}).then(() => {
|
|
51
|
-
|
|
52
|
-
plugin.name = pluginBaseNameDirectory;
|
|
53
|
-
|
|
54
|
-
return plugin.load(data).then(() => {
|
|
55
|
-
|
|
56
|
-
return plugin.name === pluginBaseNameDirectory ? Promise.resolve() : Promise.reject(new Error(
|
|
57
|
-
"Plugin's name (\"" + plugin.name + "\") does not fit with plugin's directory basename (\"" + pluginBaseNameDirectory + "\")"
|
|
58
|
-
));
|
|
59
|
-
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
}).then(() => {
|
|
63
|
-
|
|
64
|
-
return Promise.resolve(plugin);
|
|
65
|
-
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
};
|
package/lib/index.d.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
|
|
3
|
-
declare module "node-pluginsmanager" {
|
|
4
|
-
|
|
5
|
-
import { EventEmitter } from "events";
|
|
6
|
-
import { Orchestrator } from "node-pluginsmanager-plugin";
|
|
7
|
-
import { Server as WebSocketServer } from "ws";
|
|
8
|
-
import { Server as SocketIOServer } from "socket.io";
|
|
9
|
-
|
|
10
|
-
interface iPluginManagerOptions {
|
|
11
|
-
"directory"?: string;
|
|
12
|
-
"externalRessourcesDirectory"?: string;
|
|
13
|
-
"logger"?: Function | null;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
class PluginManager extends EventEmitter {
|
|
17
|
-
|
|
18
|
-
// attributes
|
|
19
|
-
|
|
20
|
-
// protected
|
|
21
|
-
|
|
22
|
-
protected _beforeLoadAll: (data?: any) => Promise<void> | void | null;
|
|
23
|
-
protected _beforeInitAll: (data?: any) => Promise<void> | void | null;
|
|
24
|
-
|
|
25
|
-
protected _orderedPluginsNames: Array<string>;
|
|
26
|
-
|
|
27
|
-
// public
|
|
28
|
-
|
|
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
|
-
|
|
33
|
-
// constructor
|
|
34
|
-
|
|
35
|
-
constructor (options?: iPluginManagerOptions);
|
|
36
|
-
|
|
37
|
-
// methods
|
|
38
|
-
|
|
39
|
-
// public
|
|
40
|
-
|
|
41
|
-
// getters
|
|
42
|
-
|
|
43
|
-
public getPluginsNames(): Array<string>;
|
|
44
|
-
|
|
45
|
-
// setters
|
|
46
|
-
|
|
47
|
-
public setOrder(pluginsNames: Array<string>): Promise<void>; // create a forced order to synchronously initialize plugins. not ordered plugins are asynchronously initialized after.
|
|
48
|
-
|
|
49
|
-
// checkers
|
|
50
|
-
|
|
51
|
-
public checkAllModules(): Promise<void>;
|
|
52
|
-
public checkModules(plugin: Orchestrator): Promise<void>;
|
|
53
|
-
|
|
54
|
-
// network
|
|
55
|
-
|
|
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
|
-
|
|
59
|
-
// load / destroy
|
|
60
|
-
|
|
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
|
-
|
|
65
|
-
// init / release
|
|
66
|
-
|
|
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
|
-
|
|
71
|
-
// write
|
|
72
|
-
|
|
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
|
-
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export = PluginManager;
|
|
80
|
-
|
|
81
|
-
}
|
package/lib/initSortedPlugins.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
// private
|
|
4
|
-
|
|
5
|
-
// methods
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Load plugins with sort conditions
|
|
9
|
-
* @param {object} plugin : plugin to init
|
|
10
|
-
* @param {function} emit : emit data function
|
|
11
|
-
* @param {object} data : data to send
|
|
12
|
-
* @return {Promise} : result operation
|
|
13
|
-
*/
|
|
14
|
-
function _initPlugin (plugin, emit, data) {
|
|
15
|
-
|
|
16
|
-
emit("initializing", plugin, data);
|
|
17
|
-
|
|
18
|
-
return plugin.init(data).then(() => {
|
|
19
|
-
|
|
20
|
-
emit("initialized", plugin, data);
|
|
21
|
-
|
|
22
|
-
return Promise.resolve();
|
|
23
|
-
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Load plugins with sort conditions
|
|
30
|
-
* @param {object} pluginsToInit : plugins to init
|
|
31
|
-
* @param {function} emit : emit data function
|
|
32
|
-
* @param {object} data : data to send
|
|
33
|
-
* @param {number} i : stepper
|
|
34
|
-
* @return {Promise} : result operation
|
|
35
|
-
*/
|
|
36
|
-
function _initPlugins (pluginsToInit, emit, data, i = 0) {
|
|
37
|
-
|
|
38
|
-
return i < pluginsToInit.length ? Promise.resolve().then(() => {
|
|
39
|
-
|
|
40
|
-
return _initPlugin(pluginsToInit[i], emit, data);
|
|
41
|
-
|
|
42
|
-
// loop
|
|
43
|
-
}).then(() => {
|
|
44
|
-
|
|
45
|
-
return _initPlugins(pluginsToInit, emit, data, i + 1);
|
|
46
|
-
|
|
47
|
-
}) : Promise.resolve();
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// module
|
|
52
|
-
|
|
53
|
-
module.exports = function initSortedPlugins (plugins, orderedPluginsNames, emit, data) {
|
|
54
|
-
|
|
55
|
-
// if no plugins, does not run
|
|
56
|
-
return !plugins.length ? Promise.resolve() : Promise.resolve().then(() => {
|
|
57
|
-
|
|
58
|
-
const sortedPlugins = [
|
|
59
|
-
...plugins.filter((plugin) => {
|
|
60
|
-
return orderedPluginsNames.includes(plugin.name);
|
|
61
|
-
})
|
|
62
|
-
];
|
|
63
|
-
|
|
64
|
-
// first, sorted plugins
|
|
65
|
-
return sortedPlugins.length ?
|
|
66
|
-
_initPlugins(sortedPlugins, emit, data) :
|
|
67
|
-
Promise.resolve();
|
|
68
|
-
|
|
69
|
-
}).then(() => {
|
|
70
|
-
|
|
71
|
-
const unsortedPlugin = [
|
|
72
|
-
...plugins.filter((plugin) => {
|
|
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
|
-
|
|
86
|
-
})
|
|
87
|
-
];
|
|
88
|
-
|
|
89
|
-
// then, all other plugins, asynchronously
|
|
90
|
-
return unsortedPlugin.length ?
|
|
91
|
-
_initPlugins(unsortedPlugin, emit, data) :
|
|
92
|
-
Promise.resolve();
|
|
93
|
-
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
};
|
package/lib/loadSortedPlugins.js
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
eslint max-params: 0
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
"use strict";
|
|
6
|
-
|
|
7
|
-
// deps
|
|
8
|
-
|
|
9
|
-
// natives
|
|
10
|
-
const { join } = require("path");
|
|
11
|
-
|
|
12
|
-
// locals
|
|
13
|
-
const createPluginByDirectory = require(join(__dirname, "createPluginByDirectory.js"));
|
|
14
|
-
|
|
15
|
-
// private
|
|
16
|
-
|
|
17
|
-
// methods
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Load plugins with sort conditions
|
|
21
|
-
* @param {string} globalDirectory : get plugins directory
|
|
22
|
-
* @param {string} externalRessourcesDirectory : get ressources directory
|
|
23
|
-
* @param {string} pluginFileName : get ressources directory
|
|
24
|
-
* @param {object} loadedPlugins : already loaded plugins
|
|
25
|
-
* @param {function} emit : emit data function
|
|
26
|
-
* @param {function|null} logger : if logger, send it to plugin
|
|
27
|
-
* @param {object} data : data to send
|
|
28
|
-
* @return {Promise} : result operation
|
|
29
|
-
*/
|
|
30
|
-
function _loadPlugin (globalDirectory, externalRessourcesDirectory, pluginFileName, loadedPlugins, emit, logger, data) {
|
|
31
|
-
|
|
32
|
-
// is already loaded ?
|
|
33
|
-
const plugin = loadedPlugins.find((p) => {
|
|
34
|
-
return pluginFileName === p.name;
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
// is already exists ?
|
|
38
|
-
return plugin ? Promise.resolve() : Promise.resolve().then(() => {
|
|
39
|
-
|
|
40
|
-
emit("loading", pluginFileName, data);
|
|
41
|
-
|
|
42
|
-
const directory = join(globalDirectory, pluginFileName);
|
|
43
|
-
|
|
44
|
-
return createPluginByDirectory(directory, externalRessourcesDirectory, logger, data);
|
|
45
|
-
|
|
46
|
-
// emit event
|
|
47
|
-
}).then((createdPlugin) => {
|
|
48
|
-
|
|
49
|
-
emit("loaded", createdPlugin, data);
|
|
50
|
-
loadedPlugins.push(createdPlugin);
|
|
51
|
-
|
|
52
|
-
return Promise.resolve();
|
|
53
|
-
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Load plugins with sort conditions
|
|
60
|
-
* @param {string} globalDirectory : get plugins directory
|
|
61
|
-
* @param {string} externalRessourcesDirectory : get ressources directory
|
|
62
|
-
* @param {Array} pluginsToLoad : plugins to load
|
|
63
|
-
* @param {object} loadedPlugins : already loaded plugins
|
|
64
|
-
* @param {function} emit : emit data function
|
|
65
|
-
* @param {function|null} logger : if logger, send it to plugin
|
|
66
|
-
* @param {object} data : data to send
|
|
67
|
-
* @param {number} i : stepper
|
|
68
|
-
* @return {Promise} : result operation
|
|
69
|
-
*/
|
|
70
|
-
function _loadPlugins (globalDirectory, externalRessourcesDirectory, pluginsToLoad, loadedPlugins, emit, logger, data, i = 0) {
|
|
71
|
-
|
|
72
|
-
return i < pluginsToLoad.length ? Promise.resolve().then(() => {
|
|
73
|
-
|
|
74
|
-
return _loadPlugin(globalDirectory, externalRessourcesDirectory, pluginsToLoad[i], loadedPlugins, emit, logger, data);
|
|
75
|
-
|
|
76
|
-
// loop
|
|
77
|
-
}).then(() => {
|
|
78
|
-
|
|
79
|
-
return _loadPlugins(globalDirectory, externalRessourcesDirectory, pluginsToLoad, loadedPlugins, emit, logger, data, i + 1);
|
|
80
|
-
|
|
81
|
-
}) : Promise.resolve();
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// module
|
|
86
|
-
|
|
87
|
-
module.exports = function loadSortedPlugins (
|
|
88
|
-
globalDirectory, externalRessourcesDirectory, files, loadedPlugins, orderedPluginsNames, emit, logger, data
|
|
89
|
-
) {
|
|
90
|
-
|
|
91
|
-
// if no files, does not run
|
|
92
|
-
return !files.length ? Promise.resolve() : Promise.resolve().then(() => {
|
|
93
|
-
|
|
94
|
-
const sortedPluginsNames = [
|
|
95
|
-
...files.filter((pluginName) => {
|
|
96
|
-
return orderedPluginsNames.includes(pluginName);
|
|
97
|
-
})
|
|
98
|
-
];
|
|
99
|
-
|
|
100
|
-
// first, sorted plugins
|
|
101
|
-
return sortedPluginsNames.length ?
|
|
102
|
-
_loadPlugins(globalDirectory, externalRessourcesDirectory, sortedPluginsNames, loadedPlugins, emit, logger, data) :
|
|
103
|
-
Promise.resolve();
|
|
104
|
-
|
|
105
|
-
}).then(() => {
|
|
106
|
-
|
|
107
|
-
const unsortedPluginsNames = [
|
|
108
|
-
...files.filter((pluginName) => {
|
|
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
|
-
|
|
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();
|
|
129
|
-
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
};
|