node-pluginsmanager 2.3.8 → 2.4.1
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 +1 -1
- 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 -64
- 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
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
// deps
|
|
7
|
+
// natives
|
|
8
|
+
const child_process_1 = require("child_process");
|
|
9
|
+
// locals
|
|
10
|
+
const checkDirectory_1 = __importDefault(require("../checkers/checkDirectory"));
|
|
11
|
+
const checkNonEmptyArray_1 = __importDefault(require("../checkers/checkNonEmptyArray"));
|
|
12
|
+
const checkNonEmptyString_1 = __importDefault(require("../checkers/checkNonEmptyString"));
|
|
13
|
+
const stdToString_1 = __importDefault(require("./stdToString"));
|
|
14
|
+
// module
|
|
15
|
+
function cmd(directory, command, params) {
|
|
16
|
+
return (0, checkDirectory_1.default)("cmd/directory", directory).then(() => {
|
|
17
|
+
return (0, checkNonEmptyString_1.default)("cmd/command", command);
|
|
18
|
+
}).then(() => {
|
|
19
|
+
return (0, checkNonEmptyArray_1.default)("cmd/params", params);
|
|
20
|
+
}).then(() => {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
let result = "";
|
|
23
|
+
const mySpawn = (0, child_process_1.spawn)(command, params, {
|
|
24
|
+
"cwd": directory
|
|
25
|
+
}).on("error", (err) => {
|
|
26
|
+
result += (0, stdToString_1.default)(err);
|
|
27
|
+
}).on("close", (code) => {
|
|
28
|
+
return code ? reject(new Error(result)) : resolve();
|
|
29
|
+
});
|
|
30
|
+
mySpawn.stderr.on("data", (msg) => {
|
|
31
|
+
result += (0, stdToString_1.default)(msg);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
exports.default = cmd;
|
|
37
|
+
;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function gitInstall(directory: string, user: string, repo: string): Promise<void>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
// deps
|
|
7
|
+
// natives
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
// locals
|
|
10
|
+
const checkDirectory_1 = __importDefault(require("../../checkers/checkDirectory"));
|
|
11
|
+
const checkNonEmptyString_1 = __importDefault(require("../../checkers/checkNonEmptyString"));
|
|
12
|
+
const cmd_1 = __importDefault(require("../cmd"));
|
|
13
|
+
// module
|
|
14
|
+
function gitInstall(directory, user, repo) {
|
|
15
|
+
return (0, checkNonEmptyString_1.default)("cmd/git/install/directory", directory).then(() => {
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
(0, checkDirectory_1.default)("cmd/git/install/directory", directory).then(() => {
|
|
18
|
+
reject(new Error("\"" + directory + "\" aldready exists"));
|
|
19
|
+
}).catch(() => {
|
|
20
|
+
resolve();
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
}).then(() => {
|
|
24
|
+
return (0, checkNonEmptyString_1.default)("cmd/git/install/user", user);
|
|
25
|
+
}).then(() => {
|
|
26
|
+
return (0, checkNonEmptyString_1.default)("cmd/git/install/repo", repo);
|
|
27
|
+
}).then(() => {
|
|
28
|
+
// git clone
|
|
29
|
+
return (0, cmd_1.default)((0, path_1.dirname)(directory), "git", [
|
|
30
|
+
"-c",
|
|
31
|
+
"core.quotepath=false",
|
|
32
|
+
"clone",
|
|
33
|
+
"--recursive",
|
|
34
|
+
"--depth",
|
|
35
|
+
"1",
|
|
36
|
+
"https://github.com/" + user + "/" + repo + "/",
|
|
37
|
+
directory
|
|
38
|
+
]);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
exports.default = gitInstall;
|
|
42
|
+
;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function gitUpdate(directory: string): Promise<void>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
// deps
|
|
7
|
+
// locals
|
|
8
|
+
const checkDirectory_1 = __importDefault(require("../../checkers/checkDirectory"));
|
|
9
|
+
const cmd_1 = __importDefault(require("../cmd"));
|
|
10
|
+
// module
|
|
11
|
+
function gitUpdate(directory) {
|
|
12
|
+
return (0, checkDirectory_1.default)("cmd/git/update/directory", directory).then(() => {
|
|
13
|
+
// git update
|
|
14
|
+
return (0, cmd_1.default)(directory, "git", ["pull"]);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
exports.default = gitUpdate;
|
|
18
|
+
;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function npmCmd(directory: string, params: Array<string>): Promise<void>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
// deps
|
|
7
|
+
// locals
|
|
8
|
+
const checkDirectory_1 = __importDefault(require("../../checkers/checkDirectory"));
|
|
9
|
+
const cmd_1 = __importDefault(require("../cmd"));
|
|
10
|
+
// module
|
|
11
|
+
function npmCmd(directory, params) {
|
|
12
|
+
return (0, checkDirectory_1.default)("cmd/npm/cmd/directory", directory).then(() => {
|
|
13
|
+
// npm install
|
|
14
|
+
return (0, cmd_1.default)(directory, (/^win/).test(process.platform) ? "npm.cmd" : "npm", params);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
exports.default = npmCmd;
|
|
18
|
+
;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function npmInstall(directory: string): Promise<void>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
// deps
|
|
7
|
+
// locals
|
|
8
|
+
const npmCmd_1 = __importDefault(require("./npmCmd"));
|
|
9
|
+
// module
|
|
10
|
+
function npmInstall(directory) {
|
|
11
|
+
return (0, npmCmd_1.default)(directory, ["install", "--prod"]);
|
|
12
|
+
}
|
|
13
|
+
exports.default = npmInstall;
|
|
14
|
+
;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function npmUpdate(directory: string): Promise<void>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
// deps
|
|
7
|
+
// locals
|
|
8
|
+
const npmCmd_1 = __importDefault(require("./npmCmd"));
|
|
9
|
+
// module
|
|
10
|
+
function npmUpdate(directory) {
|
|
11
|
+
return (0, npmCmd_1.default)(directory, ["update", "--prod"]);
|
|
12
|
+
}
|
|
13
|
+
exports.default = npmUpdate;
|
|
14
|
+
;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function stdToString(msg: any): string;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// module
|
|
4
|
+
function stdToString(msg) {
|
|
5
|
+
if ("object" !== typeof msg) {
|
|
6
|
+
return String(msg);
|
|
7
|
+
}
|
|
8
|
+
else if (msg instanceof Buffer) {
|
|
9
|
+
return msg.toString("utf8");
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
return msg.message ? msg.message : String(msg);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.default = stdToString;
|
|
16
|
+
;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
// deps
|
|
7
|
+
// natives
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
// locals
|
|
10
|
+
const checkAbsoluteDirectory_1 = __importDefault(require("./checkers/checkAbsoluteDirectory"));
|
|
11
|
+
const checkOrchestrator_1 = __importDefault(require("./checkers/checkOrchestrator"));
|
|
12
|
+
const checkFunction_1 = __importDefault(require("./checkers/checkFunction"));
|
|
13
|
+
// module
|
|
14
|
+
function createPluginByDirectory(directory, externalRessourcesDirectory, logger) {
|
|
15
|
+
return (0, checkAbsoluteDirectory_1.default)("createPluginByDirectory/directory", directory).then(() => {
|
|
16
|
+
return (0, checkAbsoluteDirectory_1.default)("createPluginByDirectory/externalRessourcesDirectory", externalRessourcesDirectory);
|
|
17
|
+
}).then(() => {
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
try {
|
|
20
|
+
resolve(require(directory));
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
reject(e);
|
|
24
|
+
}
|
|
25
|
+
}).then((Plugin) => {
|
|
26
|
+
if (Plugin.Orchestrator) {
|
|
27
|
+
return Promise.resolve(Plugin.Orchestrator);
|
|
28
|
+
}
|
|
29
|
+
else if (Plugin.default) {
|
|
30
|
+
return Promise.resolve(Plugin.default);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
return Promise.resolve(Plugin);
|
|
34
|
+
}
|
|
35
|
+
}).then((Plugin) => {
|
|
36
|
+
return (0, checkFunction_1.default)("createPluginByDirectory/function", Plugin).then(() => {
|
|
37
|
+
const pluginBaseNameDirectory = (0, path_1.basename)(directory);
|
|
38
|
+
const plugin = new Plugin({
|
|
39
|
+
// usefull for inherited Orchestrators
|
|
40
|
+
"externalRessourcesDirectory": (0, path_1.join)(externalRessourcesDirectory, pluginBaseNameDirectory),
|
|
41
|
+
"logger": logger,
|
|
42
|
+
// useless, setted in inherited Orchestrators
|
|
43
|
+
"packageFile": "",
|
|
44
|
+
"descriptorFile": "",
|
|
45
|
+
"mediatorFile": "",
|
|
46
|
+
"serverFile": ""
|
|
47
|
+
});
|
|
48
|
+
return (0, checkOrchestrator_1.default)("createPluginByDirectory/orchestrator", plugin).then(() => {
|
|
49
|
+
plugin.name = pluginBaseNameDirectory;
|
|
50
|
+
return plugin.load().then(() => {
|
|
51
|
+
return plugin.name === pluginBaseNameDirectory ? Promise.resolve() : Promise.reject(new Error("Plugin's name (\"" + plugin.name + "\") does not fit with plugin's directory basename (\"" + pluginBaseNameDirectory + "\")"));
|
|
52
|
+
});
|
|
53
|
+
}).then(() => {
|
|
54
|
+
return Promise.resolve(plugin);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
exports.default = createPluginByDirectory;
|
|
61
|
+
;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function extractGithub(plugin: any): string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// module
|
|
4
|
+
function extractGithub(plugin) {
|
|
5
|
+
let github = "";
|
|
6
|
+
if ("object" === typeof plugin) {
|
|
7
|
+
if ("string" === typeof plugin.github) {
|
|
8
|
+
github = plugin.github;
|
|
9
|
+
}
|
|
10
|
+
else if ("string" === typeof plugin.repository) {
|
|
11
|
+
github = plugin.repository;
|
|
12
|
+
}
|
|
13
|
+
else if (plugin.repository && "string" === typeof plugin.repository.url) {
|
|
14
|
+
github = plugin.repository.url;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return github;
|
|
18
|
+
}
|
|
19
|
+
exports.default = extractGithub;
|
|
20
|
+
;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// private
|
|
4
|
+
// methods
|
|
5
|
+
function _initPlugin(plugin, emit, ...data) {
|
|
6
|
+
emit("initializing", plugin, ...data);
|
|
7
|
+
return plugin.init(data).then(() => {
|
|
8
|
+
emit("initialized", plugin, ...data);
|
|
9
|
+
return Promise.resolve();
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
function _initPlugins(pluginsToInit, emit, data, i = 0) {
|
|
13
|
+
return i < pluginsToInit.length ? Promise.resolve().then(() => {
|
|
14
|
+
return _initPlugin(pluginsToInit[i], emit, ...data);
|
|
15
|
+
// loop
|
|
16
|
+
}).then(() => {
|
|
17
|
+
return _initPlugins(pluginsToInit, emit, data, i + 1);
|
|
18
|
+
}) : Promise.resolve();
|
|
19
|
+
}
|
|
20
|
+
// module
|
|
21
|
+
function initSortedPlugins(plugins, orderedPluginsNames, emit, ...data) {
|
|
22
|
+
// if no plugins, does not run
|
|
23
|
+
return !plugins.length ? Promise.resolve() : Promise.resolve().then(() => {
|
|
24
|
+
const sortedPlugins = [
|
|
25
|
+
...plugins.filter((plugin) => {
|
|
26
|
+
return orderedPluginsNames.includes(plugin.name);
|
|
27
|
+
})
|
|
28
|
+
];
|
|
29
|
+
// first, sorted plugins
|
|
30
|
+
return sortedPlugins.length ?
|
|
31
|
+
_initPlugins(sortedPlugins, emit, data) :
|
|
32
|
+
Promise.resolve();
|
|
33
|
+
}).then(() => {
|
|
34
|
+
const unsortedPlugin = [
|
|
35
|
+
...plugins.filter((plugin) => {
|
|
36
|
+
return !orderedPluginsNames.includes(plugin.name);
|
|
37
|
+
}).sort((a, b) => {
|
|
38
|
+
if (a.name < b.name) {
|
|
39
|
+
return -1;
|
|
40
|
+
}
|
|
41
|
+
else if (a.name > b.name) {
|
|
42
|
+
return 1;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
return 0;
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
];
|
|
49
|
+
// then, all other plugins, asynchronously
|
|
50
|
+
return unsortedPlugin.length ?
|
|
51
|
+
_initPlugins(unsortedPlugin, emit, data) :
|
|
52
|
+
Promise.resolve();
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
exports.default = initSortedPlugins;
|
|
56
|
+
;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { Orchestrator, tLogger } from "node-pluginsmanager-plugin";
|
|
2
|
+
export default function loadSortedPlugins(globalDirectory: string, externalRessourcesDirectory: string, files: Array<string>, loadedPlugins: Array<Orchestrator>, orderedPluginsNames: Array<string>, emit: (eventName: string, ...subdata: any) => void, logger: tLogger | null, ...data: any): Promise<void>;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
// deps
|
|
7
|
+
// natives
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
// locals
|
|
10
|
+
const createPluginByDirectory_1 = __importDefault(require("./createPluginByDirectory"));
|
|
11
|
+
// private
|
|
12
|
+
// methods
|
|
13
|
+
function _loadPlugin(globalDirectory, externalRessourcesDirectory, pluginFileName, loadedPlugins, emit, logger, ...data) {
|
|
14
|
+
// is already loaded ?
|
|
15
|
+
const plugin = loadedPlugins.find((p) => {
|
|
16
|
+
return pluginFileName === p.name;
|
|
17
|
+
});
|
|
18
|
+
// is already exists ?
|
|
19
|
+
return plugin ? Promise.resolve() : Promise.resolve().then(() => {
|
|
20
|
+
emit("loading", pluginFileName, ...data);
|
|
21
|
+
const directory = (0, path_1.join)(globalDirectory, pluginFileName);
|
|
22
|
+
return (0, createPluginByDirectory_1.default)(directory, externalRessourcesDirectory, logger);
|
|
23
|
+
// emit event
|
|
24
|
+
}).then((createdPlugin) => {
|
|
25
|
+
emit("loaded", createdPlugin, ...data);
|
|
26
|
+
loadedPlugins.push(createdPlugin);
|
|
27
|
+
return Promise.resolve();
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function _loadPlugins(globalDirectory, externalRessourcesDirectory, pluginsToLoad, loadedPlugins, emit, logger, data, i = 0) {
|
|
31
|
+
return i < pluginsToLoad.length ? Promise.resolve().then(() => {
|
|
32
|
+
return _loadPlugin(globalDirectory, externalRessourcesDirectory, pluginsToLoad[i], loadedPlugins, emit, logger, ...data);
|
|
33
|
+
// loop
|
|
34
|
+
}).then(() => {
|
|
35
|
+
return _loadPlugins(globalDirectory, externalRessourcesDirectory, pluginsToLoad, loadedPlugins, emit, logger, data, i + 1);
|
|
36
|
+
}) : Promise.resolve();
|
|
37
|
+
}
|
|
38
|
+
// module
|
|
39
|
+
function loadSortedPlugins(globalDirectory, externalRessourcesDirectory, files, loadedPlugins, orderedPluginsNames, emit, logger, ...data) {
|
|
40
|
+
// if no files, does not run
|
|
41
|
+
return !files.length ? Promise.resolve() : Promise.resolve().then(() => {
|
|
42
|
+
const sortedPluginsNames = [
|
|
43
|
+
...files.filter((pluginName) => {
|
|
44
|
+
return orderedPluginsNames.includes(pluginName);
|
|
45
|
+
})
|
|
46
|
+
];
|
|
47
|
+
// first, sorted plugins
|
|
48
|
+
return sortedPluginsNames.length ?
|
|
49
|
+
_loadPlugins(globalDirectory, externalRessourcesDirectory, sortedPluginsNames, loadedPlugins, emit, logger, data) :
|
|
50
|
+
Promise.resolve();
|
|
51
|
+
}).then(() => {
|
|
52
|
+
const unsortedPluginsNames = [
|
|
53
|
+
...files.filter((pluginName) => {
|
|
54
|
+
return !orderedPluginsNames.includes(pluginName);
|
|
55
|
+
}).sort((a, b) => {
|
|
56
|
+
if (a < b) {
|
|
57
|
+
return -1;
|
|
58
|
+
}
|
|
59
|
+
else if (a > b) {
|
|
60
|
+
return 1;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
return 0;
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
];
|
|
67
|
+
// then, all other plugins, asynchronously
|
|
68
|
+
return unsortedPluginsNames.length ?
|
|
69
|
+
_loadPlugins(globalDirectory, externalRessourcesDirectory, unsortedPluginsNames, loadedPlugins, emit, logger, data) :
|
|
70
|
+
Promise.resolve();
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
exports.default = loadSortedPlugins;
|
|
74
|
+
;
|
package/lib/cjs/main.cjs
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
// deps
|
|
6
|
+
// locals
|
|
7
|
+
const PluginsManager_1 = __importDefault(require("./PluginsManager"));
|
|
8
|
+
module.exports = PluginsManager_1.default;
|
package/package.json
CHANGED
|
@@ -1,22 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-pluginsmanager",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.1",
|
|
4
4
|
"description": "A plugins manager",
|
|
5
|
-
|
|
6
|
-
"
|
|
5
|
+
|
|
6
|
+
"type": "commonjs",
|
|
7
|
+
"typings": "./lib/cjs/main.d.cts",
|
|
8
|
+
"main": "./lib/cjs/main.cjs",
|
|
9
|
+
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"require": {
|
|
13
|
+
"types": "./lib/cjs/main.d.cts",
|
|
14
|
+
"default": "./lib/cjs/main.cjs"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
|
|
7
19
|
"scripts": {
|
|
8
|
-
|
|
20
|
+
|
|
9
21
|
"check-updates": "npx check-version-modules",
|
|
10
|
-
|
|
11
|
-
"
|
|
22
|
+
|
|
23
|
+
"compile": "npx tsc --project \"./tsconfig.json\"",
|
|
24
|
+
|
|
25
|
+
"unit-tests": "npm run compile && npx nyc --reporter=html --reporter=text mocha",
|
|
26
|
+
"tests": "npm run-script check-updates && npm run-script unit-tests",
|
|
12
27
|
"ci": "npm run-script tests && npx nyc report --reporter=text-lcov | coveralls"
|
|
28
|
+
|
|
13
29
|
},
|
|
30
|
+
|
|
14
31
|
"files": [
|
|
15
32
|
"/lib"
|
|
16
33
|
],
|
|
34
|
+
|
|
17
35
|
"husky": {
|
|
18
36
|
"hooks": {
|
|
19
|
-
"pre-commit": "npm run-script lint",
|
|
20
37
|
"pre-push": "npm run-script tests"
|
|
21
38
|
}
|
|
22
39
|
},
|
|
@@ -39,18 +56,19 @@
|
|
|
39
56
|
"fs-extra": "10.1.0"
|
|
40
57
|
},
|
|
41
58
|
"devDependencies": {
|
|
42
|
-
"@types/
|
|
59
|
+
"@types/express": "4.17.13",
|
|
60
|
+
"@types/fs-extra": "9.0.13",
|
|
61
|
+
"@types/node": "18.0.0",
|
|
43
62
|
"@types/socket.io": "3.0.2",
|
|
44
63
|
"@types/ws": "8.5.3",
|
|
45
64
|
"coveralls": "3.1.1",
|
|
46
|
-
"eslint": "8.16.0",
|
|
47
65
|
"express": "4.18.1",
|
|
48
66
|
"husky": "8.0.1",
|
|
49
67
|
"mocha": "10.0.0",
|
|
50
|
-
"node-pluginsmanager-plugin": "
|
|
68
|
+
"node-pluginsmanager-plugin": "5.0.4",
|
|
51
69
|
"nyc": "15.1.0",
|
|
52
|
-
"typescript": "4.7.
|
|
53
|
-
"ws": "8.
|
|
70
|
+
"typescript": "4.7.4",
|
|
71
|
+
"ws": "8.8.0"
|
|
54
72
|
},
|
|
55
73
|
"homepage": "https://github.com/Psychopoulet/node-pluginsmanager#readme",
|
|
56
74
|
"engines": {
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
// deps
|
|
4
|
-
|
|
5
|
-
// natives
|
|
6
|
-
const { join, isAbsolute } = require("path");
|
|
7
|
-
|
|
8
|
-
// locals
|
|
9
|
-
const isDirectory = require(join(__dirname, "isDirectory.js"));
|
|
10
|
-
|
|
11
|
-
// module
|
|
12
|
-
|
|
13
|
-
module.exports = function isAbsoluteDirectory (dataName, directory) {
|
|
14
|
-
|
|
15
|
-
return isDirectory(dataName, directory).then(() => {
|
|
16
|
-
|
|
17
|
-
return new Promise((resolve, reject) => {
|
|
18
|
-
|
|
19
|
-
return isAbsolute(directory) ? resolve() : reject(new Error(
|
|
20
|
-
"\"" + dataName + "\" (" + directory + ") is not an absolute path"
|
|
21
|
-
));
|
|
22
|
-
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
// deps
|
|
4
|
-
|
|
5
|
-
// natives
|
|
6
|
-
const { join } = require("path");
|
|
7
|
-
const { lstat } = require("fs");
|
|
8
|
-
|
|
9
|
-
// locals
|
|
10
|
-
const isNonEmptyString = require(join(__dirname, "isNonEmptyString.js"));
|
|
11
|
-
|
|
12
|
-
// module
|
|
13
|
-
|
|
14
|
-
module.exports = function isDirectory (dataName, directory) {
|
|
15
|
-
|
|
16
|
-
return isNonEmptyString(dataName, directory).then(() => {
|
|
17
|
-
|
|
18
|
-
return new Promise((resolve) => {
|
|
19
|
-
|
|
20
|
-
lstat(directory, (err, stats) => {
|
|
21
|
-
return resolve(Boolean(!err && stats.isDirectory()));
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
}).then((exists) => {
|
|
27
|
-
|
|
28
|
-
return exists ? Promise.resolve() : Promise.reject(new Error(
|
|
29
|
-
"\"" + dataName + "\" (" + directory + ") is not a valid directory"
|
|
30
|
-
));
|
|
31
|
-
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
// module
|
|
4
|
-
|
|
5
|
-
module.exports = function isFunction (dataName, data) {
|
|
6
|
-
|
|
7
|
-
if ("undefined" === typeof data) {
|
|
8
|
-
return Promise.reject(new ReferenceError("\"" + dataName + "\" parameter is missing"));
|
|
9
|
-
}
|
|
10
|
-
else if ("function" !== typeof data) {
|
|
11
|
-
return Promise.reject(new TypeError("\"" + dataName + "\" parameter is not a function"));
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
else {
|
|
15
|
-
return Promise.resolve();
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
// module
|
|
4
|
-
|
|
5
|
-
module.exports = function isNonEmptyArray (dataName, data) {
|
|
6
|
-
|
|
7
|
-
if ("undefined" === typeof data) {
|
|
8
|
-
return Promise.reject(new ReferenceError("\"" + dataName + "\" parameter is missing"));
|
|
9
|
-
}
|
|
10
|
-
else if ("object" !== typeof data || !(data instanceof Array)) {
|
|
11
|
-
return Promise.reject(new TypeError("\"" + dataName + "\" parameter is not an Array"));
|
|
12
|
-
}
|
|
13
|
-
else if (!data.length) {
|
|
14
|
-
return Promise.reject(new RangeError("\"" + dataName + "\" parameter is empty"));
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
else {
|
|
18
|
-
return Promise.resolve();
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
// module
|
|
4
|
-
|
|
5
|
-
module.exports = function isNonEmptyString (dataName, data) {
|
|
6
|
-
|
|
7
|
-
if ("undefined" === typeof data) {
|
|
8
|
-
return Promise.reject(new ReferenceError("\"" + dataName + "\" parameter is missing"));
|
|
9
|
-
}
|
|
10
|
-
else if ("string" !== typeof data) {
|
|
11
|
-
return Promise.reject(new TypeError("\"" + dataName + "\" parameter is not a string"));
|
|
12
|
-
}
|
|
13
|
-
else if ("" === data.trim()) {
|
|
14
|
-
return Promise.reject(new RangeError("\"" + dataName + "\" parameter is empty"));
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
else {
|
|
18
|
-
return Promise.resolve();
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
};
|