mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Support for library source plugins
This commit is contained in:
committed by
Nick O'Leary
parent
f96ce2fd83
commit
8a076c01ab
@@ -81,7 +81,7 @@ var api = module.exports = {
|
||||
|
||||
if (!runtime.settings.disableEditor) {
|
||||
safeSettings.context = runtime.nodes.listContextStores();
|
||||
|
||||
safeSettings.libraries = runtime.library.getLibraries();
|
||||
if (util.isArray(runtime.settings.paletteCategories)) {
|
||||
safeSettings.paletteCategories = runtime.settings.paletteCategories;
|
||||
}
|
||||
|
@@ -74,7 +74,6 @@ function init(userSettings,httpServer,_adminApi) {
|
||||
adminApi = _adminApi;
|
||||
}
|
||||
redNodes.init(runtime);
|
||||
library.init(runtime);
|
||||
externalAPI.init(runtime);
|
||||
}
|
||||
|
||||
@@ -104,6 +103,7 @@ function start() {
|
||||
return i18n.registerMessageCatalog("runtime",path.resolve(path.join(__dirname,"..","locales")),"runtime.json")
|
||||
.then(function() { return storage.init(runtime)})
|
||||
.then(function() { return settings.load(storage)})
|
||||
.then(function() { return library.init(runtime)})
|
||||
.then(function() {
|
||||
|
||||
if (log.metric()) {
|
||||
|
@@ -15,21 +15,54 @@
|
||||
**/
|
||||
|
||||
|
||||
var knownTypes = {};
|
||||
const {events} = require("@node-red/util")
|
||||
const knownTypes = {};
|
||||
const libraries = {};
|
||||
const libraryPlugins = {};
|
||||
|
||||
var libraries = {};
|
||||
// Libraries defined in the settings file. Their configurations
|
||||
// cannot be modified in the editor.
|
||||
let runtimeLibraries = [];
|
||||
|
||||
// Libraries defined by the user in the editor.
|
||||
let userLibraries = [];
|
||||
|
||||
function init(runtime) {
|
||||
knownTypes = {
|
||||
'flows': 'node-red'
|
||||
};
|
||||
|
||||
libraries["_examples_"] = require("./examples");
|
||||
libraries["_examples_"].init(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;
|
||||
libraries[library.id] = new plugin.class(library)
|
||||
if (libraries[library.id].init) {
|
||||
libraries[library.id].init();
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
knownTypes.flows = 'node-red';
|
||||
|
||||
libraries["examples"] = require("./examples");
|
||||
libraries["examples"].init(runtime);
|
||||
libraries["local"] = require("./local");
|
||||
libraries["local"].init(runtime);
|
||||
|
||||
try {
|
||||
runtimeLibraries = runtime.settings.editorTheme.library.sources;
|
||||
} catch(err) {
|
||||
runtimeLibraries = [];
|
||||
}
|
||||
// userLibraries = runtime.settings.get("library")
|
||||
|
||||
|
||||
}
|
||||
|
||||
function registerType(id,type) {
|
||||
@@ -56,7 +89,7 @@ function saveEntry(library,type,path,meta,body) {
|
||||
throw new Error(`Unknown library type '${type}'`);
|
||||
}
|
||||
if (libraries.hasOwnProperty(library)) {
|
||||
if (libraries[library].hasOwnProperty("saveEntry")) {
|
||||
if (libraries[library].saveEntry) {
|
||||
return libraries[library].saveEntry(type,path,meta,body);
|
||||
} else {
|
||||
throw new Error(`Library '${library}' is read-only`);
|
||||
@@ -66,8 +99,43 @@ function saveEntry(library,type,path,meta,body) {
|
||||
}
|
||||
}
|
||||
|
||||
function getLibraries() {
|
||||
const libraryList = [
|
||||
{
|
||||
id: "local",
|
||||
label: "editor:library.types.local",
|
||||
user: false,
|
||||
icon: "fa fa-bath"
|
||||
},
|
||||
{
|
||||
id: "examples",
|
||||
label: "editor:library.types.examples",
|
||||
user: false,
|
||||
readOnly: true,
|
||||
types: ['flows']
|
||||
}
|
||||
];
|
||||
|
||||
for (let id in libraries) {
|
||||
if (libraries.hasOwnProperty(id)) {
|
||||
if (id !== 'local' && id !== 'examples') {
|
||||
libraryList.push({
|
||||
id: id,
|
||||
label: libraries[id].name || id,
|
||||
user: false,
|
||||
icon: libraries[id].icon
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return libraryList;
|
||||
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
init: init,
|
||||
getLibraries: getLibraries,
|
||||
register: registerType,
|
||||
getEntry: getEntry,
|
||||
saveEntry: saveEntry
|
||||
|
Reference in New Issue
Block a user