mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Add tests for pluggable library
This commit is contained in:
@@ -28,43 +28,15 @@ let runtimeLibraries = [];
|
||||
// Libraries defined by the user in the editor.
|
||||
let userLibraries = [];
|
||||
|
||||
function init(runtime) {
|
||||
let runtime;
|
||||
|
||||
events.on("registry:plugin-added", function(id) {
|
||||
const plugin = runtime.plugins.getPlugin(id);
|
||||
if (plugin.type === "node-red-library-source") {
|
||||
libraryPlugins[plugin.id] = plugin;
|
||||
|
||||
runtimeLibraries.forEach(library => {
|
||||
if (library.type === id) {
|
||||
library.local = false;
|
||||
|
||||
if (!/^[a-z0-9-_]+$/.test(library.id)) {
|
||||
log.warn(log._("library.failedToInit",{error:log._("library.invalidProperty",{prop:"id",value:library.id})}));
|
||||
return;
|
||||
}
|
||||
try {
|
||||
libraries[library.id] = new plugin.class(library)
|
||||
libraryConfigs[library.id] = library;
|
||||
libraryConfigs[library.id].type = id;
|
||||
if (libraries[library.id].init) {
|
||||
libraries[library.id].init().catch(err => {
|
||||
delete libraries[library.id];
|
||||
delete libraryConfigs[library.id];
|
||||
log.warn(log._("library.failedToInit",{library:library.id, error:err.toString()}));
|
||||
});
|
||||
}
|
||||
} catch(err) {
|
||||
log.warn(log._("library.failedToInit",{library:library.id, error:err.toString()}));
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
})
|
||||
function init(_runtime) {
|
||||
runtime = _runtime;
|
||||
events.removeListener("registry:plugin-added",onPluginAdded);
|
||||
events.on("registry:plugin-added",onPluginAdded);
|
||||
|
||||
knownTypes.flows = 'node-red';
|
||||
|
||||
libraries["local"] = require("./local");
|
||||
libraries["local"].init(runtime);
|
||||
libraryConfigs["local"] = libraries["local"]
|
||||
@@ -83,6 +55,41 @@ function init(runtime) {
|
||||
|
||||
}
|
||||
|
||||
function onPluginAdded(id) {
|
||||
const plugin = runtime.plugins.getPlugin(id);
|
||||
if (plugin.type === "node-red-library-source") {
|
||||
libraryPlugins[plugin.id] = plugin;
|
||||
|
||||
runtimeLibraries.forEach(library => {
|
||||
if (library.type === id) {
|
||||
library.local = false;
|
||||
|
||||
if (!/^[a-z0-9-_]+$/.test(library.id)) {
|
||||
log.warn(log._("library.failedToInit",{error:log._("library.invalidProperty",{prop:"id",value:library.id})}));
|
||||
return;
|
||||
}
|
||||
try {
|
||||
libraries[library.id] = new plugin.class(library)
|
||||
libraryConfigs[library.id] = library;
|
||||
libraryConfigs[library.id].type = id;
|
||||
if (libraries[library.id].init) {
|
||||
libraries[library.id].init().catch(err => {
|
||||
delete libraries[library.id];
|
||||
delete libraryConfigs[library.id];
|
||||
log.warn(log._("library.failedToInit",{library:library.id, error:err.toString()}));
|
||||
});
|
||||
}
|
||||
} catch(err) {
|
||||
log.warn(log._("library.failedToInit",{library:library.id, error:err.toString()}));
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function registerType(id,type) {
|
||||
// TODO: would like to enforce this, but currently the tests register the same type multiple
|
||||
// times and have no way to remove themselves.
|
||||
|
Reference in New Issue
Block a user