mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Initial plugin runtime api implementation
This commit is contained in:
100
packages/node_modules/@node-red/registry/lib/plugins.js
vendored
Normal file
100
packages/node_modules/@node-red/registry/lib/plugins.js
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
const registry = require("./registry");
|
||||
const {events} = require("@node-red/util")
|
||||
|
||||
var pluginConfigCache = {};
|
||||
var pluginToId = {};
|
||||
var plugins = {};
|
||||
var pluginsByType = {};
|
||||
var settings;
|
||||
|
||||
function init(_settings) {
|
||||
settings = _settings;
|
||||
plugins = {};
|
||||
pluginConfigCache = {};
|
||||
pluginToId = {};
|
||||
pluginsByType = {};
|
||||
}
|
||||
|
||||
function registerPlugin(nodeSetId,id,definition) {
|
||||
var moduleId = registry.getModuleFromSetId(nodeSetId);
|
||||
var pluginId = registry.getNodeFromSetId(nodeSetId);
|
||||
|
||||
definition.id = id;
|
||||
definition.module = moduleId;
|
||||
pluginToId[id] = nodeSetId;
|
||||
plugins[id] = definition;
|
||||
var module = registry.getModule(moduleId);
|
||||
module.plugins[pluginId].plugins.push(definition);
|
||||
if (definition.type) {
|
||||
pluginsByType[definition.type] = pluginsByType[definition.type] || [];
|
||||
pluginsByType[definition.type].push(definition);
|
||||
}
|
||||
if (definition.onadd && typeof definition.onadd === 'function') {
|
||||
definition.onadd();
|
||||
}
|
||||
events.emit("registry:plugin-added",id);
|
||||
}
|
||||
|
||||
function getPlugin(id) {
|
||||
return plugins[id]
|
||||
}
|
||||
|
||||
function getPluginsByType(type) {
|
||||
return pluginsByType[type] || [];
|
||||
}
|
||||
|
||||
function getPluginConfigs(lang) {
|
||||
if (!pluginConfigCache[lang]) {
|
||||
var result = "";
|
||||
var script = "";
|
||||
var moduleConfigs = registry.getModuleList();
|
||||
for (var module in moduleConfigs) {
|
||||
/* istanbul ignore else */
|
||||
if (moduleConfigs.hasOwnProperty(module)) {
|
||||
var plugins = moduleConfigs[module].plugins;
|
||||
for (var plugin in plugins) {
|
||||
if (plugins.hasOwnProperty(plugin)) {
|
||||
var config = plugins[plugin];
|
||||
if (config.enabled && !config.err && config.config) {
|
||||
result += "\n<!-- --- [red-plugin:"+config.id+"] --- -->\n";
|
||||
result += config.config;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pluginConfigCache[lang] = result;
|
||||
}
|
||||
return pluginConfigCache[lang];
|
||||
}
|
||||
function getPluginList() {
|
||||
var list = [];
|
||||
var moduleConfigs = registry.getModuleList();
|
||||
for (var module in moduleConfigs) {
|
||||
/* istanbul ignore else */
|
||||
if (moduleConfigs.hasOwnProperty(module)) {
|
||||
var plugins = moduleConfigs[module].plugins;
|
||||
for (var plugin in plugins) {
|
||||
/* istanbul ignore else */
|
||||
if (plugins.hasOwnProperty(plugin)) {
|
||||
var pluginInfo = registry.filterNodeInfo(plugins[plugin]);
|
||||
pluginInfo.version = moduleConfigs[module].version;
|
||||
// if (moduleConfigs[module].pending_version) {
|
||||
// nodeInfo.pending_version = moduleConfigs[module].pending_version;
|
||||
// }
|
||||
list.push(pluginInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
init,
|
||||
registerPlugin,
|
||||
getPlugin,
|
||||
getPluginsByType,
|
||||
getPluginConfigs,
|
||||
getPluginList
|
||||
}
|
Reference in New Issue
Block a user