node-pluginsmanager 3.6.1 → 3.7.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/README.md +17 -13
- package/lib/cjs/PluginsManager.d.ts +18 -1
- package/lib/cjs/PluginsManager.js +138 -84
- package/lib/cjs/cmd/isGitUsed.d.ts +1 -0
- package/lib/cjs/cmd/isGitUsed.js +32 -0
- package/package.json +3 -3
- package/lib/cjs/utils/extractGithub.d.ts +0 -7
- package/lib/cjs/utils/extractGithub.js +0 -20
package/README.md
CHANGED
|
@@ -48,23 +48,27 @@ $ npm install node-pluginsmanager
|
|
|
48
48
|
|
|
49
49
|
* ``` on("error", (err: Error) => void) : this ``` fires if an error occurs
|
|
50
50
|
|
|
51
|
-
* ``` on("loading", (
|
|
52
|
-
* ``` on("loaded", (plugin: Orchestrator,
|
|
53
|
-
* ``` on("allloaded", (
|
|
51
|
+
* ``` on("loading", (pluginName: string, ...unknown[]) => void) : this ``` fires if a plugin starts load
|
|
52
|
+
* ``` on("loaded", (plugin: Orchestrator, ...unknown[]) => void) : this ``` fires if a plugin ends load
|
|
53
|
+
* ``` on("allloaded", (...unknown[]) => void) : this ``` fires if all the plugins are loaded
|
|
54
54
|
|
|
55
|
-
* ``` on("initializing", (plugin: Orchestrator,
|
|
56
|
-
* ``` on("initialized", (plugin: Orchestrator,
|
|
57
|
-
* ``` on("allinitialized", (
|
|
55
|
+
* ``` on("initializing", (plugin: Orchestrator, ...unknown[]) => void) : this ``` fires if a plugin starts init
|
|
56
|
+
* ``` on("initialized", (plugin: Orchestrator, ...unknown[]) => void) : this ``` fires if a plugin ends init
|
|
57
|
+
* ``` on("allinitialized", (...unknown[]) => void) : this ``` fires if all the plugins are initialized
|
|
58
58
|
|
|
59
|
-
* ``` on("released", (plugin: Orchestrator,
|
|
60
|
-
* ``` on("allreleased", (
|
|
59
|
+
* ``` on("released", (plugin: Orchestrator, ...unknown[]) => void) : this ``` fires if a plugin is released
|
|
60
|
+
* ``` on("allreleased", (...unknown[]) => void) : this ``` fires if all the plugins are released
|
|
61
61
|
|
|
62
|
-
* ``` on("destroyed", (pluginName: string,
|
|
63
|
-
* ``` on("alldestroyed", (
|
|
62
|
+
* ``` on("destroyed", (pluginName: string, ...unknown[]) => void) : this ``` fires if a plugin is destroyed
|
|
63
|
+
* ``` on("alldestroyed", (...unknown[]) => void) : this ``` fires if all the plugins are destroyed
|
|
64
64
|
|
|
65
|
-
* ``` on("
|
|
66
|
-
* ``` on("
|
|
67
|
-
|
|
65
|
+
* ``` on("installing", (pluginName: string, currentStep: number, maxSteps: number, stepDescription: string, ...unknown[]) => void) : this ``` fires with plugin installation progress
|
|
66
|
+
* ``` on("installed", (plugin: Orchestrator, ...unknown[]) => void) : this ``` fires if a plugin is installed
|
|
67
|
+
|
|
68
|
+
* ``` on("updating", (pluginName: string, currentStep: number, maxSteps: number, stepDescription: string, ...unknown[]) => void) : this ``` fires with plugin update progress
|
|
69
|
+
* ``` on("updated", (plugin: Orchestrator, ...unknown[]) => void) : this ``` fires if a plugin is updated
|
|
70
|
+
|
|
71
|
+
* ``` on("uninstalled", (pluginName: string, ...unknown[]) => void) : this ``` fires if a plugin is uninstalled
|
|
68
72
|
|
|
69
73
|
## Examples
|
|
70
74
|
|
|
@@ -9,7 +9,23 @@ interface iPluginManagerOptions {
|
|
|
9
9
|
"logger"?: tLogger | null;
|
|
10
10
|
}
|
|
11
11
|
type tBeforeAllMethodCallback = (...data: unknown[]) => Promise<void> | void;
|
|
12
|
-
export default class PluginsManager extends EventEmitter
|
|
12
|
+
export default class PluginsManager extends EventEmitter<{
|
|
13
|
+
"loading": [string, ...unknown[]];
|
|
14
|
+
"loaded": [Orchestrator, ...unknown[]];
|
|
15
|
+
"allloaded": [...unknown[]];
|
|
16
|
+
"initializing": [Orchestrator, ...unknown[]];
|
|
17
|
+
"initialized": [Orchestrator, ...unknown[]];
|
|
18
|
+
"allinitialized": [...unknown[]];
|
|
19
|
+
"released": [Orchestrator, ...unknown[]];
|
|
20
|
+
"allreleased": [...unknown[]];
|
|
21
|
+
"destroyed": [string, ...unknown[]];
|
|
22
|
+
"alldestroyed": [...unknown[]];
|
|
23
|
+
"installing": [string, number, number, string, ...unknown[]];
|
|
24
|
+
"installed": [Orchestrator, ...unknown[]];
|
|
25
|
+
"updating": [string, number, number, string, ...unknown[]];
|
|
26
|
+
"updated": [Orchestrator, ...unknown[]];
|
|
27
|
+
"uninstalled": [string, ...unknown[]];
|
|
28
|
+
}> {
|
|
13
29
|
protected _beforeLoadAll: tBeforeAllMethodCallback | null;
|
|
14
30
|
protected _beforeInitAll: tBeforeAllMethodCallback | null;
|
|
15
31
|
protected _logger: tLogger | null;
|
|
@@ -33,6 +49,7 @@ export default class PluginsManager extends EventEmitter {
|
|
|
33
49
|
releaseAll(...data: unknown[]): Promise<void>;
|
|
34
50
|
getLatestGithubTag(plugin: Orchestrator): Promise<string>;
|
|
35
51
|
installViaGithub(user: string, repo: string, ...data: unknown[]): Promise<Orchestrator>;
|
|
52
|
+
private _updateWithoutGit;
|
|
36
53
|
updateViaGithub(plugin: Orchestrator, ...data: unknown[]): Promise<Orchestrator>;
|
|
37
54
|
uninstall(plugin: Orchestrator, ...data: unknown[]): Promise<string>;
|
|
38
55
|
}
|
|
@@ -25,9 +25,9 @@ const isFile_1 = __importDefault(require("./utils/isFile"));
|
|
|
25
25
|
const createPluginByDirectory_1 = __importDefault(require("./createPluginByDirectory"));
|
|
26
26
|
const loadSortedPlugins_1 = __importDefault(require("./loadSortedPlugins"));
|
|
27
27
|
const initSortedPlugins_1 = __importDefault(require("./initSortedPlugins"));
|
|
28
|
-
const extractGithub_1 = __importDefault(require("./utils/extractGithub"));
|
|
29
28
|
const getLatestGithubTag_1 = __importDefault(require("./utils/getLatestGithubTag"));
|
|
30
29
|
const parseGithubUserRepo_1 = __importDefault(require("./utils/parseGithubUserRepo"));
|
|
30
|
+
const isGitUsed_1 = __importDefault(require("./cmd/isGitUsed"));
|
|
31
31
|
// git
|
|
32
32
|
const gitInstall_1 = __importDefault(require("./cmd/git/gitInstall"));
|
|
33
33
|
const gitUpdate_1 = __importDefault(require("./cmd/git/gitUpdate"));
|
|
@@ -223,8 +223,9 @@ class PluginsManager extends node_events_1.default {
|
|
|
223
223
|
// after releasing, destroy packages data & free "plugins" list, using "data" in arguments for "destroy" plugin's Orchestrator method
|
|
224
224
|
destroyAll(...data) {
|
|
225
225
|
return Promise.all(this.plugins.map((plugin) => {
|
|
226
|
-
|
|
227
|
-
|
|
226
|
+
const pluginName = plugin.name;
|
|
227
|
+
return plugin.destroy(...data).then(() => {
|
|
228
|
+
this.emit("destroyed", pluginName, ...data);
|
|
228
229
|
});
|
|
229
230
|
})).then(() => {
|
|
230
231
|
this.plugins = [];
|
|
@@ -272,7 +273,7 @@ class PluginsManager extends node_events_1.default {
|
|
|
272
273
|
}
|
|
273
274
|
getLatestGithubTag(plugin) {
|
|
274
275
|
return (0, checkOrchestrator_1.default)("getLatestGithubTag/plugin", plugin).then(() => {
|
|
275
|
-
const githubUserRepo = (0, parseGithubUserRepo_1.default)(
|
|
276
|
+
const githubUserRepo = (0, parseGithubUserRepo_1.default)(plugin.repository);
|
|
276
277
|
if (!githubUserRepo) {
|
|
277
278
|
throw new Error("Plugin \"" + plugin.name + "\" has an invalid github project link");
|
|
278
279
|
}
|
|
@@ -283,15 +284,17 @@ class PluginsManager extends node_events_1.default {
|
|
|
283
284
|
}
|
|
284
285
|
// install a plugin via github repo, using "data" in arguments for "install" and "init" plugin's Orchestrator methods
|
|
285
286
|
installViaGithub(user, repo, ...data) {
|
|
287
|
+
const MAX_INSTALL_STEPS = 10;
|
|
288
|
+
let pluginName = repo;
|
|
286
289
|
return (0, checkAbsoluteDirectory_1.default)("installViaGithub/directory", this.directory).then(() => {
|
|
287
290
|
return (0, checkNonEmptyString_1.default)("installViaGithub/user", user);
|
|
288
291
|
}).then(() => {
|
|
289
|
-
return (0, checkNonEmptyString_1.default)("installViaGithub/repo",
|
|
292
|
+
return (0, checkNonEmptyString_1.default)("installViaGithub/repo", pluginName);
|
|
290
293
|
}).then(() => {
|
|
291
|
-
const directory = (0, node_path_1.join)(this.directory,
|
|
294
|
+
const directory = (0, node_path_1.join)(this.directory, pluginName);
|
|
292
295
|
return new Promise((resolve, reject) => {
|
|
293
296
|
(0, checkAbsoluteDirectory_1.default)("installViaGithub/plugindirectory", directory).then(() => {
|
|
294
|
-
return reject(new Error("\"" +
|
|
297
|
+
return reject(new Error("\"" + pluginName + "\" plugin already exists"));
|
|
295
298
|
}).catch(() => {
|
|
296
299
|
return resolve(directory);
|
|
297
300
|
});
|
|
@@ -299,15 +302,16 @@ class PluginsManager extends node_events_1.default {
|
|
|
299
302
|
}).then((directory) => {
|
|
300
303
|
// download plugin
|
|
301
304
|
return Promise.resolve().then(() => {
|
|
302
|
-
this._logger?.("info", "Downloading plugin...", false,
|
|
303
|
-
|
|
304
|
-
|
|
305
|
+
this._logger?.("info", "Downloading plugin...", false, pluginName);
|
|
306
|
+
this.emit("installing", pluginName, 1, MAX_INSTALL_STEPS, "Downloading plugin...");
|
|
307
|
+
return (0, gitInstall_1.default)(directory, user, pluginName).then(() => {
|
|
308
|
+
this._logger?.("success", "Download success", false, pluginName);
|
|
305
309
|
});
|
|
306
310
|
// check if plugin directory is created
|
|
307
311
|
}).then(() => {
|
|
308
312
|
return (0, isDirectory_1.default)(directory).then((isPluginADirectory) => {
|
|
309
313
|
if (!isPluginADirectory) {
|
|
310
|
-
throw new Error("\"" +
|
|
314
|
+
throw new Error("\"" + pluginName + "\" plugin directory is not created");
|
|
311
315
|
}
|
|
312
316
|
});
|
|
313
317
|
// work around package.json
|
|
@@ -316,22 +320,24 @@ class PluginsManager extends node_events_1.default {
|
|
|
316
320
|
// check if plugin has a valid package.json
|
|
317
321
|
return (0, isFile_1.default)(packageFile).then((isPluginAPackageFile) => {
|
|
318
322
|
if (!isPluginAPackageFile) {
|
|
319
|
-
throw new Error("\"" +
|
|
323
|
+
throw new Error("\"" + pluginName + "\" plugin has no valid package.json");
|
|
320
324
|
}
|
|
321
325
|
// read package.json and parse it
|
|
322
326
|
}).then(() => {
|
|
327
|
+
this._logger?.("debug", "Reading package.json...", false, pluginName);
|
|
328
|
+
this.emit("installing", pluginName, 2, MAX_INSTALL_STEPS, "Reading package.json...");
|
|
323
329
|
return (0, promises_1.readFile)(packageFile, "utf-8").then((content) => {
|
|
324
330
|
return JSON.parse(content);
|
|
325
331
|
});
|
|
326
332
|
}).then((packageData) => {
|
|
327
333
|
// check if the plugin has a valid name
|
|
328
334
|
if ("string" !== typeof packageData.name || "" === packageData.name.trim()) {
|
|
329
|
-
throw new Error("\"" +
|
|
335
|
+
throw new Error("\"" + pluginName + "\" plugin has no valid name");
|
|
330
336
|
}
|
|
331
|
-
|
|
337
|
+
pluginName = packageData.name;
|
|
332
338
|
// check if the plugin has a valid entry point
|
|
333
339
|
if ("string" !== typeof packageData.main || "" === packageData.main.trim()) {
|
|
334
|
-
throw new Error("\"" +
|
|
340
|
+
throw new Error("\"" + pluginName + "\" plugin has no valid entry point");
|
|
335
341
|
}
|
|
336
342
|
const entryPoint = (0, node_path_1.join)(directory, packageData.main);
|
|
337
343
|
// check if the plugin is builded (build it if needed)
|
|
@@ -342,21 +348,24 @@ class PluginsManager extends node_events_1.default {
|
|
|
342
348
|
}
|
|
343
349
|
// check if the plugin has a build script
|
|
344
350
|
if ("object" !== typeof packageData.scripts || null === packageData.scripts || 0 >= Object.keys(packageData.scripts).length) {
|
|
345
|
-
throw new Error("\"" +
|
|
351
|
+
throw new Error("\"" + pluginName + "\" plugin has no scripts registered");
|
|
346
352
|
}
|
|
347
353
|
const scripts = packageData.scripts;
|
|
348
354
|
if ("string" !== typeof scripts.build || "" === scripts.build.trim()) {
|
|
349
|
-
throw new Error("\"" +
|
|
355
|
+
throw new Error("\"" + pluginName + "\" plugin has no build script registered");
|
|
350
356
|
}
|
|
351
357
|
this._logger?.("info", "Installing dev dependencies...", false, pluginName);
|
|
358
|
+
this.emit("installing", pluginName, 3, MAX_INSTALL_STEPS, "Installing dev dependencies...");
|
|
352
359
|
// install plugin with dependencies
|
|
353
360
|
return (0, npmInstall_1.default)(directory, true).then(() => {
|
|
354
361
|
this._logger?.("success", "Plugin installed successfully", false, pluginName);
|
|
355
362
|
this._logger?.("info", "Building plugin...", false, pluginName);
|
|
363
|
+
this.emit("installing", pluginName, 4, MAX_INSTALL_STEPS, "Building plugin...");
|
|
356
364
|
return (0, npmBuild_1.default)(directory);
|
|
357
365
|
// remove dev dependencies
|
|
358
366
|
}).then(() => {
|
|
359
367
|
this._logger?.("debug", "Removing dev dependencies...", false, pluginName);
|
|
368
|
+
this.emit("installing", pluginName, 5, MAX_INSTALL_STEPS, "Removing dev dependencies...");
|
|
360
369
|
return (0, rmdirp_1.default)((0, node_path_1.join)(directory, "node_modules")).then(() => {
|
|
361
370
|
this._logger?.("success", "Dev dependencies removed successfully", false, pluginName);
|
|
362
371
|
});
|
|
@@ -365,7 +374,8 @@ class PluginsManager extends node_events_1.default {
|
|
|
365
374
|
if ("object" !== typeof packageData.dependencies || null === packageData.dependencies || 0 >= Object.keys(packageData.dependencies).length) {
|
|
366
375
|
return Promise.resolve();
|
|
367
376
|
}
|
|
368
|
-
this._logger?.("debug", "Installing dependencies...", false, pluginName);
|
|
377
|
+
this._logger?.("debug", "Installing plugin dependencies...", false, pluginName);
|
|
378
|
+
this.emit("installing", pluginName, 6, MAX_INSTALL_STEPS, "Installing plugin dependencies...");
|
|
369
379
|
return (0, npmInstall_1.default)(directory).then(() => {
|
|
370
380
|
this._logger?.("success", "Dependencies installed successfully", false, pluginName);
|
|
371
381
|
});
|
|
@@ -373,20 +383,28 @@ class PluginsManager extends node_events_1.default {
|
|
|
373
383
|
});
|
|
374
384
|
// create plugin
|
|
375
385
|
}).then(() => {
|
|
386
|
+
this._logger?.("debug", "Creating plugin...", false, pluginName);
|
|
387
|
+
this.emit("installing", pluginName, 7, MAX_INSTALL_STEPS, "Creating plugin...");
|
|
376
388
|
return (0, createPluginByDirectory_1.default)(directory, this.externalResourcesDirectory, this._logger, ...data);
|
|
377
389
|
// check plugin modules versions
|
|
378
390
|
}).then((plugin) => {
|
|
391
|
+
this._logger?.("debug", "Checking plugin modules versions...", false, pluginName);
|
|
392
|
+
this.emit("installing", pluginName, 8, MAX_INSTALL_STEPS, "Checking plugin modules versions...");
|
|
379
393
|
return this.checkModules(plugin).then(() => {
|
|
380
394
|
return Promise.resolve(plugin);
|
|
381
395
|
});
|
|
382
396
|
}).then((plugin) => {
|
|
383
397
|
// execute plugin install script
|
|
384
398
|
return Promise.resolve().then(() => {
|
|
399
|
+
this._logger?.("debug", "Executing plugin install script...", false, pluginName);
|
|
400
|
+
this.emit("installing", pluginName, 9, MAX_INSTALL_STEPS, "Executing plugin install script...");
|
|
385
401
|
return plugin.install(...data).then(() => {
|
|
386
402
|
this.emit("installed", plugin, ...data);
|
|
387
403
|
});
|
|
388
404
|
// execute init plugin script
|
|
389
405
|
}).then(() => {
|
|
406
|
+
this._logger?.("debug", "Executing plugin init script...", false, pluginName);
|
|
407
|
+
this.emit("installing", pluginName, 10, MAX_INSTALL_STEPS, "Executing plugin init script...");
|
|
390
408
|
return plugin.init(...data).then(() => {
|
|
391
409
|
this.emit("initialized", plugin, ...data);
|
|
392
410
|
this.plugins.push(plugin);
|
|
@@ -410,105 +428,139 @@ class PluginsManager extends node_events_1.default {
|
|
|
410
428
|
});
|
|
411
429
|
});
|
|
412
430
|
}
|
|
431
|
+
_updateWithoutGit(directory, githubRepository) {
|
|
432
|
+
return (0, promises_1.rm)(directory, {
|
|
433
|
+
"recursive": true,
|
|
434
|
+
"force": true
|
|
435
|
+
}).then(() => {
|
|
436
|
+
const githubUserRepo = (0, parseGithubUserRepo_1.default)(githubRepository);
|
|
437
|
+
if (!githubUserRepo) {
|
|
438
|
+
throw new Error("Plugin has an invalid github project link");
|
|
439
|
+
}
|
|
440
|
+
const { user, repo } = githubUserRepo;
|
|
441
|
+
return (0, gitInstall_1.default)(directory, user, repo);
|
|
442
|
+
});
|
|
443
|
+
}
|
|
413
444
|
// update a plugin via its github repo, using "data" in arguments for "release", "update" and "init" plugin's methods
|
|
414
445
|
updateViaGithub(plugin, ...data) {
|
|
415
446
|
let directory = "";
|
|
416
|
-
let
|
|
447
|
+
let pluginName = "";
|
|
448
|
+
let githubRepository = "";
|
|
417
449
|
// check plugin
|
|
418
450
|
return (0, checkOrchestrator_1.default)("updateViaGithub/plugin", plugin).then(() => {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
throw new Error("Plugin \"" + plugin.name + "\" is not registered");
|
|
451
|
+
pluginName = plugin.name;
|
|
452
|
+
githubRepository = plugin.repository;
|
|
453
|
+
if (!this.getPluginsNames().includes(pluginName)) {
|
|
454
|
+
throw new Error("Plugin \"" + pluginName + "\" is not registered");
|
|
424
455
|
}
|
|
425
456
|
// check plugin directory
|
|
426
457
|
}).then(() => {
|
|
427
458
|
return (0, checkAbsoluteDirectory_1.default)("updateViaGithub/directory", this.directory).then(() => {
|
|
428
|
-
directory = (0, node_path_1.join)(this.directory,
|
|
459
|
+
directory = (0, node_path_1.join)(this.directory, pluginName);
|
|
429
460
|
return (0, checkAbsoluteDirectory_1.default)("updateViaGithub/plugindirectory", directory);
|
|
430
461
|
});
|
|
431
|
-
// check remote version
|
|
432
462
|
}).then(() => {
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
throw new Error("No valid version found for plugin \"" + plugin.name + "\" on github");
|
|
442
|
-
}
|
|
443
|
-
this._logger?.("debug", "Compare local version with github lastest tag", false, plugin.name);
|
|
444
|
-
if (!semver_1.default.gt(latestVersion, currentVersion)) {
|
|
445
|
-
throw new Error("Plugin \"" + plugin.name + "\" is already up to date (v" + plugin.version + ")");
|
|
463
|
+
return (0, isGitUsed_1.default)(directory);
|
|
464
|
+
}).then((gitUsed) => {
|
|
465
|
+
const MAX_UPDATE_STEPS = 7;
|
|
466
|
+
// check remote version
|
|
467
|
+
return Promise.resolve().then(() => {
|
|
468
|
+
const currentVersion = semver_1.default.coerce(plugin.version);
|
|
469
|
+
if (!currentVersion) {
|
|
470
|
+
throw new Error("Plugin \"" + pluginName + "\" has no valid version (\"" + plugin.version + "\")");
|
|
446
471
|
}
|
|
447
|
-
this._logger?.("
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
472
|
+
this._logger?.("debug", "Get github latest tag", false, pluginName);
|
|
473
|
+
this.emit("updating", pluginName, 1, MAX_UPDATE_STEPS, "Getting github latest tag...");
|
|
474
|
+
return this.getLatestGithubTag(plugin).then((tag) => {
|
|
475
|
+
const latestVersion = semver_1.default.coerce(tag);
|
|
476
|
+
if (!latestVersion) {
|
|
477
|
+
throw new Error("No valid version found for plugin \"" + pluginName + "\" on github");
|
|
478
|
+
}
|
|
479
|
+
this._logger?.("debug", "Compare local version with github latest tag", false, pluginName);
|
|
480
|
+
if (!semver_1.default.gt(latestVersion, currentVersion)) {
|
|
481
|
+
throw new Error("Plugin \"" + pluginName + "\" is already up to date (v" + plugin.version + ")");
|
|
482
|
+
}
|
|
483
|
+
this._logger?.("success", "New version available", false, pluginName);
|
|
484
|
+
return tag;
|
|
485
|
+
});
|
|
486
|
+
// release plugin
|
|
487
|
+
}).then((latestTag) => {
|
|
488
|
+
this._logger?.("debug", "Releasing plugin...", false, pluginName);
|
|
489
|
+
this.emit("updating", pluginName, 2, MAX_UPDATE_STEPS, "Releasing plugin...");
|
|
490
|
+
const key = this.plugins.indexOf(plugin);
|
|
491
|
+
return plugin.release(...data).then(() => {
|
|
492
|
+
this.emit("released", plugin, ...data);
|
|
493
|
+
return plugin.destroy(...data);
|
|
494
|
+
}).then(() => {
|
|
495
|
+
this.emit("destroyed", pluginName, ...data);
|
|
496
|
+
if (-1 < key) {
|
|
497
|
+
this.plugins.splice(key, 1);
|
|
498
|
+
}
|
|
499
|
+
return latestTag;
|
|
500
|
+
});
|
|
501
|
+
// update plugin
|
|
502
|
+
}).then((latestTag) => {
|
|
503
|
+
this._logger?.("debug", "Update with new plugin version", false, pluginName);
|
|
504
|
+
this.emit("updating", pluginName, 3, MAX_UPDATE_STEPS, "Updating plugin with new version...");
|
|
505
|
+
return gitUsed
|
|
506
|
+
? (0, gitUpdate_1.default)(directory, latestTag)
|
|
507
|
+
: this._updateWithoutGit(directory, githubRepository);
|
|
508
|
+
// after update, create plugin
|
|
456
509
|
}).then(() => {
|
|
457
|
-
this.
|
|
458
|
-
this.
|
|
459
|
-
return latestTag;
|
|
460
|
-
});
|
|
461
|
-
// update plugin
|
|
462
|
-
}).then((latestTag) => {
|
|
463
|
-
this._logger?.("debug", "Update with new plugin version", false, plugin.name);
|
|
464
|
-
return (0, gitUpdate_1.default)(directory, latestTag).then(() => {
|
|
510
|
+
this._logger?.("debug", "Creating plugin...", false, pluginName);
|
|
511
|
+
this.emit("updating", pluginName, 4, MAX_UPDATE_STEPS, "Creating plugin...");
|
|
465
512
|
return (0, createPluginByDirectory_1.default)(directory, this.externalResourcesDirectory, this._logger, ...data);
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
})
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
513
|
+
// check plugin modules versions
|
|
514
|
+
}).then((_plugin) => {
|
|
515
|
+
this._logger?.("debug", "Check modules", false, pluginName);
|
|
516
|
+
return this.checkModules(_plugin).then(() => {
|
|
517
|
+
return _plugin;
|
|
518
|
+
});
|
|
519
|
+
}).then((_plugin) => {
|
|
520
|
+
// update dependencies & execute update script
|
|
521
|
+
return Promise.resolve().then(() => {
|
|
522
|
+
this._logger?.("debug", "Updating dependencies...", false, pluginName);
|
|
523
|
+
this.emit("updating", pluginName, 5, MAX_UPDATE_STEPS, "Updating dependencies...");
|
|
524
|
+
return !_plugin.dependencies ? Promise.resolve() : (0, npmUpdate_1.default)(directory);
|
|
525
|
+
}).then(() => {
|
|
526
|
+
this._logger?.("debug", "Executing plugin update script...", false, pluginName);
|
|
527
|
+
this.emit("updating", pluginName, 6, MAX_UPDATE_STEPS, "Executing plugin update script...");
|
|
528
|
+
return _plugin.update(...data);
|
|
529
|
+
}).then(() => {
|
|
530
|
+
this._logger?.("debug", "Executing plugin init script...", false, pluginName);
|
|
531
|
+
this.emit("updating", pluginName, 7, MAX_UPDATE_STEPS, "Executing plugin init script...");
|
|
532
|
+
this.emit("updated", _plugin, ...data);
|
|
533
|
+
return _plugin.init(...data);
|
|
534
|
+
// execute init script
|
|
535
|
+
}).then(() => {
|
|
536
|
+
this.emit("initialized", _plugin, ...data);
|
|
537
|
+
this.plugins.push(_plugin);
|
|
538
|
+
return _plugin;
|
|
539
|
+
});
|
|
487
540
|
});
|
|
488
541
|
});
|
|
489
542
|
}
|
|
490
543
|
// uninstall a plugin, using "data" in arguments for "release" and "uninstall" plugin's methods
|
|
491
544
|
uninstall(plugin, ...data) {
|
|
492
545
|
let directory = "";
|
|
493
|
-
let key = -1;
|
|
494
546
|
let pluginName = "";
|
|
495
547
|
// check plugin
|
|
496
548
|
return Promise.resolve().then(() => {
|
|
497
549
|
return (0, checkOrchestrator_1.default)("uninstall/plugin", plugin).then(() => {
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
550
|
+
pluginName = plugin.name;
|
|
551
|
+
if (!this.getPluginsNames().includes(pluginName)) {
|
|
552
|
+
throw new Error("Plugin \"" + pluginName + "\" is not registered");
|
|
553
|
+
}
|
|
502
554
|
});
|
|
503
555
|
// check plugin directory
|
|
504
556
|
}).then(() => {
|
|
505
557
|
return (0, checkAbsoluteDirectory_1.default)("uninstall/directory", this.directory).then(() => {
|
|
506
|
-
pluginName = plugin.name;
|
|
507
558
|
directory = (0, node_path_1.join)(this.directory, pluginName);
|
|
508
559
|
return (0, checkAbsoluteDirectory_1.default)("uninstall/plugindirectory", directory);
|
|
509
560
|
});
|
|
510
561
|
// release plugin
|
|
511
562
|
}).then(() => {
|
|
563
|
+
const key = this.plugins.indexOf(plugin);
|
|
512
564
|
return plugin.release(...data).then(() => {
|
|
513
565
|
return (0, rmdirp_1.default)((0, node_path_1.join)(this.externalResourcesDirectory, pluginName));
|
|
514
566
|
}).then(() => {
|
|
@@ -516,7 +568,9 @@ class PluginsManager extends node_events_1.default {
|
|
|
516
568
|
return plugin.destroy(...data);
|
|
517
569
|
}).then(() => {
|
|
518
570
|
this.emit("destroyed", pluginName, ...data);
|
|
519
|
-
|
|
571
|
+
if (-1 < key) {
|
|
572
|
+
this.plugins.splice(key, 1);
|
|
573
|
+
}
|
|
520
574
|
});
|
|
521
575
|
// update dependencies & execute update script
|
|
522
576
|
}).then(() => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function isGitUsed(directory: string): Promise<boolean>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// deps
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.default = isGitUsed;
|
|
8
|
+
// natives
|
|
9
|
+
const node_path_1 = require("node:path");
|
|
10
|
+
// locals
|
|
11
|
+
const cmd_1 = __importDefault(require("./cmd"));
|
|
12
|
+
const isDirectory_1 = __importDefault(require("../utils/isDirectory"));
|
|
13
|
+
// module
|
|
14
|
+
function isGitUsed(directory) {
|
|
15
|
+
return (0, isDirectory_1.default)((0, node_path_1.join)(directory, ".git")).then((check) => {
|
|
16
|
+
if (!check) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
return new Promise((resolve) => {
|
|
20
|
+
(0, cmd_1.default)(directory, "git", [
|
|
21
|
+
"rev-parse",
|
|
22
|
+
"-q",
|
|
23
|
+
"--verify",
|
|
24
|
+
"HEAD"
|
|
25
|
+
]).then(() => {
|
|
26
|
+
resolve(true);
|
|
27
|
+
}).catch(() => {
|
|
28
|
+
resolve(false);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
|
|
3
3
|
"name": "node-pluginsmanager",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.7.0",
|
|
5
5
|
"description": "A plugins manager.",
|
|
6
6
|
|
|
7
7
|
"type": "commonjs",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@types/express": "5.0.6",
|
|
56
|
-
"@types/node": "26.
|
|
56
|
+
"@types/node": "26.1.1",
|
|
57
57
|
"@types/semver": "7.7.1",
|
|
58
58
|
"@types/socket.io": "3.0.2",
|
|
59
59
|
"@types/ws": "8.18.1",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"express": "5.2.1",
|
|
62
62
|
"husky": "9.1.7",
|
|
63
63
|
"mocha": "11.7.6",
|
|
64
|
-
"node-pluginsmanager-plugin": "7.4.
|
|
64
|
+
"node-pluginsmanager-plugin": "7.4.2",
|
|
65
65
|
"nyc": "18.0.0",
|
|
66
66
|
"proxyquire": "2.1.3",
|
|
67
67
|
"rimraf": "6.1.3",
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Orchestrator } from "node-pluginsmanager-plugin";
|
|
2
|
-
interface OrchestratorExtended extends Orchestrator {
|
|
3
|
-
"github"?: string;
|
|
4
|
-
"repository"?: string | Record<string, string>;
|
|
5
|
-
}
|
|
6
|
-
export default function extractGithub(plugin: OrchestratorExtended): string | null;
|
|
7
|
-
export {};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// types & interfaces
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.default = extractGithub;
|
|
5
|
-
// module
|
|
6
|
-
function extractGithub(plugin) {
|
|
7
|
-
let github = null;
|
|
8
|
-
if ("object" === typeof plugin) {
|
|
9
|
-
if ("string" === typeof plugin.github) {
|
|
10
|
-
github = plugin.github;
|
|
11
|
-
}
|
|
12
|
-
else if ("string" === typeof plugin.repository) {
|
|
13
|
-
github = plugin.repository;
|
|
14
|
-
}
|
|
15
|
-
else if ("object" === typeof plugin.repository && "string" === typeof plugin.repository.url) {
|
|
16
|
-
github = plugin.repository.url;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return github ?? null;
|
|
20
|
-
}
|