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:
@@ -28,6 +28,7 @@ var api = module.exports = {
|
||||
api.library.init(runtime);
|
||||
api.projects.init(runtime);
|
||||
api.context.init(runtime);
|
||||
api.plugins.init(runtime);
|
||||
},
|
||||
|
||||
comms: require("./comms"),
|
||||
@@ -37,6 +38,7 @@ var api = module.exports = {
|
||||
settings: require("./settings"),
|
||||
projects: require("./projects"),
|
||||
context: require("./context"),
|
||||
plugins: require("./plugins"),
|
||||
|
||||
isStarted: async function(opts) {
|
||||
return runtime.isStarted();
|
||||
|
57
packages/node_modules/@node-red/runtime/lib/api/plugins.js
vendored
Normal file
57
packages/node_modules/@node-red/runtime/lib/api/plugins.js
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* @mixin @node-red/runtime_plugins
|
||||
*/
|
||||
|
||||
var runtime;
|
||||
|
||||
var api = module.exports = {
|
||||
init: function(_runtime) {
|
||||
runtime = _runtime;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Gets the editor content for an individual plugin
|
||||
* @param {Object} opts
|
||||
* @param {User} opts.user - the user calling the api
|
||||
* @param {Object} opts.req - the request to log (optional)
|
||||
* @return {Promise<NodeInfo>} - the node information
|
||||
* @memberof @node-red/runtime_nodes
|
||||
*/
|
||||
getPluginList: async function(opts) {
|
||||
runtime.log.audit({event: "plugins.list.get"}, opts.req);
|
||||
return runtime.plugins.getPluginList();
|
||||
},
|
||||
|
||||
getPluginConfigs: async function(opts) {
|
||||
runtime.log.audit({event: "plugins.configs.get"}, opts.req);
|
||||
return runtime.plugins.getPluginConfigs(opts.lang);
|
||||
},
|
||||
/**
|
||||
* Gets all registered module message catalogs
|
||||
* @param {Object} opts
|
||||
* @param {User} opts.user - the user calling the api
|
||||
* @param {User} opts.lang - the i18n language to return. If not set, uses runtime default (en-US)
|
||||
* @param {Object} opts.req - the request to log (optional)
|
||||
* @return {Promise<Object>} - the message catalogs
|
||||
* @memberof @node-red/runtime_nodes
|
||||
*/
|
||||
getPluginCatalogs: async function(opts) {
|
||||
var lang = opts.lang;
|
||||
var prevLang = runtime.i18n.i.language;
|
||||
// Trigger a load from disk of the language if it is not the default
|
||||
return new Promise( (resolve,reject) => {
|
||||
runtime.i18n.i.changeLanguage(lang, function(){
|
||||
var nodeList = runtime.plugins.getPluginList();
|
||||
var result = {};
|
||||
nodeList.forEach(function(n) {
|
||||
if (n.module !== "node-red") {
|
||||
result[n.id] = runtime.i18n.i.getResourceBundle(lang, n.id)||{};
|
||||
}
|
||||
});
|
||||
runtime.i18n.i.changeLanguage(prevLang);
|
||||
resolve(result);
|
||||
});
|
||||
});
|
||||
},
|
||||
}
|
@@ -21,6 +21,7 @@ var flows = require("./flows");
|
||||
var storage = require("./storage");
|
||||
var library = require("./library");
|
||||
var hooks = require("./hooks");
|
||||
var plugins = require("./plugins");
|
||||
var settings = require("./settings");
|
||||
|
||||
var express = require("express");
|
||||
@@ -280,6 +281,7 @@ var runtime = {
|
||||
storage: storage,
|
||||
hooks: hooks,
|
||||
nodes: redNodes,
|
||||
plugins: plugins,
|
||||
flows: flows,
|
||||
library: library,
|
||||
exec: exec,
|
||||
@@ -341,6 +343,12 @@ module.exports = {
|
||||
*/
|
||||
context: externalAPI.context,
|
||||
|
||||
/**
|
||||
* @memberof @node-red/runtime
|
||||
* @mixes @node-red/runtime_plugins
|
||||
*/
|
||||
plugins: externalAPI.plugins,
|
||||
|
||||
/**
|
||||
* Returns whether the runtime is started
|
||||
* @param {Object} opts
|
||||
|
10
packages/node_modules/@node-red/runtime/lib/plugins.js
vendored
Normal file
10
packages/node_modules/@node-red/runtime/lib/plugins.js
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
const registry = require("@node-red/registry");
|
||||
|
||||
module.exports = {
|
||||
init: function() {},
|
||||
registerPlugin: registry.registerPlugin,
|
||||
getPlugin: registry.getPlugin,
|
||||
getPluginsByType: registry.getPluginsByType,
|
||||
getPluginList: registry.getPluginList,
|
||||
getPluginConfigs: registry.getPluginConfigs,
|
||||
}
|
Reference in New Issue
Block a user