2014-05-03 23:26:35 +02:00
|
|
|
/**
|
2015-02-03 23:02:26 +01:00
|
|
|
* Copyright 2014, 2015 IBM Corp.
|
2014-05-03 23:26:35 +02:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
**/
|
2014-11-06 11:00:25 +01:00
|
|
|
|
2014-05-03 23:26:35 +02:00
|
|
|
var util = require("util");
|
|
|
|
var when = require("when");
|
|
|
|
var whenNode = require('when/node');
|
|
|
|
var fs = require("fs");
|
|
|
|
var path = require("path");
|
2014-11-06 11:00:25 +01:00
|
|
|
var crypto = require("crypto");
|
2014-05-04 18:30:55 +02:00
|
|
|
var UglifyJS = require("uglify-js");
|
|
|
|
|
2014-05-03 23:26:35 +02:00
|
|
|
var events = require("../events");
|
|
|
|
|
|
|
|
var Node;
|
|
|
|
var settings;
|
|
|
|
|
2014-08-02 00:42:01 +02:00
|
|
|
function filterNodeInfo(n) {
|
|
|
|
var r = {
|
|
|
|
id: n.id,
|
|
|
|
name: n.name,
|
2014-08-28 01:35:07 +02:00
|
|
|
types: n.types,
|
2014-08-02 00:42:01 +02:00
|
|
|
enabled: n.enabled
|
2014-11-06 11:59:34 +01:00
|
|
|
};
|
2014-08-28 01:35:07 +02:00
|
|
|
if (n.hasOwnProperty("loaded")) {
|
|
|
|
r.loaded = n.loaded;
|
|
|
|
}
|
|
|
|
if (n.hasOwnProperty("module")) {
|
|
|
|
r.module = n.module;
|
|
|
|
}
|
|
|
|
if (n.hasOwnProperty("err")) {
|
2014-08-02 00:42:01 +02:00
|
|
|
r.err = n.err.toString();
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2014-11-26 16:25:15 +01:00
|
|
|
function getModule(id) {
|
|
|
|
return id.split("/")[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
function getNode(id) {
|
|
|
|
return id.split("/")[1];
|
|
|
|
}
|
|
|
|
|
2014-08-01 23:05:49 +02:00
|
|
|
var registry = (function() {
|
|
|
|
var nodeConfigCache = null;
|
2014-11-26 16:25:15 +01:00
|
|
|
var moduleConfigs = {};
|
2014-08-01 23:05:49 +02:00
|
|
|
var nodeList = [];
|
|
|
|
var nodeConstructors = {};
|
2014-08-04 18:12:54 +02:00
|
|
|
var nodeTypeToId = {};
|
2014-11-24 16:44:11 +01:00
|
|
|
var moduleNodes = {};
|
2014-11-06 11:00:25 +01:00
|
|
|
|
2014-08-28 01:35:07 +02:00
|
|
|
function saveNodeList() {
|
2014-11-26 16:25:15 +01:00
|
|
|
var moduleList = {};
|
|
|
|
|
2014-11-28 10:17:46 +01:00
|
|
|
for (var module in moduleConfigs) {
|
|
|
|
if (moduleConfigs.hasOwnProperty(module)) {
|
2014-11-26 16:25:15 +01:00
|
|
|
if (!moduleList[module]) {
|
2014-12-08 10:43:59 +01:00
|
|
|
moduleList[module] = {
|
|
|
|
name: module,
|
2014-12-08 11:11:59 +01:00
|
|
|
version: moduleConfigs[module].version,
|
2014-12-08 10:43:59 +01:00
|
|
|
nodes: {}
|
|
|
|
};
|
2014-11-26 16:25:15 +01:00
|
|
|
}
|
2014-11-28 10:17:46 +01:00
|
|
|
var nodes = moduleConfigs[module].nodes;
|
2014-11-26 16:25:15 +01:00
|
|
|
for(var node in nodes) {
|
|
|
|
if (nodes.hasOwnProperty(node)) {
|
|
|
|
var config = nodes[node];
|
|
|
|
var n = filterNodeInfo(config);
|
|
|
|
delete n.loaded;
|
|
|
|
delete n.err;
|
|
|
|
delete n.file;
|
|
|
|
delete n.id;
|
|
|
|
moduleList[module].nodes[node] = n;
|
|
|
|
}
|
|
|
|
}
|
2014-08-28 01:35:07 +02:00
|
|
|
}
|
|
|
|
}
|
2014-09-23 18:09:23 +02:00
|
|
|
if (settings.available()) {
|
2014-12-08 10:57:17 +01:00
|
|
|
return settings.set("nodes",moduleList);
|
2014-09-23 18:09:23 +02:00
|
|
|
} else {
|
|
|
|
return when.reject("Settings unavailable");
|
|
|
|
}
|
2014-08-28 01:35:07 +02:00
|
|
|
}
|
2014-11-06 11:00:25 +01:00
|
|
|
|
2014-12-05 21:43:41 +01:00
|
|
|
function loadNodeConfigs() {
|
|
|
|
var configs = settings.get("nodes");
|
2014-12-08 10:43:59 +01:00
|
|
|
|
2014-12-05 21:43:41 +01:00
|
|
|
if (!configs) {
|
|
|
|
return {};
|
|
|
|
} else if (configs['node-red']) {
|
|
|
|
return configs;
|
|
|
|
} else {
|
|
|
|
// Migrate from the 0.9.1 format of settings
|
|
|
|
var newConfigs = {};
|
|
|
|
for (var id in configs) {
|
|
|
|
if (configs.hasOwnProperty(id)) {
|
|
|
|
var nodeConfig = configs[id];
|
|
|
|
var moduleName;
|
|
|
|
var nodeSetName;
|
2014-12-08 10:43:59 +01:00
|
|
|
|
2014-12-05 21:43:41 +01:00
|
|
|
if (nodeConfig.module) {
|
|
|
|
moduleName = nodeConfig.module;
|
|
|
|
nodeSetName = nodeConfig.name.split(":")[1];
|
|
|
|
} else {
|
|
|
|
moduleName = "node-red";
|
2014-12-08 10:43:59 +01:00
|
|
|
nodeSetName = nodeConfig.name.replace(/^\d+-/,"").replace(/\.js$/,"");
|
2014-12-05 21:43:41 +01:00
|
|
|
}
|
2014-12-08 10:43:59 +01:00
|
|
|
|
2014-12-05 21:43:41 +01:00
|
|
|
if (!newConfigs[moduleName]) {
|
|
|
|
newConfigs[moduleName] = {
|
|
|
|
name: moduleName,
|
|
|
|
nodes:{}
|
2014-12-08 10:43:59 +01:00
|
|
|
};
|
2014-12-05 21:43:41 +01:00
|
|
|
}
|
|
|
|
newConfigs[moduleName].nodes[nodeSetName] = {
|
|
|
|
name: nodeSetName,
|
|
|
|
types: nodeConfig.types,
|
|
|
|
enabled: nodeConfig.enabled,
|
|
|
|
module: moduleName
|
2014-12-08 10:43:59 +01:00
|
|
|
};
|
2014-12-05 21:43:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
settings.set("nodes",newConfigs);
|
|
|
|
return newConfigs;
|
|
|
|
}
|
|
|
|
}
|
2014-12-08 10:43:59 +01:00
|
|
|
|
2014-08-01 23:05:49 +02:00
|
|
|
return {
|
2014-08-28 01:35:07 +02:00
|
|
|
init: function() {
|
|
|
|
if (settings.available()) {
|
2014-12-05 21:43:41 +01:00
|
|
|
moduleConfigs = loadNodeConfigs();
|
2014-08-28 01:35:07 +02:00
|
|
|
} else {
|
2014-11-26 16:25:15 +01:00
|
|
|
moduleConfigs = {};
|
2014-08-28 01:35:07 +02:00
|
|
|
}
|
2014-11-24 16:44:11 +01:00
|
|
|
moduleNodes = {};
|
2014-08-28 01:35:07 +02:00
|
|
|
nodeTypeToId = {};
|
|
|
|
nodeConstructors = {};
|
|
|
|
nodeList = [];
|
|
|
|
nodeConfigCache = null;
|
|
|
|
},
|
2014-11-21 17:35:29 +01:00
|
|
|
addNodeSet: function(id,set,version) {
|
2014-08-04 18:12:54 +02:00
|
|
|
if (!set.err) {
|
|
|
|
set.types.forEach(function(t) {
|
|
|
|
nodeTypeToId[t] = id;
|
|
|
|
});
|
|
|
|
}
|
2014-11-06 11:00:25 +01:00
|
|
|
|
2014-11-24 16:44:11 +01:00
|
|
|
moduleNodes[set.module] = moduleNodes[set.module]||[];
|
|
|
|
moduleNodes[set.module].push(set.name);
|
2014-11-06 11:00:25 +01:00
|
|
|
|
2014-11-26 16:25:15 +01:00
|
|
|
if (!moduleConfigs[set.module]) {
|
|
|
|
moduleConfigs[set.module] = {
|
|
|
|
name: set.module,
|
|
|
|
nodes: {}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2014-11-21 17:35:29 +01:00
|
|
|
if (version) {
|
2014-11-26 16:25:15 +01:00
|
|
|
moduleConfigs[set.module].version = version;
|
2014-11-21 17:35:29 +01:00
|
|
|
}
|
|
|
|
|
2014-11-26 16:25:15 +01:00
|
|
|
moduleConfigs[set.module].nodes[set.name] = set;
|
2014-08-01 23:05:49 +02:00
|
|
|
nodeList.push(id);
|
2014-08-04 18:12:54 +02:00
|
|
|
nodeConfigCache = null;
|
2014-08-01 23:05:49 +02:00
|
|
|
},
|
2014-08-04 18:12:54 +02:00
|
|
|
removeNode: function(id) {
|
2014-11-26 16:25:15 +01:00
|
|
|
var config = moduleConfigs[getModule(id)].nodes[getNode(id)];
|
2014-08-07 23:20:06 +02:00
|
|
|
if (!config) {
|
|
|
|
throw new Error("Unrecognised id: "+id);
|
|
|
|
}
|
2014-11-26 16:25:15 +01:00
|
|
|
delete moduleConfigs[getModule(id)].nodes[getNode(id)];
|
2014-08-07 23:20:06 +02:00
|
|
|
var i = nodeList.indexOf(id);
|
|
|
|
if (i > -1) {
|
|
|
|
nodeList.splice(i,1);
|
2014-08-04 18:12:54 +02:00
|
|
|
}
|
2014-08-07 23:20:06 +02:00
|
|
|
config.types.forEach(function(t) {
|
|
|
|
delete nodeConstructors[t];
|
|
|
|
delete nodeTypeToId[t];
|
|
|
|
});
|
2014-08-28 01:35:07 +02:00
|
|
|
config.enabled = false;
|
|
|
|
config.loaded = false;
|
2014-08-07 23:20:06 +02:00
|
|
|
nodeConfigCache = null;
|
2014-08-04 18:12:54 +02:00
|
|
|
return filterNodeInfo(config);
|
|
|
|
},
|
2014-08-28 01:35:07 +02:00
|
|
|
removeModule: function(module) {
|
|
|
|
if (!settings.available()) {
|
|
|
|
throw new Error("Settings unavailable");
|
|
|
|
}
|
2014-11-24 16:44:11 +01:00
|
|
|
var nodes = moduleNodes[module];
|
2014-08-28 01:35:07 +02:00
|
|
|
if (!nodes) {
|
|
|
|
throw new Error("Unrecognised module: "+module);
|
|
|
|
}
|
|
|
|
var infoList = [];
|
2014-11-24 16:44:11 +01:00
|
|
|
for (var i=0;i<nodes.length;i++) {
|
|
|
|
infoList.push(registry.removeNode(module+"/"+nodes[i]));
|
2014-08-28 01:35:07 +02:00
|
|
|
}
|
2014-11-24 16:44:11 +01:00
|
|
|
delete moduleNodes[module];
|
2014-08-28 01:35:07 +02:00
|
|
|
saveNodeList();
|
|
|
|
return infoList;
|
|
|
|
},
|
2014-08-04 18:12:54 +02:00
|
|
|
getNodeInfo: function(typeOrId) {
|
2014-11-26 16:25:15 +01:00
|
|
|
var id = typeOrId;
|
2014-08-04 18:12:54 +02:00
|
|
|
if (nodeTypeToId[typeOrId]) {
|
2014-11-26 16:25:15 +01:00
|
|
|
id = nodeTypeToId[typeOrId];
|
2014-08-04 18:12:54 +02:00
|
|
|
}
|
2014-11-26 16:25:15 +01:00
|
|
|
if (id) {
|
|
|
|
var module = moduleConfigs[getModule(id)];
|
|
|
|
if (module) {
|
|
|
|
var config = module.nodes[getNode(id)];
|
|
|
|
if (config) {
|
|
|
|
return filterNodeInfo(config);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
2014-08-02 00:42:01 +02:00
|
|
|
},
|
2014-08-01 23:05:49 +02:00
|
|
|
getNodeList: function() {
|
2014-08-28 01:35:07 +02:00
|
|
|
var list = [];
|
2014-11-26 16:25:15 +01:00
|
|
|
for (var module in moduleConfigs) {
|
|
|
|
if (moduleConfigs.hasOwnProperty(module)) {
|
|
|
|
var nodes = moduleConfigs[module].nodes;
|
|
|
|
for (var node in nodes) {
|
|
|
|
if (nodes.hasOwnProperty(node)) {
|
|
|
|
list.push(filterNodeInfo(nodes[node]));
|
|
|
|
}
|
|
|
|
}
|
2014-11-06 11:00:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
},
|
2014-11-20 16:17:13 +01:00
|
|
|
getModuleList: function() {
|
2014-11-06 11:00:25 +01:00
|
|
|
var list = [];
|
2014-11-24 16:44:11 +01:00
|
|
|
for (var module in moduleNodes) {
|
|
|
|
if (moduleNodes.hasOwnProperty(module)) {
|
|
|
|
var nodes = moduleNodes[module];
|
2014-11-06 11:00:25 +01:00
|
|
|
var m = {
|
2014-11-20 16:17:13 +01:00
|
|
|
name: module,
|
2014-11-26 16:25:15 +01:00
|
|
|
version: moduleConfigs[module].version,
|
2014-11-06 11:00:25 +01:00
|
|
|
nodes: []
|
|
|
|
};
|
|
|
|
for (var i = 0; i < nodes.length; ++i) {
|
2014-11-26 16:25:15 +01:00
|
|
|
m.nodes.push(filterNodeInfo(moduleConfigs[module].nodes[nodes[i]]));
|
2014-11-06 11:00:25 +01:00
|
|
|
}
|
|
|
|
list.push(m);
|
2014-08-28 01:35:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return list;
|
2014-08-01 23:05:49 +02:00
|
|
|
},
|
2014-11-20 16:17:13 +01:00
|
|
|
getModuleInfo: function(module) {
|
2014-11-24 16:44:11 +01:00
|
|
|
if (moduleNodes[module]) {
|
|
|
|
var nodes = moduleNodes[module];
|
2014-11-21 11:36:32 +01:00
|
|
|
var m = {
|
|
|
|
name: module,
|
2014-11-26 16:25:15 +01:00
|
|
|
version: moduleConfigs[module].version,
|
2014-11-21 11:36:32 +01:00
|
|
|
nodes: []
|
|
|
|
};
|
|
|
|
for (var i = 0; i < nodes.length; ++i) {
|
2014-11-26 16:25:15 +01:00
|
|
|
m.nodes.push(filterNodeInfo(moduleConfigs[module].nodes[nodes[i]]));
|
2014-11-21 11:36:32 +01:00
|
|
|
}
|
|
|
|
return m;
|
|
|
|
} else {
|
|
|
|
return null;
|
2014-11-06 11:00:25 +01:00
|
|
|
}
|
|
|
|
},
|
2014-12-08 17:26:54 +01:00
|
|
|
getModuleVersion: function(module) {
|
|
|
|
return moduleConfigs[module].version;
|
|
|
|
},
|
2014-08-01 23:05:49 +02:00
|
|
|
registerNodeConstructor: function(type,constructor) {
|
|
|
|
if (nodeConstructors[type]) {
|
|
|
|
throw new Error(type+" already registered");
|
|
|
|
}
|
2014-08-04 18:12:54 +02:00
|
|
|
//TODO: Ensure type is known - but doing so will break some tests
|
|
|
|
// that don't have a way to register a node template ahead
|
|
|
|
// of registering the constructor
|
2014-08-01 23:05:49 +02:00
|
|
|
util.inherits(constructor,Node);
|
|
|
|
nodeConstructors[type] = constructor;
|
|
|
|
events.emit("type-registered",type);
|
|
|
|
},
|
2014-11-06 11:00:25 +01:00
|
|
|
|
2014-08-01 23:05:49 +02:00
|
|
|
/**
|
|
|
|
* Gets all of the node template configs
|
|
|
|
* @return all of the node templates in a single string
|
|
|
|
*/
|
|
|
|
getAllNodeConfigs: function() {
|
|
|
|
if (!nodeConfigCache) {
|
|
|
|
var result = "";
|
|
|
|
var script = "";
|
|
|
|
for (var i=0;i<nodeList.length;i++) {
|
2014-11-26 16:25:15 +01:00
|
|
|
var id = nodeList[i];
|
|
|
|
var config = moduleConfigs[getModule(id)].nodes[getNode(id)];
|
2014-08-28 01:35:07 +02:00
|
|
|
if (config.enabled && !config.err) {
|
2014-08-02 00:42:01 +02:00
|
|
|
result += config.config;
|
|
|
|
script += config.script;
|
2014-08-01 23:05:49 +02:00
|
|
|
}
|
|
|
|
}
|
2014-08-04 18:12:54 +02:00
|
|
|
if (script.length > 0) {
|
|
|
|
result += '<script type="text/javascript">';
|
|
|
|
result += UglifyJS.minify(script, {fromString: true}).code;
|
|
|
|
result += '</script>';
|
|
|
|
}
|
2014-08-01 23:05:49 +02:00
|
|
|
nodeConfigCache = result;
|
|
|
|
}
|
|
|
|
return nodeConfigCache;
|
|
|
|
},
|
2014-11-06 11:00:25 +01:00
|
|
|
|
2014-08-01 23:05:49 +02:00
|
|
|
getNodeConfig: function(id) {
|
2015-01-10 23:09:37 +01:00
|
|
|
var config = moduleConfigs[getModule(id)];
|
|
|
|
if (!config) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
config = config.nodes[getNode(id)];
|
2014-08-01 23:05:49 +02:00
|
|
|
if (config) {
|
2014-08-02 00:42:01 +02:00
|
|
|
var result = config.config;
|
2014-08-28 01:35:07 +02:00
|
|
|
if (config.script) {
|
|
|
|
result += '<script type="text/javascript">'+config.script+'</script>';
|
|
|
|
}
|
2014-08-01 23:05:49 +02:00
|
|
|
return result;
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
},
|
2014-11-06 11:00:25 +01:00
|
|
|
|
2014-08-01 23:05:49 +02:00
|
|
|
getNodeConstructor: function(type) {
|
2014-11-26 16:25:15 +01:00
|
|
|
var id = nodeTypeToId[type];
|
|
|
|
|
|
|
|
var config;
|
|
|
|
if (typeof id === "undefined") {
|
|
|
|
config = undefined;
|
|
|
|
} else {
|
|
|
|
config = moduleConfigs[getModule(id)].nodes[getNode(id)];
|
|
|
|
}
|
|
|
|
|
2014-08-28 01:35:07 +02:00
|
|
|
if (!config || (config.enabled && !config.err)) {
|
2014-08-04 18:12:54 +02:00
|
|
|
return nodeConstructors[type];
|
|
|
|
}
|
|
|
|
return null;
|
2014-08-01 23:05:49 +02:00
|
|
|
},
|
2014-11-06 11:00:25 +01:00
|
|
|
|
2014-08-01 23:05:49 +02:00
|
|
|
clear: function() {
|
|
|
|
nodeConfigCache = null;
|
2014-11-26 16:25:15 +01:00
|
|
|
moduleConfigs = {};
|
2014-08-01 23:05:49 +02:00
|
|
|
nodeList = [];
|
|
|
|
nodeConstructors = {};
|
2014-08-04 18:12:54 +02:00
|
|
|
nodeTypeToId = {};
|
|
|
|
},
|
2014-11-06 11:00:25 +01:00
|
|
|
|
2014-08-04 18:12:54 +02:00
|
|
|
getTypeId: function(type) {
|
|
|
|
return nodeTypeToId[type];
|
|
|
|
},
|
2014-11-06 11:00:25 +01:00
|
|
|
|
2014-11-24 16:44:11 +01:00
|
|
|
getNodeModuleInfo: function(module) {
|
|
|
|
return moduleNodes[module];
|
2014-08-28 01:35:07 +02:00
|
|
|
},
|
2014-11-06 11:00:25 +01:00
|
|
|
|
2014-11-26 16:25:15 +01:00
|
|
|
enableNodeSet: function(typeOrId) {
|
2014-08-28 01:35:07 +02:00
|
|
|
if (!settings.available()) {
|
|
|
|
throw new Error("Settings unavailable");
|
|
|
|
}
|
2014-11-27 17:42:45 +01:00
|
|
|
|
2014-11-26 16:25:15 +01:00
|
|
|
var id = typeOrId;
|
|
|
|
if (nodeTypeToId[typeOrId]) {
|
|
|
|
id = nodeTypeToId[typeOrId];
|
2014-11-06 11:00:25 +01:00
|
|
|
}
|
2014-11-26 16:25:15 +01:00
|
|
|
|
2014-11-27 17:42:45 +01:00
|
|
|
var config;
|
|
|
|
try {
|
|
|
|
config = moduleConfigs[getModule(id)].nodes[getNode(id)];
|
2014-08-28 01:35:07 +02:00
|
|
|
delete config.err;
|
2014-08-04 18:12:54 +02:00
|
|
|
config.enabled = true;
|
2014-08-28 01:35:07 +02:00
|
|
|
if (!config.loaded) {
|
|
|
|
// TODO: honour the promise this returns
|
|
|
|
loadNodeModule(config);
|
|
|
|
}
|
2014-08-04 18:12:54 +02:00
|
|
|
nodeConfigCache = null;
|
2014-08-28 01:35:07 +02:00
|
|
|
saveNodeList();
|
2014-11-27 17:42:45 +01:00
|
|
|
} catch (err) {
|
2014-11-26 16:25:15 +01:00
|
|
|
throw new Error("Unrecognised id: "+typeOrId);
|
2014-08-04 18:12:54 +02:00
|
|
|
}
|
2014-08-28 01:35:07 +02:00
|
|
|
return filterNodeInfo(config);
|
2014-08-04 18:12:54 +02:00
|
|
|
},
|
2014-11-06 11:00:25 +01:00
|
|
|
|
2014-11-26 16:25:15 +01:00
|
|
|
disableNodeSet: function(typeOrId) {
|
2014-08-28 01:35:07 +02:00
|
|
|
if (!settings.available()) {
|
|
|
|
throw new Error("Settings unavailable");
|
|
|
|
}
|
2014-11-26 16:25:15 +01:00
|
|
|
var id = typeOrId;
|
|
|
|
if (nodeTypeToId[typeOrId]) {
|
|
|
|
id = nodeTypeToId[typeOrId];
|
2014-11-06 11:00:25 +01:00
|
|
|
}
|
2014-11-27 17:42:45 +01:00
|
|
|
var config;
|
|
|
|
try {
|
|
|
|
config = moduleConfigs[getModule(id)].nodes[getNode(id)];
|
2014-08-28 01:35:07 +02:00
|
|
|
// TODO: persist setting
|
2014-08-04 18:12:54 +02:00
|
|
|
config.enabled = false;
|
|
|
|
nodeConfigCache = null;
|
2014-08-28 01:35:07 +02:00
|
|
|
saveNodeList();
|
2014-11-27 17:42:45 +01:00
|
|
|
} catch (err) {
|
2014-08-28 01:35:07 +02:00
|
|
|
throw new Error("Unrecognised id: "+id);
|
2014-08-04 18:12:54 +02:00
|
|
|
}
|
2014-08-28 01:35:07 +02:00
|
|
|
return filterNodeInfo(config);
|
|
|
|
},
|
2014-11-06 11:00:25 +01:00
|
|
|
|
2014-09-23 18:09:23 +02:00
|
|
|
saveNodeList: saveNodeList,
|
2014-11-06 11:00:25 +01:00
|
|
|
|
2014-11-26 17:41:31 +01:00
|
|
|
cleanModuleList: function() {
|
2014-09-23 18:09:23 +02:00
|
|
|
var removed = false;
|
2014-11-26 16:25:15 +01:00
|
|
|
for (var mod in moduleConfigs) {
|
|
|
|
if (moduleConfigs.hasOwnProperty(mod)) {
|
2015-02-04 11:27:02 +01:00
|
|
|
var nodes = moduleConfigs[mod].nodes;
|
|
|
|
var node;
|
|
|
|
if (mod == "node-red") {
|
|
|
|
// For core nodes, look for nodes that are enabled, !loaded and !errored
|
|
|
|
for (node in nodes) {
|
|
|
|
if (nodes.hasOwnProperty(node)) {
|
|
|
|
var n = nodes[node];
|
|
|
|
if (n.enabled && !n.err && !n.loaded) {
|
|
|
|
registry.removeNode(mod+"/"+node);
|
|
|
|
removed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (moduleConfigs[mod] && !moduleNodes[mod]) {
|
|
|
|
// For node modules, look for missing ones
|
|
|
|
for (node in nodes) {
|
2014-11-26 17:41:31 +01:00
|
|
|
if (nodes.hasOwnProperty(node)) {
|
|
|
|
registry.removeNode(mod+"/"+node);
|
|
|
|
removed = true;
|
|
|
|
}
|
|
|
|
}
|
2014-09-23 18:09:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (removed) {
|
|
|
|
saveNodeList();
|
|
|
|
}
|
|
|
|
}
|
2014-11-06 11:59:34 +01:00
|
|
|
};
|
2014-08-01 23:05:49 +02:00
|
|
|
})();
|
|
|
|
|
2014-07-28 17:37:39 +02:00
|
|
|
|
2014-08-01 23:05:49 +02:00
|
|
|
|
|
|
|
function init(_settings) {
|
|
|
|
Node = require("./Node");
|
|
|
|
settings = _settings;
|
2014-08-28 01:35:07 +02:00
|
|
|
registry.init();
|
2014-08-01 23:05:49 +02:00
|
|
|
}
|
2014-05-03 23:26:35 +02:00
|
|
|
|
2014-07-25 00:16:41 +02:00
|
|
|
/**
|
|
|
|
* Synchronously walks the directory looking for node files.
|
|
|
|
* Emits 'node-icon-dir' events for an icon dirs found
|
|
|
|
* @param dir the directory to search
|
|
|
|
* @return an array of fully-qualified paths to .js files
|
|
|
|
*/
|
|
|
|
function getNodeFiles(dir) {
|
|
|
|
var result = [];
|
2014-08-01 23:05:49 +02:00
|
|
|
var files = [];
|
|
|
|
try {
|
|
|
|
files = fs.readdirSync(dir);
|
|
|
|
} catch(err) {
|
|
|
|
return result;
|
|
|
|
}
|
2014-07-25 00:16:41 +02:00
|
|
|
files.sort();
|
|
|
|
files.forEach(function(fn) {
|
|
|
|
var stats = fs.statSync(path.join(dir,fn));
|
|
|
|
if (stats.isFile()) {
|
|
|
|
if (/\.js$/.test(fn)) {
|
2014-08-01 23:05:49 +02:00
|
|
|
var valid = true;
|
|
|
|
if (settings.nodesExcludes) {
|
|
|
|
for (var i=0;i<settings.nodesExcludes.length;i++) {
|
|
|
|
if (settings.nodesExcludes[i] == fn) {
|
|
|
|
valid = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-11-06 11:59:34 +01:00
|
|
|
valid = valid && fs.existsSync(path.join(dir,fn.replace(/\.js$/,".html")));
|
2014-11-06 11:00:25 +01:00
|
|
|
|
2014-08-01 23:05:49 +02:00
|
|
|
if (valid) {
|
|
|
|
result.push(path.join(dir,fn));
|
|
|
|
}
|
2014-05-07 21:45:26 +02:00
|
|
|
}
|
2014-07-25 00:16:41 +02:00
|
|
|
} else if (stats.isDirectory()) {
|
2014-11-06 11:00:25 +01:00
|
|
|
// Ignore /.dirs/, /lib/ /node_modules/
|
2014-07-25 00:16:41 +02:00
|
|
|
if (!/^(\..*|lib|icons|node_modules|test)$/.test(fn)) {
|
|
|
|
result = result.concat(getNodeFiles(path.join(dir,fn)));
|
|
|
|
} else if (fn === "icons") {
|
|
|
|
events.emit("node-icon-dir",path.join(dir,fn));
|
|
|
|
}
|
|
|
|
}
|
2014-05-03 23:26:35 +02:00
|
|
|
});
|
2014-07-25 00:16:41 +02:00
|
|
|
return result;
|
2014-05-03 23:26:35 +02:00
|
|
|
}
|
|
|
|
|
2015-02-25 15:23:59 +01:00
|
|
|
function scanDirForNodesModules(dir,moduleName) {
|
|
|
|
var results = [];
|
|
|
|
try {
|
|
|
|
var files = fs.readdirSync(dir);
|
|
|
|
for (var i=0;i<files.length;i++) {
|
|
|
|
var fn = files[i];
|
|
|
|
if (!registry.getNodeModuleInfo(fn)) {
|
|
|
|
if (!moduleName || fn == moduleName) {
|
|
|
|
var pkgfn = path.join(dir,fn,"package.json");
|
|
|
|
try {
|
|
|
|
var pkg = require(pkgfn);
|
|
|
|
if (pkg['node-red']) {
|
|
|
|
var moduleDir = path.join(dir,fn);
|
|
|
|
results.push({dir:moduleDir,package:pkg});
|
|
|
|
}
|
|
|
|
} catch(err) {
|
|
|
|
if (err.code != "MODULE_NOT_FOUND") {
|
|
|
|
// TODO: handle unexpected error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fn == moduleName) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch(err) {
|
|
|
|
}
|
|
|
|
return results;
|
|
|
|
}
|
|
|
|
|
2014-07-25 00:16:41 +02:00
|
|
|
/**
|
|
|
|
* Scans the node_modules path for nodes
|
2014-07-30 19:07:20 +02:00
|
|
|
* @param moduleName the name of the module to be found
|
2014-07-25 00:16:41 +02:00
|
|
|
* @return a list of node modules: {dir,package}
|
|
|
|
*/
|
2014-07-28 17:37:39 +02:00
|
|
|
function scanTreeForNodesModules(moduleName) {
|
2014-07-25 00:16:41 +02:00
|
|
|
var dir = __dirname+"/../../nodes";
|
|
|
|
var results = [];
|
2015-02-25 15:23:59 +01:00
|
|
|
var userDir;
|
|
|
|
|
|
|
|
if (settings.userDir) {
|
|
|
|
userDir = path.join(settings.userDir,"node_modules");
|
|
|
|
results = results.concat(scanDirForNodesModules(userDir,moduleName));
|
|
|
|
}
|
|
|
|
|
2014-07-25 00:16:41 +02:00
|
|
|
var up = path.resolve(path.join(dir,".."));
|
|
|
|
while (up !== dir) {
|
|
|
|
var pm = path.join(dir,"node_modules");
|
2015-02-25 15:23:59 +01:00
|
|
|
if (pm != userDir) {
|
|
|
|
results = results.concat(scanDirForNodesModules(pm,moduleName));
|
2014-05-03 23:26:35 +02:00
|
|
|
}
|
2014-07-25 00:16:41 +02:00
|
|
|
dir = up;
|
|
|
|
up = path.resolve(path.join(dir,".."));
|
|
|
|
}
|
|
|
|
return results;
|
|
|
|
}
|
|
|
|
|
2014-07-28 17:37:39 +02:00
|
|
|
/**
|
|
|
|
* Loads the nodes provided in an npm package.
|
|
|
|
* @param moduleDir the root directory of the package
|
|
|
|
* @param pkg the module's package.json object
|
|
|
|
*/
|
2014-12-08 11:11:59 +01:00
|
|
|
function loadNodesFromModule(moduleDir,pkg) {
|
2014-07-28 17:37:39 +02:00
|
|
|
var nodes = pkg['node-red'].nodes||{};
|
2014-08-01 23:05:49 +02:00
|
|
|
var results = [];
|
2014-07-28 17:37:39 +02:00
|
|
|
var iconDirs = [];
|
|
|
|
for (var n in nodes) {
|
|
|
|
if (nodes.hasOwnProperty(n)) {
|
2014-08-03 22:17:24 +02:00
|
|
|
var file = path.join(moduleDir,nodes[n]);
|
2014-09-20 23:25:00 +02:00
|
|
|
try {
|
2014-12-08 11:11:59 +01:00
|
|
|
results.push(loadNodeConfig(file,pkg.name,n,pkg.version));
|
2014-09-20 23:25:00 +02:00
|
|
|
} catch(err) {
|
|
|
|
}
|
2014-07-28 17:37:39 +02:00
|
|
|
var iconDir = path.join(moduleDir,path.dirname(nodes[n]),"icons");
|
|
|
|
if (iconDirs.indexOf(iconDir) == -1) {
|
|
|
|
if (fs.existsSync(iconDir)) {
|
|
|
|
events.emit("node-icon-dir",iconDir);
|
|
|
|
iconDirs.push(iconDir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-01 23:05:49 +02:00
|
|
|
return results;
|
2014-07-28 17:37:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-25 00:16:41 +02:00
|
|
|
/**
|
2014-08-01 23:05:49 +02:00
|
|
|
* Loads a node's configuration
|
|
|
|
* @param file the fully qualified path of the node's .js file
|
|
|
|
* @param name the name of the node
|
|
|
|
* @return the node object
|
2014-07-28 17:37:39 +02:00
|
|
|
* {
|
2014-08-01 23:05:49 +02:00
|
|
|
* id: a unqiue id for the node file
|
2014-07-28 17:37:39 +02:00
|
|
|
* name: the name of the node file, or label from the npm module
|
2014-08-01 23:05:49 +02:00
|
|
|
* file: the fully qualified path to the node's .js file
|
2014-07-28 17:37:39 +02:00
|
|
|
* template: the fully qualified path to the node's .html file
|
|
|
|
* config: the non-script parts of the node's .html file
|
|
|
|
* script: the script part of the node's .html file
|
2014-08-01 23:05:49 +02:00
|
|
|
* types: an array of node type names in this file
|
2014-07-28 17:37:39 +02:00
|
|
|
* }
|
2014-07-25 00:16:41 +02:00
|
|
|
*/
|
2014-11-21 17:35:29 +01:00
|
|
|
function loadNodeConfig(file,module,name,version) {
|
2014-11-20 11:06:18 +01:00
|
|
|
var id = module + "/" + name;
|
2014-08-28 01:35:07 +02:00
|
|
|
var info = registry.getNodeInfo(id);
|
2014-11-06 11:00:25 +01:00
|
|
|
|
2014-08-28 01:35:07 +02:00
|
|
|
var isEnabled = true;
|
|
|
|
|
|
|
|
if (info) {
|
|
|
|
if (info.hasOwnProperty("loaded")) {
|
|
|
|
throw new Error(file+" already loaded");
|
|
|
|
}
|
|
|
|
isEnabled = info.enabled;
|
2014-08-02 00:42:01 +02:00
|
|
|
}
|
2014-11-06 11:00:25 +01:00
|
|
|
|
2014-08-01 23:05:49 +02:00
|
|
|
var node = {
|
|
|
|
id: id,
|
2014-11-20 11:06:18 +01:00
|
|
|
module: module,
|
|
|
|
name: name,
|
2014-08-01 23:05:49 +02:00
|
|
|
file: file,
|
|
|
|
template: file.replace(/\.js$/,".html"),
|
2014-08-28 01:35:07 +02:00
|
|
|
enabled: isEnabled,
|
|
|
|
loaded:false
|
2014-11-06 11:59:34 +01:00
|
|
|
};
|
2014-11-06 11:00:25 +01:00
|
|
|
|
2014-09-20 23:25:00 +02:00
|
|
|
try {
|
|
|
|
var content = fs.readFileSync(node.template,'utf8');
|
2014-11-06 11:00:25 +01:00
|
|
|
|
2014-09-20 23:25:00 +02:00
|
|
|
var types = [];
|
2014-11-06 11:00:25 +01:00
|
|
|
|
2014-09-20 23:25:00 +02:00
|
|
|
var regExp = /<script ([^>]*)data-template-name=['"]([^'"]*)['"]/gi;
|
|
|
|
var match = null;
|
2014-11-06 11:00:25 +01:00
|
|
|
|
2014-09-20 23:25:00 +02:00
|
|
|
while((match = regExp.exec(content)) !== null) {
|
|
|
|
types.push(match[2]);
|
|
|
|
}
|
|
|
|
node.types = types;
|
|
|
|
node.config = content;
|
2014-11-06 11:00:25 +01:00
|
|
|
|
2014-09-20 23:25:00 +02:00
|
|
|
// TODO: parse out the javascript portion of the template
|
|
|
|
node.script = "";
|
2014-11-06 11:00:25 +01:00
|
|
|
|
2014-09-20 23:25:00 +02:00
|
|
|
for (var i=0;i<node.types.length;i++) {
|
|
|
|
if (registry.getTypeId(node.types[i])) {
|
|
|
|
node.err = node.types[i]+" already registered";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch(err) {
|
|
|
|
node.types = [];
|
|
|
|
if (err.code === 'ENOENT') {
|
|
|
|
node.err = "Error: "+file+" does not exist";
|
|
|
|
} else {
|
|
|
|
node.err = err.toString();
|
2014-08-04 18:12:54 +02:00
|
|
|
}
|
|
|
|
}
|
2014-12-08 10:43:59 +01:00
|
|
|
|
2014-11-21 17:35:29 +01:00
|
|
|
registry.addNodeSet(id,node,version);
|
2014-08-01 23:05:49 +02:00
|
|
|
return node;
|
2014-05-03 23:26:35 +02:00
|
|
|
}
|
|
|
|
|
2014-07-25 00:16:41 +02:00
|
|
|
/**
|
|
|
|
* Loads all palette nodes
|
2014-08-01 23:05:49 +02:00
|
|
|
* @param defaultNodesDir optional parameter, when set, it overrides the default
|
|
|
|
* location of nodeFiles - used by the tests
|
|
|
|
* @return a promise that resolves on completion of loading
|
2014-07-25 00:16:41 +02:00
|
|
|
*/
|
2014-08-03 22:17:24 +02:00
|
|
|
function load(defaultNodesDir,disableNodePathScan) {
|
2014-05-03 23:26:35 +02:00
|
|
|
return when.promise(function(resolve,reject) {
|
2014-07-25 00:16:41 +02:00
|
|
|
// Find all of the nodes to load
|
2014-07-30 19:07:20 +02:00
|
|
|
var nodeFiles;
|
2015-02-25 15:23:59 +01:00
|
|
|
var dir;
|
2014-07-30 19:07:20 +02:00
|
|
|
if(defaultNodesDir) {
|
|
|
|
nodeFiles = getNodeFiles(path.resolve(defaultNodesDir));
|
|
|
|
} else {
|
|
|
|
nodeFiles = getNodeFiles(__dirname+"/../../nodes");
|
|
|
|
}
|
2014-11-06 11:00:25 +01:00
|
|
|
|
2015-02-25 15:23:59 +01:00
|
|
|
if (settings.userDir) {
|
|
|
|
dir = path.join(settings.userDir,"nodes");
|
|
|
|
nodeFiles = nodeFiles.concat(getNodeFiles(dir));
|
|
|
|
}
|
2014-07-25 00:16:41 +02:00
|
|
|
if (settings.nodesDir) {
|
2015-02-25 15:23:59 +01:00
|
|
|
dir = settings.nodesDir;
|
2014-07-25 00:16:41 +02:00
|
|
|
if (typeof settings.nodesDir == "string") {
|
|
|
|
dir = [dir];
|
2014-05-03 23:26:35 +02:00
|
|
|
}
|
2014-07-25 00:16:41 +02:00
|
|
|
for (var i=0;i<dir.length;i++) {
|
|
|
|
nodeFiles = nodeFiles.concat(getNodeFiles(dir[i]));
|
|
|
|
}
|
|
|
|
}
|
2014-08-01 23:05:49 +02:00
|
|
|
var nodes = [];
|
2014-07-25 00:16:41 +02:00
|
|
|
nodeFiles.forEach(function(file) {
|
2014-08-04 18:12:54 +02:00
|
|
|
try {
|
2014-12-08 11:11:59 +01:00
|
|
|
nodes.push(loadNodeConfig(file,"node-red",path.basename(file).replace(/^\d+-/,"").replace(/\.js$/,""),settings.version));
|
2014-08-04 18:12:54 +02:00
|
|
|
} catch(err) {
|
2014-11-06 11:00:25 +01:00
|
|
|
//
|
2014-08-04 18:12:54 +02:00
|
|
|
}
|
2014-07-25 00:16:41 +02:00
|
|
|
});
|
2014-11-06 11:00:25 +01:00
|
|
|
|
2014-08-01 23:05:49 +02:00
|
|
|
// TODO: disabling npm module loading if defaultNodesDir set
|
|
|
|
// This indicates a test is being run - don't want to pick up
|
|
|
|
// unexpected nodes.
|
|
|
|
// Urgh.
|
2014-08-03 22:17:24 +02:00
|
|
|
if (!disableNodePathScan) {
|
2014-08-01 23:05:49 +02:00
|
|
|
// Find all of the modules containing nodes
|
|
|
|
var moduleFiles = scanTreeForNodesModules();
|
|
|
|
moduleFiles.forEach(function(moduleFile) {
|
|
|
|
nodes = nodes.concat(loadNodesFromModule(moduleFile.dir,moduleFile.package));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
var promises = [];
|
|
|
|
nodes.forEach(function(node) {
|
2014-09-20 23:25:00 +02:00
|
|
|
if (!node.err) {
|
|
|
|
promises.push(loadNodeModule(node));
|
|
|
|
}
|
2014-07-25 00:16:41 +02:00
|
|
|
});
|
2014-11-06 11:00:25 +01:00
|
|
|
|
2014-08-01 23:05:49 +02:00
|
|
|
//resolve([]);
|
|
|
|
when.settle(promises).then(function(results) {
|
2014-07-28 17:37:39 +02:00
|
|
|
// Trigger a load of the configs to get it precached
|
2014-08-01 23:05:49 +02:00
|
|
|
registry.getAllNodeConfigs();
|
2014-11-06 11:00:25 +01:00
|
|
|
|
2014-08-28 01:35:07 +02:00
|
|
|
if (settings.available()) {
|
2014-09-23 18:09:23 +02:00
|
|
|
resolve(registry.saveNodeList());
|
|
|
|
} else {
|
|
|
|
resolve();
|
2014-08-28 01:35:07 +02:00
|
|
|
}
|
2014-11-06 11:00:25 +01:00
|
|
|
});
|
2014-05-03 23:26:35 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-07-25 00:16:41 +02:00
|
|
|
/**
|
2014-08-01 23:05:49 +02:00
|
|
|
* Loads the specified node into the runtime
|
|
|
|
* @param node a node info object - see loadNodeConfig
|
|
|
|
* @return a promise that resolves to an update node info object. The object
|
|
|
|
* has the following properties added:
|
|
|
|
* err: any error encountered whilst loading the node
|
2014-11-06 11:00:25 +01:00
|
|
|
*
|
2014-07-25 00:16:41 +02:00
|
|
|
*/
|
2014-08-02 00:42:01 +02:00
|
|
|
function loadNodeModule(node) {
|
2014-08-01 23:05:49 +02:00
|
|
|
var nodeDir = path.dirname(node.file);
|
|
|
|
var nodeFn = path.basename(node.file);
|
2014-08-28 01:35:07 +02:00
|
|
|
if (!node.enabled) {
|
|
|
|
return when.resolve(node);
|
|
|
|
}
|
2014-08-01 23:05:49 +02:00
|
|
|
try {
|
|
|
|
var loadPromise = null;
|
|
|
|
var r = require(node.file);
|
|
|
|
if (typeof r === "function") {
|
|
|
|
var promise = r(require('../red'));
|
|
|
|
if (promise != null && typeof promise.then === "function") {
|
|
|
|
loadPromise = promise.then(function() {
|
|
|
|
node.enabled = true;
|
2014-08-28 01:35:07 +02:00
|
|
|
node.loaded = true;
|
2014-08-01 23:05:49 +02:00
|
|
|
return node;
|
|
|
|
}).otherwise(function(err) {
|
|
|
|
node.err = err;
|
|
|
|
return node;
|
|
|
|
});
|
|
|
|
}
|
2014-07-28 17:37:39 +02:00
|
|
|
}
|
2014-08-01 23:05:49 +02:00
|
|
|
if (loadPromise == null) {
|
|
|
|
node.enabled = true;
|
2014-08-28 01:35:07 +02:00
|
|
|
node.loaded = true;
|
2014-08-01 23:05:49 +02:00
|
|
|
loadPromise = when.resolve(node);
|
|
|
|
}
|
|
|
|
return loadPromise;
|
|
|
|
} catch(err) {
|
|
|
|
node.err = err;
|
|
|
|
return when.resolve(node);
|
2014-07-25 00:16:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-28 01:35:07 +02:00
|
|
|
function loadNodeList(nodes) {
|
2014-08-04 18:12:54 +02:00
|
|
|
var promises = [];
|
|
|
|
nodes.forEach(function(node) {
|
2014-09-20 23:42:48 +02:00
|
|
|
if (!node.err) {
|
|
|
|
promises.push(loadNodeModule(node));
|
|
|
|
} else {
|
|
|
|
promises.push(node);
|
|
|
|
}
|
2014-08-04 18:12:54 +02:00
|
|
|
});
|
2014-11-06 11:00:25 +01:00
|
|
|
|
2014-08-04 18:12:54 +02:00
|
|
|
return when.settle(promises).then(function(results) {
|
2014-09-23 18:09:23 +02:00
|
|
|
return registry.saveNodeList().then(function() {
|
|
|
|
var list = results.map(function(r) {
|
|
|
|
return filterNodeInfo(r.value);
|
|
|
|
});
|
|
|
|
return list;
|
2014-08-04 18:12:54 +02:00
|
|
|
});
|
2014-08-28 01:35:07 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function addNode(file) {
|
|
|
|
if (!settings.available()) {
|
|
|
|
throw new Error("Settings unavailable");
|
|
|
|
}
|
|
|
|
var nodes = [];
|
2014-11-06 11:00:25 +01:00
|
|
|
try {
|
2014-12-08 11:11:59 +01:00
|
|
|
nodes.push(loadNodeConfig(file,"node-red",path.basename(file).replace(/^\d+-/,"").replace(/\.js$/,""),settings.version));
|
2014-08-28 01:35:07 +02:00
|
|
|
} catch(err) {
|
|
|
|
return when.reject(err);
|
|
|
|
}
|
|
|
|
return loadNodeList(nodes);
|
|
|
|
}
|
|
|
|
|
2014-12-08 11:11:59 +01:00
|
|
|
function addModule(module) {
|
2014-08-28 01:35:07 +02:00
|
|
|
if (!settings.available()) {
|
|
|
|
throw new Error("Settings unavailable");
|
|
|
|
}
|
|
|
|
var nodes = [];
|
2014-11-20 16:17:13 +01:00
|
|
|
if (registry.getNodeModuleInfo(module)) {
|
2014-08-28 01:35:07 +02:00
|
|
|
return when.reject(new Error("Module already loaded"));
|
|
|
|
}
|
|
|
|
var moduleFiles = scanTreeForNodesModules(module);
|
|
|
|
if (moduleFiles.length === 0) {
|
|
|
|
var err = new Error("Cannot find module '" + module + "'");
|
|
|
|
err.code = 'MODULE_NOT_FOUND';
|
|
|
|
return when.reject(err);
|
|
|
|
}
|
|
|
|
moduleFiles.forEach(function(moduleFile) {
|
2014-12-08 11:11:59 +01:00
|
|
|
nodes = nodes.concat(loadNodesFromModule(moduleFile.dir,moduleFile.package));
|
2014-08-02 00:42:01 +02:00
|
|
|
});
|
2014-08-28 01:35:07 +02:00
|
|
|
return loadNodeList(nodes);
|
2014-08-02 00:42:01 +02:00
|
|
|
}
|
|
|
|
|
2014-07-28 17:37:39 +02:00
|
|
|
module.exports = {
|
2014-05-03 23:26:35 +02:00
|
|
|
init:init,
|
|
|
|
load:load,
|
2014-08-01 23:05:49 +02:00
|
|
|
clear: registry.clear,
|
|
|
|
registerType: registry.registerNodeConstructor,
|
2014-11-20 16:17:13 +01:00
|
|
|
|
2014-08-01 23:05:49 +02:00
|
|
|
get: registry.getNodeConstructor,
|
2014-08-04 18:12:54 +02:00
|
|
|
getNodeInfo: registry.getNodeInfo,
|
2014-08-01 23:05:49 +02:00
|
|
|
getNodeList: registry.getNodeList,
|
2014-11-20 16:17:13 +01:00
|
|
|
|
|
|
|
getNodeModuleInfo: registry.getNodeModuleInfo,
|
|
|
|
|
|
|
|
getModuleInfo: registry.getModuleInfo,
|
|
|
|
getModuleList: registry.getModuleList,
|
2014-12-08 17:26:54 +01:00
|
|
|
getModuleVersion: registry.getModuleVersion,
|
2014-11-20 16:17:13 +01:00
|
|
|
|
2014-08-01 23:05:49 +02:00
|
|
|
getNodeConfigs: registry.getAllNodeConfigs,
|
|
|
|
getNodeConfig: registry.getNodeConfig,
|
2014-11-20 16:17:13 +01:00
|
|
|
|
2014-08-04 18:12:54 +02:00
|
|
|
addNode: addNode,
|
|
|
|
removeNode: registry.removeNode,
|
|
|
|
enableNode: registry.enableNodeSet,
|
2014-08-28 01:35:07 +02:00
|
|
|
disableNode: registry.disableNodeSet,
|
2014-11-06 11:00:25 +01:00
|
|
|
|
2014-08-28 01:35:07 +02:00
|
|
|
addModule: addModule,
|
2014-09-23 18:09:23 +02:00
|
|
|
removeModule: registry.removeModule,
|
2014-11-26 17:41:31 +01:00
|
|
|
cleanModuleList: registry.cleanModuleList
|
2014-11-06 11:59:34 +01:00
|
|
|
};
|