@node-red/registry 4.0.0-beta.1 → 4.0.0-beta.2
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/index.js +1 -0
- package/lib/installer.js +16 -2
- package/lib/plugins.js +71 -12
- package/lib/registry.js +17 -2
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -319,6 +319,7 @@ module.exports = {
|
|
|
319
319
|
getPluginsByType: plugins.getPluginsByType,
|
|
320
320
|
getPluginList: plugins.getPluginList,
|
|
321
321
|
getPluginConfigs: plugins.getPluginConfigs,
|
|
322
|
+
getPluginConfig: plugins.getPluginConfig,
|
|
322
323
|
exportPluginSettings: plugins.exportPluginSettings,
|
|
323
324
|
|
|
324
325
|
|
package/lib/installer.js
CHANGED
|
@@ -28,6 +28,8 @@ const child_process = require('child_process');
|
|
|
28
28
|
const npmCommand = process.platform === 'win32' ? 'npm.cmd' : 'npm';
|
|
29
29
|
let installerEnabled = false;
|
|
30
30
|
|
|
31
|
+
const plugins = require("./plugins");
|
|
32
|
+
|
|
31
33
|
let settings;
|
|
32
34
|
const moduleRe = /^(@[^/@]+?[/])?[^/@]+?$/;
|
|
33
35
|
const slashRe = process.platform === "win32" ? /\\|[/]/ : /[/]/;
|
|
@@ -330,10 +332,18 @@ function reportRemovedModules(removedNodes) {
|
|
|
330
332
|
//comms.publish("node/removed",removedNodes,false);
|
|
331
333
|
log.info(log._("server.removed-types"));
|
|
332
334
|
for (var j=0;j<removedNodes.length;j++) {
|
|
333
|
-
for (var i=0;i<removedNodes[j].types
|
|
335
|
+
for (var i=0;i<removedNodes[j].types?.length;i++) {
|
|
334
336
|
log.info(" - "+(removedNodes[j].module?removedNodes[j].module+":":"")+removedNodes[j].types[i]);
|
|
335
337
|
}
|
|
336
338
|
}
|
|
339
|
+
|
|
340
|
+
log.info(log._("server.removed-plugins"));
|
|
341
|
+
for (let j=0;j<removedNodes.length;j++) {
|
|
342
|
+
for (var i=0;i<removedNodes[j].plugins?.length;i++) {
|
|
343
|
+
log.info(" - "+(removedNodes[j].module?removedNodes[j].module+":":"")+removedNodes[j].plugins[i].id);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
337
347
|
return removedNodes;
|
|
338
348
|
}
|
|
339
349
|
|
|
@@ -495,8 +505,12 @@ function uninstallModule(module) {
|
|
|
495
505
|
} catch(err) {
|
|
496
506
|
return reject(new Error(log._("server.install.uninstall-failed",{name:module})));
|
|
497
507
|
}
|
|
508
|
+
|
|
509
|
+
// need to remove the plugins first,
|
|
510
|
+
// as registry data necessary to perform this operation
|
|
511
|
+
var list = plugins.removeModule(module);
|
|
512
|
+
list = list.concat(registry.removeModule(module));
|
|
498
513
|
|
|
499
|
-
var list = registry.removeModule(module);
|
|
500
514
|
log.info(log._("server.install.uninstalling",{name:module}));
|
|
501
515
|
|
|
502
516
|
let triggerPayload = {
|
package/lib/plugins.js
CHANGED
|
@@ -39,6 +39,8 @@ function registerPlugin(nodeSetId,id,definition) {
|
|
|
39
39
|
pluginSettings[id] = definition.settings;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
// reset the cache when a new plugin is incoming!
|
|
43
|
+
pluginConfigCache = {};
|
|
42
44
|
|
|
43
45
|
if (definition.onadd && typeof definition.onadd === 'function') {
|
|
44
46
|
definition.onadd();
|
|
@@ -55,29 +57,47 @@ function getPluginsByType(type) {
|
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
function getPluginConfigs(lang) {
|
|
60
|
+
// we're not re-using getPluginConfig() here,
|
|
61
|
+
// to avoid calling registry.getModuleList() multiple times!
|
|
62
|
+
|
|
58
63
|
if (!pluginConfigCache[lang]) {
|
|
59
64
|
var result = "";
|
|
60
|
-
var script = "";
|
|
61
65
|
var moduleConfigs = registry.getModuleList();
|
|
62
66
|
for (var module in moduleConfigs) {
|
|
63
67
|
/* istanbul ignore else */
|
|
64
68
|
if (moduleConfigs.hasOwnProperty(module)) {
|
|
65
|
-
|
|
66
|
-
for (var plugin in plugins) {
|
|
67
|
-
if (plugins.hasOwnProperty(plugin)) {
|
|
68
|
-
var config = plugins[plugin];
|
|
69
|
-
if (config.enabled && !config.err && config.config) {
|
|
70
|
-
result += "\n<!-- --- [red-plugin:"+config.id+"] --- -->\n";
|
|
71
|
-
result += config.config;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
69
|
+
result += generateModulePluginConfig(moduleConfigs[module]);
|
|
75
70
|
}
|
|
76
71
|
}
|
|
77
72
|
pluginConfigCache[lang] = result;
|
|
78
73
|
}
|
|
79
74
|
return pluginConfigCache[lang];
|
|
80
75
|
}
|
|
76
|
+
|
|
77
|
+
function getPluginConfig(id, lang) {
|
|
78
|
+
let result = '';
|
|
79
|
+
let moduleConfigs = registry.getModuleList();
|
|
80
|
+
if (moduleConfigs.hasOwnProperty(id)) {
|
|
81
|
+
result = generateModulePluginConfig(moduleConfigs[id]);
|
|
82
|
+
}
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function generateModulePluginConfig(module) {
|
|
87
|
+
let result = '';
|
|
88
|
+
const plugins = module.plugins
|
|
89
|
+
for (let plugin in plugins) {
|
|
90
|
+
if (plugins.hasOwnProperty(plugin)) {
|
|
91
|
+
let config = plugins[plugin];
|
|
92
|
+
if (config.enabled && !config.err && config.config) {
|
|
93
|
+
result += "\n<!-- --- [red-plugin:"+config.id+"] --- -->\n";
|
|
94
|
+
result += config.config;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
|
|
81
101
|
function getPluginList() {
|
|
82
102
|
var list = [];
|
|
83
103
|
var moduleConfigs = registry.getModuleList();
|
|
@@ -142,12 +162,51 @@ function exportPluginSettings(safeSettings) {
|
|
|
142
162
|
return safeSettings;
|
|
143
163
|
}
|
|
144
164
|
|
|
165
|
+
function removeModule(moduleId) {
|
|
166
|
+
|
|
167
|
+
// clean the (plugin) registry when a module is removed / uninstalled
|
|
168
|
+
|
|
169
|
+
let pluginList = [];
|
|
170
|
+
let module = registry.getModule(moduleId);
|
|
171
|
+
let keys = Object.keys(module.plugins ?? {});
|
|
172
|
+
keys.forEach( key => {
|
|
173
|
+
let _plugins = module.plugins[key].plugins ?? [];
|
|
174
|
+
_plugins.forEach( plugin => {
|
|
175
|
+
let id = plugin.id;
|
|
176
|
+
|
|
177
|
+
if (plugin.onremove && typeof plugin.onremove === 'function') {
|
|
178
|
+
plugin.onremove();
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
delete pluginToId[id];
|
|
182
|
+
delete plugins[id];
|
|
183
|
+
delete pluginSettings[id];
|
|
184
|
+
pluginConfigCache = {};
|
|
185
|
+
|
|
186
|
+
let psbtype = pluginsByType[plugin.type] ?? [];
|
|
187
|
+
for (let i=psbtype.length; i>0; i--) {
|
|
188
|
+
let pbt = psbtype[i-1];
|
|
189
|
+
if (pbt.id == id) {
|
|
190
|
+
psbtype.splice(i-1, 1);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
pluginList.push(registry.filterNodeInfo(module.plugins[key]));
|
|
196
|
+
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
return pluginList;
|
|
200
|
+
}
|
|
201
|
+
|
|
145
202
|
module.exports = {
|
|
146
203
|
init,
|
|
147
204
|
registerPlugin,
|
|
148
205
|
getPlugin,
|
|
149
206
|
getPluginsByType,
|
|
150
207
|
getPluginConfigs,
|
|
208
|
+
getPluginConfig,
|
|
151
209
|
getPluginList,
|
|
152
|
-
exportPluginSettings
|
|
210
|
+
exportPluginSettings,
|
|
211
|
+
removeModule
|
|
153
212
|
}
|
package/lib/registry.js
CHANGED
|
@@ -65,7 +65,13 @@ function filterNodeInfo(n) {
|
|
|
65
65
|
r.err = n.err;
|
|
66
66
|
}
|
|
67
67
|
if (n.hasOwnProperty("plugins")) {
|
|
68
|
-
r.plugins = n.plugins
|
|
68
|
+
r.plugins = n.plugins.map(p => {
|
|
69
|
+
return {
|
|
70
|
+
id: p.id,
|
|
71
|
+
type: p.type,
|
|
72
|
+
module: p.module
|
|
73
|
+
}
|
|
74
|
+
});
|
|
69
75
|
}
|
|
70
76
|
if (n.type === "plugin") {
|
|
71
77
|
r.editor = !!n.template;
|
|
@@ -386,7 +392,8 @@ function getModuleInfo(module) {
|
|
|
386
392
|
local: moduleConfigs[module].local,
|
|
387
393
|
user: moduleConfigs[module].user,
|
|
388
394
|
path: moduleConfigs[module].path,
|
|
389
|
-
nodes: []
|
|
395
|
+
nodes: [],
|
|
396
|
+
plugins: []
|
|
390
397
|
};
|
|
391
398
|
if (moduleConfigs[module].dependencies) {
|
|
392
399
|
m.dependencies = moduleConfigs[module].dependencies;
|
|
@@ -399,6 +406,14 @@ function getModuleInfo(module) {
|
|
|
399
406
|
nodeInfo.version = m.version;
|
|
400
407
|
m.nodes.push(nodeInfo);
|
|
401
408
|
}
|
|
409
|
+
|
|
410
|
+
let plugins = Object.values(moduleConfigs[module].plugins ?? {});
|
|
411
|
+
plugins.forEach((plugin) => {
|
|
412
|
+
let nodeInfo = filterNodeInfo(plugin);
|
|
413
|
+
nodeInfo.version = m.version;
|
|
414
|
+
m.plugins.push(nodeInfo);
|
|
415
|
+
});
|
|
416
|
+
|
|
402
417
|
return m;
|
|
403
418
|
} else {
|
|
404
419
|
return null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@node-red/registry",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.2",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
}
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@node-red/util": "4.0.0-beta.
|
|
19
|
+
"@node-red/util": "4.0.0-beta.2",
|
|
20
20
|
"clone": "2.1.2",
|
|
21
21
|
"fs-extra": "11.1.1",
|
|
22
22
|
"semver": "7.5.4",
|