自1.3.0版本起
Node-RED编辑器中的导入/导出对话框提供了一种将流程和节点保存到本地库的方法。
这个本地库由Storage API管理。默认情况下会存储在~/.node-red/lib
目录下。
Library Store API 是一种插件机制,可用于提供将内容存储在其他位置(而不仅仅是本地文件)的库。
Node-RED提供了一个文件存储插件,可用于添加存储在本地文件系统中的库。例如,可以通过Dropbox等工具在共享文件系统上创建库,从而更轻松地与您合作的其他开发者共享流程。
~/.node-red/settings.js
editorTheme
部分,如果不存在library
部分就添加一个。在该部分下添加一个sources
数组。在该数组中您可以添加任意数量的新文件存储源。
editorTheme: {
library: {
sources: [
{
id: "team-collaboration-library",
type: "node-red-library-file-store",
path: "/Users/tom/work/team-library/",
label: "Team collaboration",
icon: "font-awesome/fa-users"
}
]
},
}
配置对象可以包含以下属性:
属性 | 描述 |
---|---|
id |
Required A unique, url-safe, identifier for the library. Should contain only letters, numbers and the symbols - _ . |
type |
Required Must be set to node-red-library-file-store |
path |
Required The absolute path to the where the library should be stored |
label |
An optional label to use in the editor, otherwise the id will be used. |
icon |
An optional icon from FontAwesome 4.7. |
types |
By default the library will be used to store all types of object. It can be restricted to certain types by setting this property to an array of the acceptable types. For example, to restrict it to just flows, set this property to ["flows"] . |
readOnly |
To make this a read-only library so it can only be used to import from, set this property to true . |
要创建一个由不同类型存储支持的存储库,您需要开发一个新的插件。
该插件以npm模块形式打包,包含一个package.json
文件。
以下代码可作为该插件的起点。您还应参考File Store插件。
{
"name": "your-custom-library-store",
"version": "1.0.0",
"description": "A Custom Library plugin for Node-RED",
"keywords": [
"node-red"
],
"node-red": {
"plugins": {
"customstore": "store.js"
}
}
}
module.exports = function(RED) {
// This must be a unique identifier for the library store type
const PLUGIN_TYPE_ID = "node-red-library-custom-store";
class CustomStorePlugin {
/**
* @param {object} config an object containing the configuration for an
* instance of the store
*/
constructor(config) {
// Required properties
this.type = PLUGIN_TYPE_ID;
this.id = config.id;
this.label = config.label;
}
/**
* Initialise the store.
*/
async init() {
}
/**
* Get an entry from the store
* @param {string} type The type of entry, for example, "flow"
* @param {string} path The path to the library entry
* @return if 'path' resolves to a single entry, it returns the contents
* of that entry.
* if 'path' resolves to a 'directory', it returns a listing of
* the contents of the directory
* if 'path' is not valid, it should throw a suitable error
*/
async getEntry(type,path) {
throw new Error("Not implemented")
}
/**
* Save an entry to the library
* @param {string} type The type of entry, for example, "flow"
* @param {string} path The path to the library entry
* @param {object} meta An object of key/value meta data about the entry
* @param {string} body The entry contents
*/
async saveEntry(type,path,meta,body) {
throw new Error("Not implemented")
}
}
// Register the plugin.
RED.plugins.registerPlugin(PLUGIN_TYPE_ID, {
// This tells Node-RED the plugin is a library source plugin
type: "node-red-library-source",
class: CustomStorePlugin
})
}
Node-RED: 面向事件驱动应用的低代码编程平台。
版权所有 OpenJS基金会 及 Node-RED 贡献者。保留所有权利。OpenJS基金会 拥有注册商标并使用商标。有关 OpenJS基金会 的商标列表,请参阅我们的 商标政策 和 商标列表。未在 OpenJS基金会商标列表 中标注的商标™或注册®商标归其各自持有人所有。使用这些商标并不意味着与它们有任何关联或获得其认可。
The OpenJS Foundation | 使用条款 | 隐私政策 | OpenJS基金会章程 | 商标政策 | 商标列表 | Cookie政策