node-pluginsmanager 3.6.2 → 3.7.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/README.md +17 -13
- package/lib/cjs/PluginsManager.d.ts +18 -1
- package/lib/cjs/PluginsManager.js +128 -75
- package/lib/cjs/cmd/isGitUsed.d.ts +1 -0
- package/lib/cjs/cmd/isGitUsed.js +32 -0
- package/package.json +4 -4
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
|
}
|
|
@@ -27,6 +27,7 @@ const loadSortedPlugins_1 = __importDefault(require("./loadSortedPlugins"));
|
|
|
27
27
|
const initSortedPlugins_1 = __importDefault(require("./initSortedPlugins"));
|
|
28
28
|
const getLatestGithubTag_1 = __importDefault(require("./utils/getLatestGithubTag"));
|
|
29
29
|
const parseGithubUserRepo_1 = __importDefault(require("./utils/parseGithubUserRepo"));
|
|
30
|
+
const isGitUsed_1 = __importDefault(require("./cmd/isGitUsed"));
|
|
30
31
|
// git
|
|
31
32
|
const gitInstall_1 = __importDefault(require("./cmd/git/gitInstall"));
|
|
32
33
|
const gitUpdate_1 = __importDefault(require("./cmd/git/gitUpdate"));
|
|
@@ -222,8 +223,9 @@ class PluginsManager extends node_events_1.default {
|
|
|
222
223
|
// after releasing, destroy packages data & free "plugins" list, using "data" in arguments for "destroy" plugin's Orchestrator method
|
|
223
224
|
destroyAll(...data) {
|
|
224
225
|
return Promise.all(this.plugins.map((plugin) => {
|
|
226
|
+
const pluginName = plugin.name;
|
|
225
227
|
return plugin.destroy(...data).then(() => {
|
|
226
|
-
this.emit("destroyed",
|
|
228
|
+
this.emit("destroyed", pluginName, ...data);
|
|
227
229
|
});
|
|
228
230
|
})).then(() => {
|
|
229
231
|
this.plugins = [];
|
|
@@ -282,15 +284,17 @@ class PluginsManager extends node_events_1.default {
|
|
|
282
284
|
}
|
|
283
285
|
// install a plugin via github repo, using "data" in arguments for "install" and "init" plugin's Orchestrator methods
|
|
284
286
|
installViaGithub(user, repo, ...data) {
|
|
287
|
+
const MAX_INSTALL_STEPS = 10;
|
|
288
|
+
let pluginName = repo;
|
|
285
289
|
return (0, checkAbsoluteDirectory_1.default)("installViaGithub/directory", this.directory).then(() => {
|
|
286
290
|
return (0, checkNonEmptyString_1.default)("installViaGithub/user", user);
|
|
287
291
|
}).then(() => {
|
|
288
|
-
return (0, checkNonEmptyString_1.default)("installViaGithub/repo",
|
|
292
|
+
return (0, checkNonEmptyString_1.default)("installViaGithub/repo", pluginName);
|
|
289
293
|
}).then(() => {
|
|
290
|
-
const directory = (0, node_path_1.join)(this.directory,
|
|
294
|
+
const directory = (0, node_path_1.join)(this.directory, pluginName);
|
|
291
295
|
return new Promise((resolve, reject) => {
|
|
292
296
|
(0, checkAbsoluteDirectory_1.default)("installViaGithub/plugindirectory", directory).then(() => {
|
|
293
|
-
return reject(new Error("\"" +
|
|
297
|
+
return reject(new Error("\"" + pluginName + "\" plugin already exists"));
|
|
294
298
|
}).catch(() => {
|
|
295
299
|
return resolve(directory);
|
|
296
300
|
});
|
|
@@ -298,15 +302,16 @@ class PluginsManager extends node_events_1.default {
|
|
|
298
302
|
}).then((directory) => {
|
|
299
303
|
// download plugin
|
|
300
304
|
return Promise.resolve().then(() => {
|
|
301
|
-
this._logger?.("info", "Downloading plugin...", false,
|
|
302
|
-
|
|
303
|
-
|
|
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);
|
|
304
309
|
});
|
|
305
310
|
// check if plugin directory is created
|
|
306
311
|
}).then(() => {
|
|
307
312
|
return (0, isDirectory_1.default)(directory).then((isPluginADirectory) => {
|
|
308
313
|
if (!isPluginADirectory) {
|
|
309
|
-
throw new Error("\"" +
|
|
314
|
+
throw new Error("\"" + pluginName + "\" plugin directory is not created");
|
|
310
315
|
}
|
|
311
316
|
});
|
|
312
317
|
// work around package.json
|
|
@@ -315,22 +320,24 @@ class PluginsManager extends node_events_1.default {
|
|
|
315
320
|
// check if plugin has a valid package.json
|
|
316
321
|
return (0, isFile_1.default)(packageFile).then((isPluginAPackageFile) => {
|
|
317
322
|
if (!isPluginAPackageFile) {
|
|
318
|
-
throw new Error("\"" +
|
|
323
|
+
throw new Error("\"" + pluginName + "\" plugin has no valid package.json");
|
|
319
324
|
}
|
|
320
325
|
// read package.json and parse it
|
|
321
326
|
}).then(() => {
|
|
327
|
+
this._logger?.("debug", "Reading package.json...", false, pluginName);
|
|
328
|
+
this.emit("installing", pluginName, 2, MAX_INSTALL_STEPS, "Reading package.json...");
|
|
322
329
|
return (0, promises_1.readFile)(packageFile, "utf-8").then((content) => {
|
|
323
330
|
return JSON.parse(content);
|
|
324
331
|
});
|
|
325
332
|
}).then((packageData) => {
|
|
326
333
|
// check if the plugin has a valid name
|
|
327
334
|
if ("string" !== typeof packageData.name || "" === packageData.name.trim()) {
|
|
328
|
-
throw new Error("\"" +
|
|
335
|
+
throw new Error("\"" + pluginName + "\" plugin has no valid name");
|
|
329
336
|
}
|
|
330
|
-
|
|
337
|
+
pluginName = packageData.name;
|
|
331
338
|
// check if the plugin has a valid entry point
|
|
332
339
|
if ("string" !== typeof packageData.main || "" === packageData.main.trim()) {
|
|
333
|
-
throw new Error("\"" +
|
|
340
|
+
throw new Error("\"" + pluginName + "\" plugin has no valid entry point");
|
|
334
341
|
}
|
|
335
342
|
const entryPoint = (0, node_path_1.join)(directory, packageData.main);
|
|
336
343
|
// check if the plugin is builded (build it if needed)
|
|
@@ -341,21 +348,24 @@ class PluginsManager extends node_events_1.default {
|
|
|
341
348
|
}
|
|
342
349
|
// check if the plugin has a build script
|
|
343
350
|
if ("object" !== typeof packageData.scripts || null === packageData.scripts || 0 >= Object.keys(packageData.scripts).length) {
|
|
344
|
-
throw new Error("\"" +
|
|
351
|
+
throw new Error("\"" + pluginName + "\" plugin has no scripts registered");
|
|
345
352
|
}
|
|
346
353
|
const scripts = packageData.scripts;
|
|
347
354
|
if ("string" !== typeof scripts.build || "" === scripts.build.trim()) {
|
|
348
|
-
throw new Error("\"" +
|
|
355
|
+
throw new Error("\"" + pluginName + "\" plugin has no build script registered");
|
|
349
356
|
}
|
|
350
357
|
this._logger?.("info", "Installing dev dependencies...", false, pluginName);
|
|
358
|
+
this.emit("installing", pluginName, 3, MAX_INSTALL_STEPS, "Installing dev dependencies...");
|
|
351
359
|
// install plugin with dependencies
|
|
352
360
|
return (0, npmInstall_1.default)(directory, true).then(() => {
|
|
353
361
|
this._logger?.("success", "Plugin installed successfully", false, pluginName);
|
|
354
362
|
this._logger?.("info", "Building plugin...", false, pluginName);
|
|
363
|
+
this.emit("installing", pluginName, 4, MAX_INSTALL_STEPS, "Building plugin...");
|
|
355
364
|
return (0, npmBuild_1.default)(directory);
|
|
356
365
|
// remove dev dependencies
|
|
357
366
|
}).then(() => {
|
|
358
367
|
this._logger?.("debug", "Removing dev dependencies...", false, pluginName);
|
|
368
|
+
this.emit("installing", pluginName, 5, MAX_INSTALL_STEPS, "Removing dev dependencies...");
|
|
359
369
|
return (0, rmdirp_1.default)((0, node_path_1.join)(directory, "node_modules")).then(() => {
|
|
360
370
|
this._logger?.("success", "Dev dependencies removed successfully", false, pluginName);
|
|
361
371
|
});
|
|
@@ -364,7 +374,8 @@ class PluginsManager extends node_events_1.default {
|
|
|
364
374
|
if ("object" !== typeof packageData.dependencies || null === packageData.dependencies || 0 >= Object.keys(packageData.dependencies).length) {
|
|
365
375
|
return Promise.resolve();
|
|
366
376
|
}
|
|
367
|
-
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...");
|
|
368
379
|
return (0, npmInstall_1.default)(directory).then(() => {
|
|
369
380
|
this._logger?.("success", "Dependencies installed successfully", false, pluginName);
|
|
370
381
|
});
|
|
@@ -372,20 +383,28 @@ class PluginsManager extends node_events_1.default {
|
|
|
372
383
|
});
|
|
373
384
|
// create plugin
|
|
374
385
|
}).then(() => {
|
|
386
|
+
this._logger?.("debug", "Creating plugin...", false, pluginName);
|
|
387
|
+
this.emit("installing", pluginName, 7, MAX_INSTALL_STEPS, "Creating plugin...");
|
|
375
388
|
return (0, createPluginByDirectory_1.default)(directory, this.externalResourcesDirectory, this._logger, ...data);
|
|
376
389
|
// check plugin modules versions
|
|
377
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...");
|
|
378
393
|
return this.checkModules(plugin).then(() => {
|
|
379
394
|
return Promise.resolve(plugin);
|
|
380
395
|
});
|
|
381
396
|
}).then((plugin) => {
|
|
382
397
|
// execute plugin install script
|
|
383
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...");
|
|
384
401
|
return plugin.install(...data).then(() => {
|
|
385
402
|
this.emit("installed", plugin, ...data);
|
|
386
403
|
});
|
|
387
404
|
// execute init plugin script
|
|
388
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...");
|
|
389
408
|
return plugin.init(...data).then(() => {
|
|
390
409
|
this.emit("initialized", plugin, ...data);
|
|
391
410
|
this.plugins.push(plugin);
|
|
@@ -409,18 +428,29 @@ class PluginsManager extends node_events_1.default {
|
|
|
409
428
|
});
|
|
410
429
|
});
|
|
411
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
|
+
}
|
|
412
444
|
// update a plugin via its github repo, using "data" in arguments for "release", "update" and "init" plugin's methods
|
|
413
445
|
updateViaGithub(plugin, ...data) {
|
|
414
446
|
let directory = "";
|
|
415
|
-
let key = -1;
|
|
416
447
|
let pluginName = "";
|
|
448
|
+
let githubRepository = "";
|
|
417
449
|
// check plugin
|
|
418
450
|
return (0, checkOrchestrator_1.default)("updateViaGithub/plugin", plugin).then(() => {
|
|
419
451
|
pluginName = plugin.name;
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
});
|
|
423
|
-
if (-1 >= key) {
|
|
452
|
+
githubRepository = plugin.repository;
|
|
453
|
+
if (!this.getPluginsNames().includes(pluginName)) {
|
|
424
454
|
throw new Error("Plugin \"" + pluginName + "\" is not registered");
|
|
425
455
|
}
|
|
426
456
|
// check plugin directory
|
|
@@ -429,61 +459,84 @@ class PluginsManager extends node_events_1.default {
|
|
|
429
459
|
directory = (0, node_path_1.join)(this.directory, pluginName);
|
|
430
460
|
return (0, checkAbsoluteDirectory_1.default)("updateViaGithub/plugindirectory", directory);
|
|
431
461
|
});
|
|
432
|
-
// check remote version
|
|
433
462
|
}).then(() => {
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
throw new Error("No valid version found for plugin \"" + pluginName + "\" on github");
|
|
443
|
-
}
|
|
444
|
-
this._logger?.("debug", "Compare local version with github latest tag", false, pluginName);
|
|
445
|
-
if (!semver_1.default.gt(latestVersion, currentVersion)) {
|
|
446
|
-
throw new Error("Plugin \"" + pluginName + "\" 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 + "\")");
|
|
447
471
|
}
|
|
448
|
-
this._logger?.("
|
|
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, pluginName);
|
|
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
|
}
|
|
@@ -507,9 +560,7 @@ class PluginsManager extends node_events_1.default {
|
|
|
507
560
|
});
|
|
508
561
|
// release plugin
|
|
509
562
|
}).then(() => {
|
|
510
|
-
const key = this.
|
|
511
|
-
return name === pluginName;
|
|
512
|
-
});
|
|
563
|
+
const key = this.plugins.indexOf(plugin);
|
|
513
564
|
return plugin.release(...data).then(() => {
|
|
514
565
|
return (0, rmdirp_1.default)((0, node_path_1.join)(this.externalResourcesDirectory, pluginName));
|
|
515
566
|
}).then(() => {
|
|
@@ -517,7 +568,9 @@ class PluginsManager extends node_events_1.default {
|
|
|
517
568
|
return plugin.destroy(...data);
|
|
518
569
|
}).then(() => {
|
|
519
570
|
this.emit("destroyed", pluginName, ...data);
|
|
520
|
-
|
|
571
|
+
if (-1 < key) {
|
|
572
|
+
this.plugins.splice(key, 1);
|
|
573
|
+
}
|
|
521
574
|
});
|
|
522
575
|
// update dependencies & execute update script
|
|
523
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.1",
|
|
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.1.
|
|
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,14 +61,14 @@
|
|
|
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.3",
|
|
65
65
|
"nyc": "18.0.0",
|
|
66
66
|
"proxyquire": "2.1.3",
|
|
67
67
|
"rimraf": "6.1.3",
|
|
68
68
|
"socket.io": "4.8.3",
|
|
69
69
|
"typescript": "5.9.3",
|
|
70
70
|
"used-deps-analyzer": "0.4.0",
|
|
71
|
-
"ws": "8.21.
|
|
71
|
+
"ws": "8.21.1"
|
|
72
72
|
},
|
|
73
73
|
|
|
74
74
|
"keywords": [
|