1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Refactor nodeModules.nodes to moduleNodes

This commit is contained in:
Anna Thomas 2014-11-24 15:44:11 +00:00
parent d7f249eac4
commit 04ffaeb2b8

View File

@ -52,7 +52,7 @@ var registry = (function() {
var nodeList = []; var nodeList = [];
var nodeConstructors = {}; var nodeConstructors = {};
var nodeTypeToId = {}; var nodeTypeToId = {};
var nodeModules = {}; var moduleNodes = {};
function saveNodeList() { function saveNodeList() {
var nodeList = {}; var nodeList = {};
@ -89,7 +89,7 @@ var registry = (function() {
} else { } else {
nodeConfigs = {}; nodeConfigs = {};
} }
nodeModules = {}; moduleNodes = {};
nodeTypeToId = {}; nodeTypeToId = {};
nodeConstructors = {}; nodeConstructors = {};
nodeList = []; nodeList = [];
@ -102,11 +102,10 @@ var registry = (function() {
}); });
} }
nodeModules[set.module] = nodeModules[set.module]||{nodes:[]}; moduleNodes[set.module] = moduleNodes[set.module]||[];
nodeModules[set.module].nodes.push(set.name); moduleNodes[set.module].push(set.name);
if (version) { if (version) {
nodeModules[set.module].version = version.replace(/(\r\n|\n|\r)/gm,"");
} }
nodeConfigs[id] = set; nodeConfigs[id] = set;
@ -136,15 +135,15 @@ var registry = (function() {
if (!settings.available()) { if (!settings.available()) {
throw new Error("Settings unavailable"); throw new Error("Settings unavailable");
} }
var nodes = nodeModules[module]; var nodes = moduleNodes[module];
if (!nodes) { if (!nodes) {
throw new Error("Unrecognised module: "+module); throw new Error("Unrecognised module: "+module);
} }
var infoList = []; var infoList = [];
for (var i=0;i<nodes.nodes.length;i++) { for (var i=0;i<nodes.length;i++) {
infoList.push(registry.removeNode(module+"/"+nodes.nodes[i])); infoList.push(registry.removeNode(module+"/"+nodes[i]));
} }
delete nodeModules[module]; delete moduleNodes[module];
saveNodeList(); saveNodeList();
return infoList; return infoList;
}, },
@ -168,9 +167,9 @@ var registry = (function() {
}, },
getModuleList: function() { getModuleList: function() {
var list = []; var list = [];
for (var module in nodeModules) { for (var module in moduleNodes) {
if (nodeModules.hasOwnProperty(module)) { if (moduleNodes.hasOwnProperty(module)) {
var nodes = nodeModules[module].nodes; var nodes = moduleNodes[module];
var m = { var m = {
name: module, name: module,
nodes: [] nodes: []
@ -184,12 +183,11 @@ var registry = (function() {
return list; return list;
}, },
getModuleInfo: function(module) { getModuleInfo: function(module) {
if (nodeModules[module]) { if (moduleNodes[module]) {
console.log(nodeModules[module]); console.log(moduleNodes[module]);
var nodes = nodeModules[module].nodes; var nodes = moduleNodes[module];
var m = { var m = {
name: module, name: module,
version: nodeModules[module].version,
nodes: [] nodes: []
}; };
for (var i = 0; i < nodes.length; ++i) { for (var i = 0; i < nodes.length; ++i) {
@ -271,8 +269,8 @@ var registry = (function() {
return nodeTypeToId[type]; return nodeTypeToId[type];
}, },
getNodeModuleInfo: function(type) { getNodeModuleInfo: function(module) {
return nodeModules[type]; return moduleNodes[module];
}, },
enableNodeSet: function(id) { enableNodeSet: function(id) {
@ -327,7 +325,7 @@ var registry = (function() {
var removed = false; var removed = false;
for (var id in nodeConfigs) { for (var id in nodeConfigs) {
if (nodeConfigs.hasOwnProperty(id)) { if (nodeConfigs.hasOwnProperty(id)) {
if (nodeConfigs[id].module && !nodeModules[nodeConfigs[id].module]) { if (nodeConfigs[id].module && !moduleNodes[nodeConfigs[id].module]) {
registry.removeNode(id); registry.removeNode(id);
removed = true; removed = true;
} }