mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Move exec and events components to util module
The exec and events components are common components that are used by both runtime and registry. It makes sense to move them into the util package. This also adds some docs to the registry module
This commit is contained in:
@@ -14,9 +14,8 @@
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
var path = require("path");
|
||||
var i18n = require("@node-red/util").i18n;
|
||||
var registry;
|
||||
const path = require("path");
|
||||
const {events,i18n,log} = require("@node-red/util");
|
||||
var runtime;
|
||||
|
||||
function copyObjectProperties(src,dst,copyList,blockList) {
|
||||
@@ -40,7 +39,7 @@ function copyObjectProperties(src,dst,copyList,blockList) {
|
||||
}
|
||||
}
|
||||
function requireModule(name) {
|
||||
var moduleInfo = registry.getModuleInfo(name);
|
||||
var moduleInfo = require("./index").getModuleInfo(name);
|
||||
if (moduleInfo && moduleInfo.path) {
|
||||
var relPath = path.relative(__dirname, moduleInfo.path);
|
||||
return require(relPath);
|
||||
@@ -56,14 +55,14 @@ function createNodeApi(node) {
|
||||
nodes: {},
|
||||
log: {},
|
||||
settings: {},
|
||||
events: runtime.events,
|
||||
events: events,
|
||||
hooks: runtime.hooks,
|
||||
util: runtime.util,
|
||||
version: runtime.version,
|
||||
require: requireModule,
|
||||
comms: {
|
||||
publish: function(topic,data,retain) {
|
||||
runtime.events.emit("comms",{
|
||||
events.emit("comms",{
|
||||
topic: topic,
|
||||
data: data,
|
||||
retain: retain
|
||||
@@ -83,7 +82,7 @@ function createNodeApi(node) {
|
||||
red.nodes.registerType = function(type,constructor,opts) {
|
||||
runtime.nodes.registerType(node.id,type,constructor,opts);
|
||||
}
|
||||
copyObjectProperties(runtime.log,red.log,null,["init"]);
|
||||
copyObjectProperties(log,red.log,null,["init"]);
|
||||
copyObjectProperties(runtime.settings,red.settings,null,["init","load","reset"]);
|
||||
if (runtime.adminApi) {
|
||||
red.auth = runtime.adminApi.auth;
|
||||
@@ -108,7 +107,6 @@ function createNodeApi(node) {
|
||||
module.exports = {
|
||||
init: function(_runtime) {
|
||||
runtime = _runtime;
|
||||
registry = require("@node-red/registry/lib");
|
||||
},
|
||||
createNodeApi: createNodeApi
|
||||
}
|
||||
|
Reference in New Issue
Block a user