mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Add RED.require to allow nodes to access other modules
This commit is contained in:
parent
626d012775
commit
f3e1b85d82
@ -62,6 +62,17 @@ function copyObjectProperties(src,dst,copyList,blockList) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function requireModule(name) {
|
||||||
|
var moduleInfo = registry.getModuleInfo(name);
|
||||||
|
if (moduleInfo && moduleInfo.path) {
|
||||||
|
var relPath = path.relative(__dirname, moduleInfo.path);
|
||||||
|
return require(relPath);
|
||||||
|
} else {
|
||||||
|
var err = new Error(`Cannot find module '${name}'`);
|
||||||
|
err.code = "MODULE_NOT_FOUND";
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function createNodeApi(node) {
|
function createNodeApi(node) {
|
||||||
var red = {
|
var red = {
|
||||||
@ -71,6 +82,7 @@ function createNodeApi(node) {
|
|||||||
events: runtime.events,
|
events: runtime.events,
|
||||||
util: runtime.util,
|
util: runtime.util,
|
||||||
version: runtime.version,
|
version: runtime.version,
|
||||||
|
require: requireModule
|
||||||
}
|
}
|
||||||
copyObjectProperties(runtime.nodes,red.nodes,["createNode","getNode","eachNode","addCredentials","getCredentials","deleteCredentials" ]);
|
copyObjectProperties(runtime.nodes,red.nodes,["createNode","getNode","eachNode","addCredentials","getCredentials","deleteCredentials" ]);
|
||||||
red.nodes.registerType = function(type,constructor,opts) {
|
red.nodes.registerType = function(type,constructor,opts) {
|
||||||
@ -112,6 +124,7 @@ function createNodeApi(node) {
|
|||||||
|
|
||||||
function loadNodeFiles(nodeFiles) {
|
function loadNodeFiles(nodeFiles) {
|
||||||
var promises = [];
|
var promises = [];
|
||||||
|
var nodes = [];
|
||||||
for (var module in nodeFiles) {
|
for (var module in nodeFiles) {
|
||||||
/* istanbul ignore else */
|
/* istanbul ignore else */
|
||||||
if (nodeFiles.hasOwnProperty(module)) {
|
if (nodeFiles.hasOwnProperty(module)) {
|
||||||
@ -119,6 +132,7 @@ function loadNodeFiles(nodeFiles) {
|
|||||||
!semver.satisfies(runtime.version().replace(/(\-[1-9A-Za-z-][0-9A-Za-z-\.]*)?(\+[0-9A-Za-z-\.]+)?$/,""), nodeFiles[module].redVersion)) {
|
!semver.satisfies(runtime.version().replace(/(\-[1-9A-Za-z-][0-9A-Za-z-\.]*)?(\+[0-9A-Za-z-\.]+)?$/,""), nodeFiles[module].redVersion)) {
|
||||||
//TODO: log it
|
//TODO: log it
|
||||||
runtime.log.warn("["+module+"] "+runtime.log._("server.node-version-mismatch",{version:nodeFiles[module].redVersion}));
|
runtime.log.warn("["+module+"] "+runtime.log._("server.node-version-mismatch",{version:nodeFiles[module].redVersion}));
|
||||||
|
nodeFiles[module].err = "version_mismatch";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (module == "node-red" || !registry.getModuleInfo(module)) {
|
if (module == "node-red" || !registry.getModuleInfo(module)) {
|
||||||
@ -148,7 +162,14 @@ function loadNodeFiles(nodeFiles) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
promises.push(loadNodeConfig(nodeFiles[module].nodes[node]))
|
promises.push(loadNodeConfig(nodeFiles[module].nodes[node]).then((function() {
|
||||||
|
var m = module;
|
||||||
|
var n = node;
|
||||||
|
return function(nodeSet) {
|
||||||
|
nodeFiles[m].nodes[n] = nodeSet;
|
||||||
|
nodes.push(nodeSet);
|
||||||
|
}
|
||||||
|
})()));
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
@ -158,16 +179,19 @@ function loadNodeFiles(nodeFiles) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return when.settle(promises).then(function(results) {
|
return when.settle(promises).then(function(results) {
|
||||||
var nodes = results.map(function(r) {
|
for (var module in nodeFiles) {
|
||||||
registry.addNodeSet(r.value.id,r.value,r.value.version);
|
if (nodeFiles.hasOwnProperty(module)) {
|
||||||
return r.value;
|
if (!nodeFiles[module].err) {
|
||||||
});
|
registry.addModule(nodeFiles[module]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return loadNodeSetList(nodes);
|
return loadNodeSetList(nodes);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadNodeConfig(fileInfo) {
|
function loadNodeConfig(fileInfo) {
|
||||||
return when.promise(function(resolve) {
|
return new Promise(function(resolve) {
|
||||||
var file = fileInfo.file;
|
var file = fileInfo.file;
|
||||||
var module = fileInfo.module;
|
var module = fileInfo.module;
|
||||||
var name = fileInfo.name;
|
var name = fileInfo.name;
|
||||||
@ -292,7 +316,7 @@ function loadNodeSet(node) {
|
|||||||
var nodeDir = path.dirname(node.file);
|
var nodeDir = path.dirname(node.file);
|
||||||
var nodeFn = path.basename(node.file);
|
var nodeFn = path.basename(node.file);
|
||||||
if (!node.enabled) {
|
if (!node.enabled) {
|
||||||
return when.resolve(node);
|
return Promise.resolve(node);
|
||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -316,7 +340,7 @@ function loadNodeSet(node) {
|
|||||||
if (loadPromise == null) {
|
if (loadPromise == null) {
|
||||||
node.enabled = true;
|
node.enabled = true;
|
||||||
node.loaded = true;
|
node.loaded = true;
|
||||||
loadPromise = when.resolve(node);
|
loadPromise = Promise.resolve(node);
|
||||||
}
|
}
|
||||||
return loadPromise;
|
return loadPromise;
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
@ -333,7 +357,7 @@ function loadNodeSet(node) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return when.resolve(node);
|
return Promise.resolve(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -365,19 +389,19 @@ function addModule(module) {
|
|||||||
// TODO: nls
|
// TODO: nls
|
||||||
var e = new Error("module_already_loaded");
|
var e = new Error("module_already_loaded");
|
||||||
e.code = "module_already_loaded";
|
e.code = "module_already_loaded";
|
||||||
return when.reject(e);
|
return Promise.reject(e);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
var moduleFiles = localfilesystem.getModuleFiles(module);
|
var moduleFiles = localfilesystem.getModuleFiles(module);
|
||||||
return loadNodeFiles(moduleFiles);
|
return loadNodeFiles(moduleFiles);
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
return when.reject(err);
|
return Promise.reject(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadNodeHelp(node,lang) {
|
function loadNodeHelp(node,lang) {
|
||||||
var base = path.basename(node.template);
|
var base = path.basename(node.template);
|
||||||
var localePath = undefined;
|
var localePath;
|
||||||
if (node.module === 'node-red') {
|
if (node.module === 'node-red') {
|
||||||
var cat_dir = path.dirname(node.template);
|
var cat_dir = path.dirname(node.template);
|
||||||
var cat = path.basename(cat_dir);
|
var cat = path.basename(cat_dir);
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
var when = require("when");
|
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
|
|
||||||
@ -85,6 +84,7 @@ function getLocalNodeFiles(dir) {
|
|||||||
|
|
||||||
var result = [];
|
var result = [];
|
||||||
var files = [];
|
var files = [];
|
||||||
|
var icons = [];
|
||||||
try {
|
try {
|
||||||
files = fs.readdirSync(dir);
|
files = fs.readdirSync(dir);
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
@ -103,14 +103,16 @@ function getLocalNodeFiles(dir) {
|
|||||||
} else if (stats.isDirectory()) {
|
} else if (stats.isDirectory()) {
|
||||||
// Ignore /.dirs/, /lib/ /node_modules/
|
// Ignore /.dirs/, /lib/ /node_modules/
|
||||||
if (!/^(\..*|lib|icons|node_modules|test|locales)$/.test(fn)) {
|
if (!/^(\..*|lib|icons|node_modules|test|locales)$/.test(fn)) {
|
||||||
result = result.concat(getLocalNodeFiles(path.join(dir,fn)));
|
var subDirResults = getLocalNodeFiles(path.join(dir,fn));
|
||||||
|
result = result.concat(subDirResults.files);
|
||||||
|
icons = icons.concat(subDirResults.icons);
|
||||||
} else if (fn === "icons") {
|
} else if (fn === "icons") {
|
||||||
var iconList = scanIconDir(path.join(dir,fn));
|
var iconList = scanIconDir(path.join(dir,fn));
|
||||||
events.emit("node-icon-dir",{name:'node-red',path:path.join(dir,fn),icons:iconList});
|
icons.push({path:path.join(dir,fn),icons:iconList});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return result;
|
return {files: result, icons: icons}
|
||||||
}
|
}
|
||||||
|
|
||||||
function scanDirForNodesModules(dir,moduleName) {
|
function scanDirForNodesModules(dir,moduleName) {
|
||||||
@ -198,7 +200,7 @@ function getModuleNodeFiles(module) {
|
|||||||
var nodes = pkg['node-red'].nodes||{};
|
var nodes = pkg['node-red'].nodes||{};
|
||||||
var results = [];
|
var results = [];
|
||||||
var iconDirs = [];
|
var iconDirs = [];
|
||||||
|
var iconList = [];
|
||||||
for (var n in nodes) {
|
for (var n in nodes) {
|
||||||
/* istanbul ignore else */
|
/* istanbul ignore else */
|
||||||
if (nodes.hasOwnProperty(n)) {
|
if (nodes.hasOwnProperty(n)) {
|
||||||
@ -213,47 +215,54 @@ function getModuleNodeFiles(module) {
|
|||||||
if (iconDirs.indexOf(iconDir) == -1) {
|
if (iconDirs.indexOf(iconDir) == -1) {
|
||||||
try {
|
try {
|
||||||
fs.statSync(iconDir);
|
fs.statSync(iconDir);
|
||||||
var iconList = scanIconDir(iconDir);
|
var icons = scanIconDir(iconDir);
|
||||||
events.emit("node-icon-dir",{name:pkg.name,path:iconDir,icons:iconList});
|
iconList.push({path:iconDir,icons:icons});
|
||||||
iconDirs.push(iconDir);
|
iconDirs.push(iconDir);
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var result = {files:results,icons:iconList};
|
||||||
|
|
||||||
var examplesDir = path.join(moduleDir,"examples");
|
var examplesDir = path.join(moduleDir,"examples");
|
||||||
try {
|
try {
|
||||||
fs.statSync(examplesDir)
|
fs.statSync(examplesDir)
|
||||||
events.emit("node-examples-dir",{name:pkg.name,path:examplesDir});
|
events.emit("node-examples-dir",{name:pkg.name,path:examplesDir});
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
}
|
}
|
||||||
return results;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getNodeFiles(disableNodePathScan) {
|
function getNodeFiles(disableNodePathScan) {
|
||||||
var dir;
|
var dir;
|
||||||
// Find all of the nodes to load
|
// Find all of the nodes to load
|
||||||
var nodeFiles = [];
|
var nodeFiles = [];
|
||||||
|
var results;
|
||||||
|
|
||||||
var dir = path.resolve(__dirname + '/../../../../public/icons');
|
var dir = path.resolve(__dirname + '/../../../../public/icons');
|
||||||
var iconList = scanIconDir(dir);
|
var iconList = [{path:dir,icons:scanIconDir(dir)}];
|
||||||
events.emit("node-icon-dir",{name:'node-red',path:dir,icons:iconList});
|
|
||||||
|
|
||||||
if (settings.coreNodesDir) {
|
if (settings.coreNodesDir) {
|
||||||
nodeFiles = getLocalNodeFiles(path.resolve(settings.coreNodesDir));
|
results = getLocalNodeFiles(path.resolve(settings.coreNodesDir));
|
||||||
|
nodeFiles = nodeFiles.concat(results.files);
|
||||||
|
iconList = iconList.concat(results.icons);
|
||||||
|
|
||||||
var defaultLocalesPath = path.join(settings.coreNodesDir,"core","locales");
|
var defaultLocalesPath = path.join(settings.coreNodesDir,"core","locales");
|
||||||
i18n.registerMessageCatalog("node-red",defaultLocalesPath,"messages.json");
|
i18n.registerMessageCatalog("node-red",defaultLocalesPath,"messages.json");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settings.userDir) {
|
if (settings.userDir) {
|
||||||
dir = path.join(settings.userDir,"lib","icons");
|
dir = path.join(settings.userDir,"lib","icons");
|
||||||
iconList = scanIconDir(dir);
|
var icons = scanIconDir(dir);
|
||||||
if (iconList.length > 0) {
|
if (icons.length > 0) {
|
||||||
events.emit("node-icon-dir",{name:'Library',path:dir,icons:iconList});
|
iconList.push({path:dir,icons:icons});
|
||||||
}
|
}
|
||||||
|
|
||||||
dir = path.join(settings.userDir,"nodes");
|
dir = path.join(settings.userDir,"nodes");
|
||||||
nodeFiles = nodeFiles.concat(getLocalNodeFiles(dir));
|
results = getLocalNodeFiles(path.resolve(dir));
|
||||||
|
nodeFiles = nodeFiles.concat(results.files);
|
||||||
|
iconList = iconList.concat(results.icons);
|
||||||
}
|
}
|
||||||
if (settings.nodesDir) {
|
if (settings.nodesDir) {
|
||||||
dir = settings.nodesDir;
|
dir = settings.nodesDir;
|
||||||
@ -261,7 +270,9 @@ function getNodeFiles(disableNodePathScan) {
|
|||||||
dir = [dir];
|
dir = [dir];
|
||||||
}
|
}
|
||||||
for (var i=0;i<dir.length;i++) {
|
for (var i=0;i<dir.length;i++) {
|
||||||
nodeFiles = nodeFiles.concat(getLocalNodeFiles(dir[i]));
|
results = getLocalNodeFiles(dir[i]);
|
||||||
|
nodeFiles = nodeFiles.concat(results.files);
|
||||||
|
iconList = iconList.concat(results.icons);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,7 +280,8 @@ function getNodeFiles(disableNodePathScan) {
|
|||||||
"node-red": {
|
"node-red": {
|
||||||
name: "node-red",
|
name: "node-red",
|
||||||
version: settings.version,
|
version: settings.version,
|
||||||
nodes: {}
|
nodes: {},
|
||||||
|
icons: iconList
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nodeFiles.forEach(function(node) {
|
nodeFiles.forEach(function(node) {
|
||||||
@ -283,20 +295,22 @@ function getNodeFiles(disableNodePathScan) {
|
|||||||
nodeList[moduleFile.package.name] = {
|
nodeList[moduleFile.package.name] = {
|
||||||
name: moduleFile.package.name,
|
name: moduleFile.package.name,
|
||||||
version: moduleFile.package.version,
|
version: moduleFile.package.version,
|
||||||
|
path: moduleFile.dir,
|
||||||
local: moduleFile.local||false,
|
local: moduleFile.local||false,
|
||||||
nodes: {}
|
nodes: {},
|
||||||
|
icons: nodeModuleFiles.icons
|
||||||
};
|
};
|
||||||
if (moduleFile.package['node-red'].version) {
|
if (moduleFile.package['node-red'].version) {
|
||||||
nodeList[moduleFile.package.name].redVersion = moduleFile.package['node-red'].version;
|
nodeList[moduleFile.package.name].redVersion = moduleFile.package['node-red'].version;
|
||||||
}
|
}
|
||||||
nodeModuleFiles.forEach(function(node) {
|
nodeModuleFiles.files.forEach(function(node) {
|
||||||
node.local = moduleFile.local||false;
|
node.local = moduleFile.local||false;
|
||||||
nodeList[moduleFile.package.name].nodes[node.name] = node;
|
nodeList[moduleFile.package.name].nodes[node.name] = node;
|
||||||
});
|
});
|
||||||
nodeFiles = nodeFiles.concat(nodeModuleFiles);
|
nodeFiles = nodeFiles.concat(nodeModuleFiles.files);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.log("node path scan disabled");
|
// console.log("node path scan disabled");
|
||||||
}
|
}
|
||||||
return nodeList;
|
return nodeList;
|
||||||
}
|
}
|
||||||
@ -316,12 +330,13 @@ function getModuleFiles(module) {
|
|||||||
nodeList[moduleFile.package.name] = {
|
nodeList[moduleFile.package.name] = {
|
||||||
name: moduleFile.package.name,
|
name: moduleFile.package.name,
|
||||||
version: moduleFile.package.version,
|
version: moduleFile.package.version,
|
||||||
nodes: {}
|
nodes: {},
|
||||||
|
icons: nodeModuleFiles.icons
|
||||||
};
|
};
|
||||||
if (moduleFile.package['node-red'].version) {
|
if (moduleFile.package['node-red'].version) {
|
||||||
nodeList[moduleFile.package.name].redVersion = moduleFile.package['node-red'].version;
|
nodeList[moduleFile.package.name].redVersion = moduleFile.package['node-red'].version;
|
||||||
}
|
}
|
||||||
nodeModuleFiles.forEach(function(node) {
|
nodeModuleFiles.files.forEach(function(node) {
|
||||||
nodeList[moduleFile.package.name].nodes[node.name] = node;
|
nodeList[moduleFile.package.name].nodes[node.name] = node;
|
||||||
nodeList[moduleFile.package.name].nodes[node.name].local = moduleFile.local || false;
|
nodeList[moduleFile.package.name].nodes[node.name].local = moduleFile.local || false;
|
||||||
});
|
});
|
||||||
|
@ -181,7 +181,14 @@ function loadNodeConfigs() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function addNodeSet(id,set,version) {
|
function addModule(module) {
|
||||||
|
moduleNodes[module.name] = [];
|
||||||
|
moduleConfigs[module.name] = module;
|
||||||
|
for (var setName in module.nodes) {
|
||||||
|
if (module.nodes.hasOwnProperty(setName)) {
|
||||||
|
var set = module.nodes[setName];
|
||||||
|
moduleNodes[module.name].push(set.name);
|
||||||
|
nodeList.push(set.id);
|
||||||
if (!set.err) {
|
if (!set.err) {
|
||||||
set.types.forEach(function(t) {
|
set.types.forEach(function(t) {
|
||||||
if (nodeTypeToId.hasOwnProperty(t)) {
|
if (nodeTypeToId.hasOwnProperty(t)) {
|
||||||
@ -197,30 +204,20 @@ function addNodeSet(id,set,version) {
|
|||||||
});
|
});
|
||||||
if (!set.err) {
|
if (!set.err) {
|
||||||
set.types.forEach(function(t) {
|
set.types.forEach(function(t) {
|
||||||
nodeTypeToId[t] = id;
|
nodeTypeToId[t] = set.id;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
moduleNodes[set.module] = moduleNodes[set.module]||[];
|
|
||||||
moduleNodes[set.module].push(set.name);
|
|
||||||
|
|
||||||
if (!moduleConfigs[set.module]) {
|
|
||||||
moduleConfigs[set.module] = {
|
|
||||||
name: set.module,
|
|
||||||
nodes: {}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (version) {
|
|
||||||
moduleConfigs[set.module].version = version;
|
|
||||||
}
|
}
|
||||||
moduleConfigs[set.module].local = set.local;
|
if (module.icons) {
|
||||||
|
icon_paths[module.name] = [];
|
||||||
moduleConfigs[set.module].nodes[set.name] = set;
|
module.icons.forEach(icon=>icon_paths[module.name].push(path.resolve(icon.path)) )
|
||||||
nodeList.push(id);
|
}
|
||||||
nodeConfigCache = null;
|
nodeConfigCache = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function removeNode(id) {
|
function removeNode(id) {
|
||||||
var config = moduleConfigs[getModule(id)].nodes[getNode(id)];
|
var config = moduleConfigs[getModule(id)].nodes[getNode(id)];
|
||||||
if (!config) {
|
if (!config) {
|
||||||
@ -346,6 +343,7 @@ function getModuleInfo(module) {
|
|||||||
name: module,
|
name: module,
|
||||||
version: moduleConfigs[module].version,
|
version: moduleConfigs[module].version,
|
||||||
local: moduleConfigs[module].local,
|
local: moduleConfigs[module].local,
|
||||||
|
path: moduleConfigs[module].path,
|
||||||
nodes: []
|
nodes: []
|
||||||
};
|
};
|
||||||
for (var i = 0; i < nodes.length; ++i) {
|
for (var i = 0; i < nodes.length; ++i) {
|
||||||
@ -592,6 +590,7 @@ var iconCache = {};
|
|||||||
var defaultIcon = path.resolve(__dirname + '/../../../../public/icons/arrow-in.png');
|
var defaultIcon = path.resolve(__dirname + '/../../../../public/icons/arrow-in.png');
|
||||||
|
|
||||||
function nodeIconDir(dir) {
|
function nodeIconDir(dir) {
|
||||||
|
return;
|
||||||
icon_paths[dir.name] = icon_paths[dir.name] || [];
|
icon_paths[dir.name] = icon_paths[dir.name] || [];
|
||||||
icon_paths[dir.name].push(path.resolve(dir.path));
|
icon_paths[dir.name].push(path.resolve(dir.path));
|
||||||
|
|
||||||
@ -647,11 +646,11 @@ function getNodeIcons() {
|
|||||||
for (var module in moduleConfigs) {
|
for (var module in moduleConfigs) {
|
||||||
if (moduleConfigs.hasOwnProperty(module)) {
|
if (moduleConfigs.hasOwnProperty(module)) {
|
||||||
if (moduleConfigs[module].icons) {
|
if (moduleConfigs[module].icons) {
|
||||||
iconList[module] = moduleConfigs[module].icons;
|
iconList[module] = [];
|
||||||
|
moduleConfigs[module].icons.forEach(icon=>{ iconList[module] = iconList[module].concat(icon.icons) });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return iconList;
|
return iconList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -663,7 +662,9 @@ var registry = module.exports = {
|
|||||||
registerNodeConstructor: registerNodeConstructor,
|
registerNodeConstructor: registerNodeConstructor,
|
||||||
getNodeConstructor: getNodeConstructor,
|
getNodeConstructor: getNodeConstructor,
|
||||||
|
|
||||||
addNodeSet: addNodeSet,
|
|
||||||
|
addModule: addModule,
|
||||||
|
|
||||||
enableNodeSet: enableNodeSet,
|
enableNodeSet: enableNodeSet,
|
||||||
disableNodeSet: disableNodeSet,
|
disableNodeSet: disableNodeSet,
|
||||||
|
|
||||||
|
@ -79,6 +79,7 @@ describe("red/nodes/registry/loader",function() {
|
|||||||
var result = {};
|
var result = {};
|
||||||
result["node-red"] = {
|
result["node-red"] = {
|
||||||
"name": "node-red",
|
"name": "node-red",
|
||||||
|
"version": "1.2.3",
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"TestNode1": {
|
"TestNode1": {
|
||||||
"file": path.join(resourcesDir,"TestNode1","TestNode1.js"),
|
"file": path.join(resourcesDir,"TestNode1","TestNode1.js"),
|
||||||
@ -91,34 +92,39 @@ describe("red/nodes/registry/loader",function() {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return }));
|
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return }));
|
||||||
stubs.push(sinon.stub(registry,"addNodeSet", function(){ return }));
|
stubs.push(sinon.stub(registry,"addModule", function(){ return }));
|
||||||
// This module isn't already loaded
|
// This module isn't already loaded
|
||||||
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
|
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
|
||||||
|
|
||||||
stubs.push(sinon.stub(nodes,"registerType"));
|
stubs.push(sinon.stub(nodes,"registerType"));
|
||||||
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
|
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
|
||||||
loader.load().then(function(result) {
|
loader.load().then(function(result) {
|
||||||
registry.addNodeSet.called.should.be.true();
|
registry.addModule.called.should.be.true();
|
||||||
registry.addNodeSet.lastCall.args[0].should.eql("node-red/TestNode1");
|
var module = registry.addModule.lastCall.args[0];
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('id',"node-red/TestNode1");
|
module.should.have.property("name","node-red");
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('module',"node-red");
|
module.should.have.property("version","1.2.3");
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('enabled',true);
|
module.should.have.property("nodes");
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('loaded',true);
|
module.nodes.should.have.property("TestNode1");
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('version',undefined);
|
module.nodes.TestNode1.should.have.property("id","node-red/TestNode1");
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('types');
|
module.nodes.TestNode1.should.have.property("module","node-red");
|
||||||
registry.addNodeSet.lastCall.args[1].types.should.have.a.length(1);
|
module.nodes.TestNode1.should.have.property("name","TestNode1");
|
||||||
registry.addNodeSet.lastCall.args[1].types[0].should.eql('test-node-1');
|
module.nodes.TestNode1.should.have.property("file");
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('config');
|
module.nodes.TestNode1.should.have.property("template");
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('help');
|
module.nodes.TestNode1.should.have.property("enabled",true);
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('namespace','node-red');
|
module.nodes.TestNode1.should.have.property("loaded",true);
|
||||||
registry.addNodeSet.lastCall.args[1].should.not.have.a.property('err');
|
module.nodes.TestNode1.should.have.property("types");
|
||||||
|
module.nodes.TestNode1.types.should.have.a.length(1);
|
||||||
|
module.nodes.TestNode1.types[0].should.eql('test-node-1');
|
||||||
|
module.nodes.TestNode1.should.have.property("config");
|
||||||
|
module.nodes.TestNode1.should.have.property("help");
|
||||||
|
module.nodes.TestNode1.should.have.property("namespace","node-red");
|
||||||
|
|
||||||
nodes.registerType.calledOnce.should.be.true();
|
nodes.registerType.calledOnce.should.be.true();
|
||||||
nodes.registerType.lastCall.args[0].should.eql('node-red/TestNode1');
|
nodes.registerType.lastCall.args[0].should.eql('node-red/TestNode1');
|
||||||
nodes.registerType.lastCall.args[1].should.eql('test-node-1');
|
nodes.registerType.lastCall.args[1].should.eql('test-node-1');
|
||||||
|
|
||||||
done();
|
done();
|
||||||
}).otherwise(function(err) {
|
}).catch(function(err) {
|
||||||
done(err);
|
done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -128,6 +134,7 @@ describe("red/nodes/registry/loader",function() {
|
|||||||
var result = {};
|
var result = {};
|
||||||
result["node-red"] = {
|
result["node-red"] = {
|
||||||
"name": "node-red",
|
"name": "node-red",
|
||||||
|
"version": "4.5.6",
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"MultipleNodes1": {
|
"MultipleNodes1": {
|
||||||
"file": path.join(resourcesDir,"MultipleNodes1","MultipleNodes1.js"),
|
"file": path.join(resourcesDir,"MultipleNodes1","MultipleNodes1.js"),
|
||||||
@ -140,27 +147,33 @@ describe("red/nodes/registry/loader",function() {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return }));
|
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return }));
|
||||||
stubs.push(sinon.stub(registry,"addNodeSet", function(){ return }));
|
stubs.push(sinon.stub(registry,"addModule", function(){ return }));
|
||||||
// This module isn't already loaded
|
// This module isn't already loaded
|
||||||
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
|
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
|
||||||
stubs.push(sinon.stub(nodes,"registerType"));
|
stubs.push(sinon.stub(nodes,"registerType"));
|
||||||
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
|
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
|
||||||
loader.load().then(function(result) {
|
loader.load().then(function(result) {
|
||||||
registry.addNodeSet.called.should.be.true();
|
|
||||||
registry.addNodeSet.lastCall.args[0].should.eql("node-red/MultipleNodes1");
|
registry.addModule.called.should.be.true();
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('id',"node-red/MultipleNodes1");
|
var module = registry.addModule.lastCall.args[0];
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('module',"node-red");
|
module.should.have.property("name","node-red");
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('enabled',true);
|
module.should.have.property("version","4.5.6");
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('loaded',true);
|
module.should.have.property("nodes");
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('version',undefined);
|
module.nodes.should.have.property("MultipleNodes1");
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('types');
|
module.nodes.MultipleNodes1.should.have.property("id","node-red/MultipleNodes1");
|
||||||
registry.addNodeSet.lastCall.args[1].types.should.have.a.length(2);
|
module.nodes.MultipleNodes1.should.have.property("module","node-red");
|
||||||
registry.addNodeSet.lastCall.args[1].types[0].should.eql('test-node-multiple-1a');
|
module.nodes.MultipleNodes1.should.have.property("name","MultipleNodes1");
|
||||||
registry.addNodeSet.lastCall.args[1].types[1].should.eql('test-node-multiple-1b');
|
module.nodes.MultipleNodes1.should.have.property("file");
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('config');
|
module.nodes.MultipleNodes1.should.have.property("template");
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('help');
|
module.nodes.MultipleNodes1.should.have.property("enabled",true);
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('namespace','node-red');
|
module.nodes.MultipleNodes1.should.have.property("loaded",true);
|
||||||
registry.addNodeSet.lastCall.args[1].should.not.have.a.property('err');
|
module.nodes.MultipleNodes1.should.have.property("types");
|
||||||
|
module.nodes.MultipleNodes1.types.should.have.a.length(2);
|
||||||
|
module.nodes.MultipleNodes1.types[0].should.eql('test-node-multiple-1a');
|
||||||
|
module.nodes.MultipleNodes1.types[1].should.eql('test-node-multiple-1b');
|
||||||
|
module.nodes.MultipleNodes1.should.have.property("config");
|
||||||
|
module.nodes.MultipleNodes1.should.have.property("help");
|
||||||
|
module.nodes.MultipleNodes1.should.have.property("namespace","node-red");
|
||||||
|
|
||||||
nodes.registerType.calledTwice.should.be.true();
|
nodes.registerType.calledTwice.should.be.true();
|
||||||
nodes.registerType.firstCall.args[0].should.eql('node-red/MultipleNodes1');
|
nodes.registerType.firstCall.args[0].should.eql('node-red/MultipleNodes1');
|
||||||
@ -168,8 +181,9 @@ describe("red/nodes/registry/loader",function() {
|
|||||||
nodes.registerType.secondCall.args[0].should.eql('node-red/MultipleNodes1');
|
nodes.registerType.secondCall.args[0].should.eql('node-red/MultipleNodes1');
|
||||||
nodes.registerType.secondCall.args[1].should.eql('test-node-multiple-1b');
|
nodes.registerType.secondCall.args[1].should.eql('test-node-multiple-1b');
|
||||||
|
|
||||||
|
|
||||||
done();
|
done();
|
||||||
}).otherwise(function(err) {
|
}).catch(function(err) {
|
||||||
done(err);
|
done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -180,6 +194,7 @@ describe("red/nodes/registry/loader",function() {
|
|||||||
var result = {};
|
var result = {};
|
||||||
result["node-red"] = {
|
result["node-red"] = {
|
||||||
"name": "node-red",
|
"name": "node-red",
|
||||||
|
"version":"2.4.6",
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"TestNode2": {
|
"TestNode2": {
|
||||||
"file": path.join(resourcesDir,"TestNode2","TestNode2.js"),
|
"file": path.join(resourcesDir,"TestNode2","TestNode2.js"),
|
||||||
@ -192,34 +207,41 @@ describe("red/nodes/registry/loader",function() {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return }));
|
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return }));
|
||||||
stubs.push(sinon.stub(registry,"addNodeSet", function(){ return }));
|
stubs.push(sinon.stub(registry,"addModule", function(){ return }));
|
||||||
// This module isn't already loaded
|
// This module isn't already loaded
|
||||||
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
|
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
|
||||||
|
|
||||||
stubs.push(sinon.stub(nodes,"registerType"));
|
stubs.push(sinon.stub(nodes,"registerType"));
|
||||||
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
|
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
|
||||||
loader.load().then(function(result) {
|
loader.load().then(function(result) {
|
||||||
registry.addNodeSet.called.should.be.true();
|
|
||||||
registry.addNodeSet.lastCall.args[0].should.eql("node-red/TestNode2");
|
registry.addModule.called.should.be.true();
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('id',"node-red/TestNode2");
|
var module = registry.addModule.lastCall.args[0];
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('module',"node-red");
|
module.should.have.property("name","node-red");
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('enabled',true);
|
module.should.have.property("version","2.4.6");
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('loaded',true);
|
module.should.have.property("nodes");
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('version',undefined);
|
module.nodes.should.have.property("TestNode2");
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('types');
|
module.nodes.TestNode2.should.have.property("id","node-red/TestNode2");
|
||||||
registry.addNodeSet.lastCall.args[1].types.should.have.a.length(1);
|
module.nodes.TestNode2.should.have.property("module","node-red");
|
||||||
registry.addNodeSet.lastCall.args[1].types[0].should.eql('test-node-2');
|
module.nodes.TestNode2.should.have.property("name","TestNode2");
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('config');
|
module.nodes.TestNode2.should.have.property("file");
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('help');
|
module.nodes.TestNode2.should.have.property("template");
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('namespace','node-red');
|
module.nodes.TestNode2.should.have.property("enabled",true);
|
||||||
registry.addNodeSet.lastCall.args[1].should.not.have.a.property('err');
|
module.nodes.TestNode2.should.have.property("loaded",true);
|
||||||
|
module.nodes.TestNode2.should.have.property("types");
|
||||||
|
module.nodes.TestNode2.types.should.have.a.length(1);
|
||||||
|
module.nodes.TestNode2.types[0].should.eql('test-node-2');
|
||||||
|
module.nodes.TestNode2.should.have.property("config");
|
||||||
|
module.nodes.TestNode2.should.have.property("help");
|
||||||
|
module.nodes.TestNode2.should.have.property("namespace","node-red");
|
||||||
|
module.nodes.TestNode2.should.not.have.property('err');
|
||||||
|
|
||||||
nodes.registerType.calledOnce.should.be.true();
|
nodes.registerType.calledOnce.should.be.true();
|
||||||
nodes.registerType.lastCall.args[0].should.eql('node-red/TestNode2');
|
nodes.registerType.lastCall.args[0].should.eql('node-red/TestNode2');
|
||||||
nodes.registerType.lastCall.args[1].should.eql('test-node-2');
|
nodes.registerType.lastCall.args[1].should.eql('test-node-2');
|
||||||
|
|
||||||
done();
|
done();
|
||||||
}).otherwise(function(err) {
|
}).catch(function(err) {
|
||||||
done(err);
|
done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -230,6 +252,7 @@ describe("red/nodes/registry/loader",function() {
|
|||||||
var result = {};
|
var result = {};
|
||||||
result["node-red"] = {
|
result["node-red"] = {
|
||||||
"name": "node-red",
|
"name": "node-red",
|
||||||
|
"version":"1.2.3",
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"TestNode3": {
|
"TestNode3": {
|
||||||
"file": path.join(resourcesDir,"TestNode3","TestNode3.js"),
|
"file": path.join(resourcesDir,"TestNode3","TestNode3.js"),
|
||||||
@ -242,32 +265,38 @@ describe("red/nodes/registry/loader",function() {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return }));
|
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return }));
|
||||||
stubs.push(sinon.stub(registry,"addNodeSet", function(){ return }));
|
stubs.push(sinon.stub(registry,"addModule", function(){ return }));
|
||||||
// This module isn't already loaded
|
// This module isn't already loaded
|
||||||
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
|
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
|
||||||
|
|
||||||
stubs.push(sinon.stub(nodes,"registerType"));
|
stubs.push(sinon.stub(nodes,"registerType"));
|
||||||
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
|
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
|
||||||
loader.load().then(function(result) {
|
loader.load().then(function(result) {
|
||||||
registry.addNodeSet.called.should.be.true();
|
registry.addModule.called.should.be.true();
|
||||||
registry.addNodeSet.lastCall.args[0].should.eql("node-red/TestNode3");
|
var module = registry.addModule.lastCall.args[0];
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('id',"node-red/TestNode3");
|
module.should.have.property("name","node-red");
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('module',"node-red");
|
module.should.have.property("version","1.2.3");
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('enabled',true);
|
module.should.have.property("nodes");
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('loaded',false);
|
module.nodes.should.have.property("TestNode3");
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('version',undefined);
|
module.nodes.TestNode3.should.have.property("id","node-red/TestNode3");
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('types');
|
module.nodes.TestNode3.should.have.property("module","node-red");
|
||||||
registry.addNodeSet.lastCall.args[1].types.should.have.a.length(1);
|
module.nodes.TestNode3.should.have.property("name","TestNode3");
|
||||||
registry.addNodeSet.lastCall.args[1].types[0].should.eql('test-node-3');
|
module.nodes.TestNode3.should.have.property("file");
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('config');
|
module.nodes.TestNode3.should.have.property("template");
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('help');
|
module.nodes.TestNode3.should.have.property("enabled",true);
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('namespace','node-red');
|
module.nodes.TestNode3.should.have.property("loaded",false);
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('err','fail');
|
module.nodes.TestNode3.should.have.property("types");
|
||||||
|
module.nodes.TestNode3.types.should.have.a.length(1);
|
||||||
|
module.nodes.TestNode3.types[0].should.eql('test-node-3');
|
||||||
|
module.nodes.TestNode3.should.have.property("config");
|
||||||
|
module.nodes.TestNode3.should.have.property("help");
|
||||||
|
module.nodes.TestNode3.should.have.property("namespace","node-red");
|
||||||
|
module.nodes.TestNode3.should.have.property('err','fail');
|
||||||
|
|
||||||
nodes.registerType.calledOnce.should.be.false();
|
nodes.registerType.called.should.be.false();
|
||||||
|
|
||||||
done();
|
done();
|
||||||
}).otherwise(function(err) {
|
}).catch(function(err) {
|
||||||
done(err);
|
done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -277,6 +306,7 @@ describe("red/nodes/registry/loader",function() {
|
|||||||
var result = {};
|
var result = {};
|
||||||
result["node-red"] = {
|
result["node-red"] = {
|
||||||
"name": "node-red",
|
"name": "node-red",
|
||||||
|
"version":"1.2.3",
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"DoesNotExist": {
|
"DoesNotExist": {
|
||||||
"file": path.join(resourcesDir,"doesnotexist"),
|
"file": path.join(resourcesDir,"doesnotexist"),
|
||||||
@ -289,31 +319,37 @@ describe("red/nodes/registry/loader",function() {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return }));
|
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return }));
|
||||||
stubs.push(sinon.stub(registry,"addNodeSet", function(){ return }));
|
stubs.push(sinon.stub(registry,"addModule", function(){ return }));
|
||||||
// This module isn't already loaded
|
// This module isn't already loaded
|
||||||
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
|
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
|
||||||
|
|
||||||
stubs.push(sinon.stub(nodes,"registerType"));
|
stubs.push(sinon.stub(nodes,"registerType"));
|
||||||
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
|
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
|
||||||
loader.load().then(function(result) {
|
loader.load().then(function(result) {
|
||||||
registry.addNodeSet.called.should.be.true();
|
registry.addModule.called.should.be.true();
|
||||||
registry.addNodeSet.lastCall.args[0].should.eql("node-red/DoesNotExist");
|
var module = registry.addModule.lastCall.args[0];
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('id',"node-red/DoesNotExist");
|
module.should.have.property("name","node-red");
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('module',"node-red");
|
module.should.have.property("version","1.2.3");
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('enabled',true);
|
module.should.have.property("nodes");
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('loaded',false);
|
module.nodes.should.have.property("DoesNotExist");
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('version',undefined);
|
module.nodes.DoesNotExist.should.have.property("id","node-red/DoesNotExist");
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('types');
|
module.nodes.DoesNotExist.should.have.property("module","node-red");
|
||||||
registry.addNodeSet.lastCall.args[1].types.should.have.a.length(0);
|
module.nodes.DoesNotExist.should.have.property("name","DoesNotExist");
|
||||||
registry.addNodeSet.lastCall.args[1].should.not.have.a.property('config');
|
module.nodes.DoesNotExist.should.have.property("file");
|
||||||
registry.addNodeSet.lastCall.args[1].should.not.have.a.property('help');
|
module.nodes.DoesNotExist.should.have.property("template");
|
||||||
registry.addNodeSet.lastCall.args[1].should.not.have.a.property('namespace','node-red');
|
module.nodes.DoesNotExist.should.have.property("enabled",true);
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('err');
|
module.nodes.DoesNotExist.should.have.property("loaded",false);
|
||||||
|
module.nodes.DoesNotExist.should.have.property("types");
|
||||||
|
module.nodes.DoesNotExist.types.should.have.a.length(0);
|
||||||
|
module.nodes.DoesNotExist.should.not.have.property("config");
|
||||||
|
module.nodes.DoesNotExist.should.not.have.property("help");
|
||||||
|
module.nodes.DoesNotExist.should.not.have.property("namespace","node-red");
|
||||||
|
module.nodes.DoesNotExist.should.have.property('err');
|
||||||
|
|
||||||
nodes.registerType.calledOnce.should.be.false();
|
nodes.registerType.called.should.be.false();
|
||||||
|
|
||||||
done();
|
done();
|
||||||
}).otherwise(function(err) {
|
}).catch(function(err) {
|
||||||
done(err);
|
done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -323,6 +359,7 @@ describe("red/nodes/registry/loader",function() {
|
|||||||
var result = {};
|
var result = {};
|
||||||
result["node-red"] = {
|
result["node-red"] = {
|
||||||
"name": "node-red",
|
"name": "node-red",
|
||||||
|
"version": "1.2.3",
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"DuffNode": {
|
"DuffNode": {
|
||||||
"file": path.join(resourcesDir,"DuffNode","DuffNode.js"),
|
"file": path.join(resourcesDir,"DuffNode","DuffNode.js"),
|
||||||
@ -335,32 +372,39 @@ describe("red/nodes/registry/loader",function() {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return }));
|
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return }));
|
||||||
stubs.push(sinon.stub(registry,"addNodeSet", function(){ return }));
|
stubs.push(sinon.stub(registry,"addModule", function(){ return }));
|
||||||
// This module isn't already loaded
|
// This module isn't already loaded
|
||||||
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
|
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
|
||||||
|
|
||||||
stubs.push(sinon.stub(nodes,"registerType"));
|
stubs.push(sinon.stub(nodes,"registerType"));
|
||||||
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
|
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
|
||||||
loader.load().then(function(result) {
|
loader.load().then(function(result) {
|
||||||
registry.addNodeSet.called.should.be.true();
|
|
||||||
registry.addNodeSet.lastCall.args[0].should.eql("node-red/DuffNode");
|
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('id',"node-red/DuffNode");
|
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('module',"node-red");
|
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('enabled',true);
|
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('loaded',false);
|
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('version',undefined);
|
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('types');
|
|
||||||
registry.addNodeSet.lastCall.args[1].types.should.have.a.length(0);
|
|
||||||
registry.addNodeSet.lastCall.args[1].should.not.have.a.property('config');
|
|
||||||
registry.addNodeSet.lastCall.args[1].should.not.have.a.property('help');
|
|
||||||
registry.addNodeSet.lastCall.args[1].should.not.have.a.property('namespace','node-red');
|
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('err');
|
|
||||||
registry.addNodeSet.lastCall.args[1].err.should.endWith("DuffNode.html does not exist");
|
|
||||||
|
|
||||||
nodes.registerType.calledOnce.should.be.false();
|
registry.addModule.called.should.be.true();
|
||||||
|
var module = registry.addModule.lastCall.args[0];
|
||||||
|
module.should.have.property("name","node-red");
|
||||||
|
module.should.have.property("version","1.2.3");
|
||||||
|
module.should.have.property("nodes");
|
||||||
|
module.nodes.should.have.property("DuffNode");
|
||||||
|
module.nodes.DuffNode.should.have.property("id","node-red/DuffNode");
|
||||||
|
module.nodes.DuffNode.should.have.property("module","node-red");
|
||||||
|
module.nodes.DuffNode.should.have.property("name","DuffNode");
|
||||||
|
module.nodes.DuffNode.should.have.property("file");
|
||||||
|
module.nodes.DuffNode.should.have.property("template");
|
||||||
|
module.nodes.DuffNode.should.have.property("enabled",true);
|
||||||
|
module.nodes.DuffNode.should.have.property("loaded",false);
|
||||||
|
module.nodes.DuffNode.should.have.property("types");
|
||||||
|
module.nodes.DuffNode.types.should.have.a.length(0);
|
||||||
|
module.nodes.DuffNode.should.not.have.property("config");
|
||||||
|
module.nodes.DuffNode.should.not.have.property("help");
|
||||||
|
module.nodes.DuffNode.should.not.have.property("namespace","node-red");
|
||||||
|
module.nodes.DuffNode.should.have.property('err');
|
||||||
|
module.nodes.DuffNode.err.should.endWith("DuffNode.html does not exist");
|
||||||
|
|
||||||
|
nodes.registerType.called.should.be.false();
|
||||||
|
|
||||||
done();
|
done();
|
||||||
}).otherwise(function(err) {
|
}).catch(function(err) {
|
||||||
done(err);
|
done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -379,7 +423,7 @@ describe("red/nodes/registry/loader",function() {
|
|||||||
stubs.push(sinon.stub(registry,"getModuleInfo",function(){return{}}));
|
stubs.push(sinon.stub(registry,"getModuleInfo",function(){return{}}));
|
||||||
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
|
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
|
||||||
|
|
||||||
loader.addModule("test-module").otherwise(function(err) {
|
loader.addModule("test-module").catch(function(err) {
|
||||||
err.code.should.eql("module_already_loaded");
|
err.code.should.eql("module_already_loaded");
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@ -390,7 +434,7 @@ describe("red/nodes/registry/loader",function() {
|
|||||||
throw new Error("failure");
|
throw new Error("failure");
|
||||||
}));
|
}));
|
||||||
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
|
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
|
||||||
loader.addModule("test-module").otherwise(function(err) {
|
loader.addModule("test-module").catch(function(err) {
|
||||||
err.message.should.eql("failure");
|
err.message.should.eql("failure");
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@ -419,29 +463,36 @@ describe("red/nodes/registry/loader",function() {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return "a node list" }));
|
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return "a node list" }));
|
||||||
stubs.push(sinon.stub(registry,"addNodeSet", function(){ return }));
|
stubs.push(sinon.stub(registry,"addModule", function(){ return }));
|
||||||
stubs.push(sinon.stub(nodes,"registerType"));
|
stubs.push(sinon.stub(nodes,"registerType"));
|
||||||
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
|
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
|
||||||
loader.addModule("TestNodeModule").then(function(result) {
|
loader.addModule("TestNodeModule").then(function(result) {
|
||||||
result.should.eql("a node list");
|
result.should.eql("a node list");
|
||||||
registry.addNodeSet.calledOnce.should.be.true();
|
|
||||||
registry.addNodeSet.lastCall.args[0].should.eql("TestNodeModule/TestNode1");
|
registry.addModule.called.should.be.true();
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('id',"TestNodeModule/TestNode1");
|
var module = registry.addModule.lastCall.args[0];
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('module',"TestNodeModule");
|
module.should.have.property("name","TestNodeModule");
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('enabled',true);
|
module.should.have.property("version","1.2.3");
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('loaded',true);
|
module.should.have.property("nodes");
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('version',"1.2.3");
|
module.nodes.should.have.property("TestNode1");
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('types');
|
module.nodes.TestNode1.should.have.property("id","TestNodeModule/TestNode1");
|
||||||
registry.addNodeSet.lastCall.args[1].types.should.have.a.length(1);
|
module.nodes.TestNode1.should.have.property("module","TestNodeModule");
|
||||||
registry.addNodeSet.lastCall.args[1].types[0].should.eql('test-node-mod-1');
|
module.nodes.TestNode1.should.have.property("name","TestNode1");
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('config');
|
module.nodes.TestNode1.should.have.property("file");
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('help');
|
module.nodes.TestNode1.should.have.property("template");
|
||||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('namespace','TestNodeModule');
|
module.nodes.TestNode1.should.have.property("enabled",true);
|
||||||
registry.addNodeSet.lastCall.args[1].should.not.have.a.property('err');
|
module.nodes.TestNode1.should.have.property("loaded",true);
|
||||||
|
module.nodes.TestNode1.should.have.property("types");
|
||||||
|
module.nodes.TestNode1.types.should.have.a.length(1);
|
||||||
|
module.nodes.TestNode1.types[0].should.eql('test-node-mod-1');
|
||||||
|
module.nodes.TestNode1.should.have.property("config");
|
||||||
|
module.nodes.TestNode1.should.have.property("help");
|
||||||
|
module.nodes.TestNode1.should.have.property("namespace","TestNodeModule");
|
||||||
|
module.nodes.TestNode1.should.not.have.property('err');
|
||||||
|
|
||||||
nodes.registerType.calledOnce.should.be.true();
|
nodes.registerType.calledOnce.should.be.true();
|
||||||
done();
|
done();
|
||||||
}).otherwise(function(err) {
|
}).catch(function(err) {
|
||||||
done(err);
|
done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -469,15 +520,15 @@ describe("red/nodes/registry/loader",function() {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return "a node list" }));
|
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return "a node list" }));
|
||||||
stubs.push(sinon.stub(registry,"addNodeSet", function(){ return }));
|
stubs.push(sinon.stub(registry,"addModule", function(){ return }));
|
||||||
stubs.push(sinon.stub(nodes,"registerType"));
|
stubs.push(sinon.stub(nodes,"registerType"));
|
||||||
loader.init({log:{"_":function(){},warn:function(){}},nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},version: function() { return "0.12.0"}, settings:{available:function(){return true;}}});
|
loader.init({log:{"_":function(){},warn:function(){}},nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},version: function() { return "0.12.0"}, settings:{available:function(){return true;}}});
|
||||||
loader.addModule("TestNodeModule").then(function(result) {
|
loader.addModule("TestNodeModule").then(function(result) {
|
||||||
result.should.eql("a node list");
|
result.should.eql("a node list");
|
||||||
registry.addNodeSet.called.should.be.false();
|
registry.addModule.called.should.be.false();
|
||||||
nodes.registerType.called.should.be.false();
|
nodes.registerType.called.should.be.false();
|
||||||
done();
|
done();
|
||||||
}).otherwise(function(err) {
|
}).catch(function(err) {
|
||||||
done(err);
|
done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -498,7 +549,7 @@ describe("red/nodes/registry/loader",function() {
|
|||||||
node.enabled.should.be.false();
|
node.enabled.should.be.false();
|
||||||
nodes.registerType.called.should.be.false();
|
nodes.registerType.called.should.be.false();
|
||||||
done();
|
done();
|
||||||
}).otherwise(function(err) {
|
}).catch(function(err) {
|
||||||
done(err);
|
done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -517,7 +568,7 @@ describe("red/nodes/registry/loader",function() {
|
|||||||
node.err.toString().should.eql("Error: fail to require (line:1)");
|
node.err.toString().should.eql("Error: fail to require (line:1)");
|
||||||
|
|
||||||
done();
|
done();
|
||||||
}).otherwise(function(err) {
|
}).catch(function(err) {
|
||||||
done(err);
|
done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -166,7 +166,15 @@ describe("red/nodes/registry/localfilesystem",function() {
|
|||||||
}},
|
}},
|
||||||
settings:{coreNodesDir:resourcesDir}
|
settings:{coreNodesDir:resourcesDir}
|
||||||
});
|
});
|
||||||
localfilesystem.getNodeFiles(true);
|
var list = localfilesystem.getNodeFiles(true);
|
||||||
|
list.should.have.property("node-red");
|
||||||
|
list["node-red"].should.have.property("icons");
|
||||||
|
list["node-red"].icons.should.have.length(2);
|
||||||
|
//list["node-red"].icons[1].should.have.property("path",path.join(__dirname,"resources/local/NestedDirectoryNode/NestedNode/icons"))
|
||||||
|
list["node-red"].icons[1].should.have.property("icons");
|
||||||
|
list["node-red"].icons[1].icons.should.have.length(1);
|
||||||
|
list["node-red"].icons[1].icons[0].should.eql("arrow-in.png");
|
||||||
|
done();
|
||||||
});
|
});
|
||||||
it("scans icons dir in library",function(done) {
|
it("scans icons dir in library",function(done) {
|
||||||
var count = 0;
|
var count = 0;
|
||||||
@ -188,7 +196,15 @@ describe("red/nodes/registry/localfilesystem",function() {
|
|||||||
}},
|
}},
|
||||||
settings:{userDir:userDir}
|
settings:{userDir:userDir}
|
||||||
});
|
});
|
||||||
localfilesystem.getNodeFiles(true);
|
var list = localfilesystem.getNodeFiles(true);
|
||||||
|
list.should.have.property("node-red");
|
||||||
|
list["node-red"].should.have.property("icons");
|
||||||
|
list["node-red"].icons.should.have.length(2);
|
||||||
|
//list["node-red"].icons[1].should.have.property("path",path.join(__dirname,"resources/userDir/lib/icons"))
|
||||||
|
list["node-red"].icons[1].should.have.property("icons");
|
||||||
|
list["node-red"].icons[1].icons.should.have.length(1);
|
||||||
|
list["node-red"].icons[1].icons[0].should.eql("test_icon.png");
|
||||||
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("#getModuleFiles",function() {
|
describe("#getModuleFiles",function() {
|
||||||
@ -256,6 +272,14 @@ describe("red/nodes/registry/localfilesystem",function() {
|
|||||||
settings:{coreNodesDir:moduleDir}
|
settings:{coreNodesDir:moduleDir}
|
||||||
});
|
});
|
||||||
var nodeModule = localfilesystem.getModuleFiles('TestNodeModule');
|
var nodeModule = localfilesystem.getModuleFiles('TestNodeModule');
|
||||||
|
nodeModule.should.have.property("TestNodeModule");
|
||||||
|
nodeModule.TestNodeModule.should.have.property('icons');
|
||||||
|
|
||||||
|
nodeModule.TestNodeModule.icons.should.have.length(1);
|
||||||
|
nodeModule.TestNodeModule.icons[0].should.have.property("path");
|
||||||
|
nodeModule.TestNodeModule.icons[0].should.have.property("icons");
|
||||||
|
nodeModule.TestNodeModule.icons[0].icons[0].should.eql("arrow-in.png");
|
||||||
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -132,7 +132,7 @@ describe("red/nodes/registry/registry",function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
describe('#addNodeSet', function() {
|
describe.skip('#addNodeSet', function() {
|
||||||
it('adds a node set for an unknown module', function() {
|
it('adds a node set for an unknown module', function() {
|
||||||
|
|
||||||
typeRegistry.init(settings);
|
typeRegistry.init(settings);
|
||||||
@ -290,29 +290,34 @@ describe("red/nodes/registry/registry",function() {
|
|||||||
|
|
||||||
describe('#saveNodeList',function() {
|
describe('#saveNodeList',function() {
|
||||||
it('rejects when settings unavailable',function(done) {
|
it('rejects when settings unavailable',function(done) {
|
||||||
typeRegistry.init(stubSettings({},false,{}));
|
typeRegistry.init(stubSettings({},false,{}),null,events);
|
||||||
typeRegistry.addNodeSet("test-module/test-name",testNodeSet1, "0.0.1");
|
typeRegistry.addModule({name: "test-module",version:"0.0.1",nodes: {"test-name":{module:"test-module",name:"test-name",types:[]}}});
|
||||||
typeRegistry.saveNodeList().otherwise(function(err) {
|
typeRegistry.saveNodeList().catch(function(err) {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('saves the list',function(done) {
|
it('saves the list',function(done) {
|
||||||
var s = stubSettings({},true,{});
|
var s = stubSettings({},true,{});
|
||||||
typeRegistry.init(s);
|
typeRegistry.init(s);
|
||||||
typeRegistry.addNodeSet("test-module/test-name",testNodeSet1, "0.0.1");
|
typeRegistry.addModule({name: "test-module",version:"0.0.1",nodes: {
|
||||||
typeRegistry.addNodeSet("test-module/test-name-2",testNodeSet2WithError, "0.0.1");
|
"test-name":testNodeSet1,
|
||||||
|
"test-name-2":testNodeSet2WithError
|
||||||
|
}});
|
||||||
|
|
||||||
typeRegistry.saveNodeList().then(function() {
|
typeRegistry.saveNodeList().then(function() {
|
||||||
s.set.called.should.be.true();
|
s.set.called.should.be.true();
|
||||||
s.set.lastCall.args[0].should.eql('nodes');
|
s.set.lastCall.args[0].should.eql('nodes');
|
||||||
var nodes = s.set.lastCall.args[1];
|
var nodes = s.set.lastCall.args[1];
|
||||||
nodes.should.have.property('test-module');
|
nodes.should.have.property('test-module');
|
||||||
for (var n in nodes['test-module'].nodes) {
|
for (var n in nodes['test-module'].nodes) {
|
||||||
|
if (nodes['test-module'].nodes.hasOwnProperty(n)) {
|
||||||
var nn = nodes['test-module'].nodes[n];
|
var nn = nodes['test-module'].nodes[n];
|
||||||
nn.should.not.have.property('err');
|
nn.should.not.have.property('err');
|
||||||
nn.should.not.have.property('id');
|
nn.should.not.have.property('id');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
done();
|
done();
|
||||||
}).otherwise(function(err) {
|
}).catch(function(err) {
|
||||||
done(err);
|
done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -338,7 +343,9 @@ describe("red/nodes/registry/registry",function() {
|
|||||||
it('removes a known module', function() {
|
it('removes a known module', function() {
|
||||||
var s = stubSettings({},true,{});
|
var s = stubSettings({},true,{});
|
||||||
typeRegistry.init(s);
|
typeRegistry.init(s);
|
||||||
typeRegistry.addNodeSet("test-module/test-name",testNodeSet1, "0.0.1");
|
typeRegistry.addModule({name: "test-module",version:"0.0.1",nodes: {
|
||||||
|
"test-name":testNodeSet1
|
||||||
|
}});
|
||||||
var moduleList = typeRegistry.getModuleList();
|
var moduleList = typeRegistry.getModuleList();
|
||||||
moduleList.should.have.a.property("test-module");
|
moduleList.should.have.a.property("test-module");
|
||||||
typeRegistry.getNodeList().should.have.lengthOf(1);
|
typeRegistry.getNodeList().should.have.lengthOf(1);
|
||||||
@ -355,7 +362,9 @@ describe("red/nodes/registry/registry",function() {
|
|||||||
typeRegistry.init(settings,{
|
typeRegistry.init(settings,{
|
||||||
getNodeHelp: function(config) { return "HE"+config.name+"LP" }
|
getNodeHelp: function(config) { return "HE"+config.name+"LP" }
|
||||||
});
|
});
|
||||||
typeRegistry.addNodeSet("test-module/test-name",{
|
|
||||||
|
typeRegistry.addModule({name: "test-module",version:"0.0.1",nodes: {
|
||||||
|
"test-name":{
|
||||||
id: "test-module/test-name",
|
id: "test-module/test-name",
|
||||||
module: "test-module",
|
module: "test-module",
|
||||||
name: "test-name",
|
name: "test-name",
|
||||||
@ -363,11 +372,8 @@ describe("red/nodes/registry/registry",function() {
|
|||||||
loaded: false,
|
loaded: false,
|
||||||
config: "configA",
|
config: "configA",
|
||||||
types: [ "test-a","test-b"]
|
types: [ "test-a","test-b"]
|
||||||
}, "0.0.1");
|
},
|
||||||
typeRegistry.getNodeConfig("test-module/test-name").should.eql('<!-- --- [red-module:test-module/test-name] --- -->\nconfigAHEtest-nameLP');
|
"test-name-2":{
|
||||||
typeRegistry.getAllNodeConfigs().should.eql('\n<!-- --- [red-module:test-module/test-name] --- -->\nconfigAHEtest-nameLP');
|
|
||||||
|
|
||||||
typeRegistry.addNodeSet("test-module/test-name-2",{
|
|
||||||
id: "test-module/test-name-2",
|
id: "test-module/test-name-2",
|
||||||
module: "test-module",
|
module: "test-module",
|
||||||
name: "test-name-2",
|
name: "test-name-2",
|
||||||
@ -375,7 +381,9 @@ describe("red/nodes/registry/registry",function() {
|
|||||||
loaded: false,
|
loaded: false,
|
||||||
config: "configB",
|
config: "configB",
|
||||||
types: [ "test-c","test-d"]
|
types: [ "test-c","test-d"]
|
||||||
}, "0.0.1");
|
}
|
||||||
|
}});
|
||||||
|
typeRegistry.getNodeConfig("test-module/test-name").should.eql('<!-- --- [red-module:test-module/test-name] --- -->\nconfigAHEtest-nameLP');
|
||||||
typeRegistry.getNodeConfig("test-module/test-name-2").should.eql('<!-- --- [red-module:test-module/test-name-2] --- -->\nconfigBHEtest-name-2LP');
|
typeRegistry.getNodeConfig("test-module/test-name-2").should.eql('<!-- --- [red-module:test-module/test-name-2] --- -->\nconfigBHEtest-name-2LP');
|
||||||
typeRegistry.getAllNodeConfigs().should.eql('\n<!-- --- [red-module:test-module/test-name] --- -->\nconfigAHEtest-nameLP\n<!-- --- [red-module:test-module/test-name-2] --- -->\nconfigBHEtest-name-2LP');
|
typeRegistry.getAllNodeConfigs().should.eql('\n<!-- --- [red-module:test-module/test-name] --- -->\nconfigAHEtest-nameLP\n<!-- --- [red-module:test-module/test-name-2] --- -->\nconfigBHEtest-name-2LP');
|
||||||
});
|
});
|
||||||
@ -383,7 +391,8 @@ describe("red/nodes/registry/registry",function() {
|
|||||||
describe('#getModuleInfo', function() {
|
describe('#getModuleInfo', function() {
|
||||||
it('returns module info', function() {
|
it('returns module info', function() {
|
||||||
typeRegistry.init(settings,{});
|
typeRegistry.init(settings,{});
|
||||||
typeRegistry.addNodeSet("test-module/test-name",{
|
typeRegistry.addModule({name: "test-module",version:"0.0.1",nodes: {
|
||||||
|
"test-name":{
|
||||||
id: "test-module/test-name",
|
id: "test-module/test-name",
|
||||||
module: "test-module",
|
module: "test-module",
|
||||||
name: "test-name",
|
name: "test-name",
|
||||||
@ -392,7 +401,8 @@ describe("red/nodes/registry/registry",function() {
|
|||||||
config: "configA",
|
config: "configA",
|
||||||
types: [ "test-a","test-b"],
|
types: [ "test-a","test-b"],
|
||||||
file: "abc"
|
file: "abc"
|
||||||
}, "0.0.1");
|
}
|
||||||
|
}});
|
||||||
var moduleInfo = typeRegistry.getModuleInfo("test-module");
|
var moduleInfo = typeRegistry.getModuleInfo("test-module");
|
||||||
moduleInfo.should.have.a.property('name','test-module');
|
moduleInfo.should.have.a.property('name','test-module');
|
||||||
moduleInfo.should.have.a.property('version','0.0.1');
|
moduleInfo.should.have.a.property('version','0.0.1');
|
||||||
@ -405,7 +415,8 @@ describe("red/nodes/registry/registry",function() {
|
|||||||
describe('#getNodeInfo', function() {
|
describe('#getNodeInfo', function() {
|
||||||
it('returns node info', function() {
|
it('returns node info', function() {
|
||||||
typeRegistry.init(settings,{});
|
typeRegistry.init(settings,{});
|
||||||
typeRegistry.addNodeSet("test-module/test-name",{
|
typeRegistry.addModule({name: "test-module",version:"0.0.1",nodes: {
|
||||||
|
"test-name":{
|
||||||
id: "test-module/test-name",
|
id: "test-module/test-name",
|
||||||
module: "test-module",
|
module: "test-module",
|
||||||
name: "test-name",
|
name: "test-name",
|
||||||
@ -414,7 +425,8 @@ describe("red/nodes/registry/registry",function() {
|
|||||||
config: "configA",
|
config: "configA",
|
||||||
types: [ "test-a","test-b"],
|
types: [ "test-a","test-b"],
|
||||||
file: "abc"
|
file: "abc"
|
||||||
}, "0.0.1");
|
}
|
||||||
|
}});
|
||||||
var nodeSetInfo = typeRegistry.getNodeInfo("test-module/test-name");
|
var nodeSetInfo = typeRegistry.getNodeInfo("test-module/test-name");
|
||||||
nodeSetInfo.should.have.a.property('id',"test-module/test-name");
|
nodeSetInfo.should.have.a.property('id',"test-module/test-name");
|
||||||
nodeSetInfo.should.not.have.a.property('config');
|
nodeSetInfo.should.not.have.a.property('config');
|
||||||
@ -424,7 +436,8 @@ describe("red/nodes/registry/registry",function() {
|
|||||||
describe('#getFullNodeInfo', function() {
|
describe('#getFullNodeInfo', function() {
|
||||||
it('returns node info', function() {
|
it('returns node info', function() {
|
||||||
typeRegistry.init(settings,{});
|
typeRegistry.init(settings,{});
|
||||||
typeRegistry.addNodeSet("test-module/test-name",{
|
typeRegistry.addModule({name: "test-module",version:"0.0.1",nodes: {
|
||||||
|
"test-name":{
|
||||||
id: "test-module/test-name",
|
id: "test-module/test-name",
|
||||||
module: "test-module",
|
module: "test-module",
|
||||||
name: "test-name",
|
name: "test-name",
|
||||||
@ -434,7 +447,8 @@ describe("red/nodes/registry/registry",function() {
|
|||||||
types: [ "test-a","test-b"],
|
types: [ "test-a","test-b"],
|
||||||
file: "abc"
|
file: "abc"
|
||||||
|
|
||||||
}, "0.0.1");
|
}
|
||||||
|
}});
|
||||||
var nodeSetInfo = typeRegistry.getFullNodeInfo("test-module/test-name");
|
var nodeSetInfo = typeRegistry.getFullNodeInfo("test-module/test-name");
|
||||||
nodeSetInfo.should.have.a.property('id',"test-module/test-name");
|
nodeSetInfo.should.have.a.property('id',"test-module/test-name");
|
||||||
nodeSetInfo.should.have.a.property('config');
|
nodeSetInfo.should.have.a.property('config');
|
||||||
@ -447,7 +461,8 @@ describe("red/nodes/registry/registry",function() {
|
|||||||
describe('#getNodeList', function() {
|
describe('#getNodeList', function() {
|
||||||
it("returns a filtered list", function() {
|
it("returns a filtered list", function() {
|
||||||
typeRegistry.init(settings,{});
|
typeRegistry.init(settings,{});
|
||||||
typeRegistry.addNodeSet("test-module/test-name",{
|
typeRegistry.addModule({name: "test-module",version:"0.0.1",nodes: {
|
||||||
|
"test-name":{
|
||||||
id: "test-module/test-name",
|
id: "test-module/test-name",
|
||||||
module: "test-module",
|
module: "test-module",
|
||||||
name: "test-name",
|
name: "test-name",
|
||||||
@ -456,8 +471,8 @@ describe("red/nodes/registry/registry",function() {
|
|||||||
config: "configA",
|
config: "configA",
|
||||||
types: [ "test-a","test-b"],
|
types: [ "test-a","test-b"],
|
||||||
file: "abc"
|
file: "abc"
|
||||||
}, "0.0.1");
|
},
|
||||||
typeRegistry.addNodeSet("test-module/test-name-2",{
|
"test-name-2":{
|
||||||
id: "test-module/test-name-2",
|
id: "test-module/test-name-2",
|
||||||
module: "test-module",
|
module: "test-module",
|
||||||
name: "test-name-2",
|
name: "test-name-2",
|
||||||
@ -466,7 +481,8 @@ describe("red/nodes/registry/registry",function() {
|
|||||||
config: "configB",
|
config: "configB",
|
||||||
types: [ "test-c","test-d"],
|
types: [ "test-c","test-d"],
|
||||||
file: "def"
|
file: "def"
|
||||||
}, "0.0.1");
|
}
|
||||||
|
}});
|
||||||
var filterCallCount = 0;
|
var filterCallCount = 0;
|
||||||
var filteredList = typeRegistry.getNodeList(function(n) { filterCallCount++; return n.name === 'test-name-2';});
|
var filteredList = typeRegistry.getNodeList(function(n) { filterCallCount++; return n.name === 'test-name-2';});
|
||||||
filterCallCount.should.eql(2);
|
filterCallCount.should.eql(2);
|
||||||
@ -532,10 +548,22 @@ describe("red/nodes/registry/registry",function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('returns a registered icon' , function() {
|
it('returns a registered icon' , function() {
|
||||||
var testIcon = path.resolve(__dirname+'/../../../../resources/icons/test_icon.png');
|
var testIcon = path.resolve(__dirname+'/../../../../resources/icons/');
|
||||||
events.emit("node-icon-dir",{name:"test-module", path: path.resolve(__dirname+'/../../../../resources/icons'), icons:[]});
|
typeRegistry.init(settings,{});
|
||||||
|
typeRegistry.addModule({name: "test-module",version:"0.0.1",nodes: {
|
||||||
|
"test-name":{
|
||||||
|
id: "test-module/test-name",
|
||||||
|
module: "test-module",
|
||||||
|
name: "test-name",
|
||||||
|
enabled: true,
|
||||||
|
loaded: false,
|
||||||
|
config: "configA",
|
||||||
|
types: [ "test-a","test-b"],
|
||||||
|
file: "abc"
|
||||||
|
}
|
||||||
|
},icons: [{path:testIcon,icons:['test_icon.png']}]});
|
||||||
var iconPath = typeRegistry.getNodeIconPath('test-module','test_icon.png');
|
var iconPath = typeRegistry.getNodeIconPath('test-module','test_icon.png');
|
||||||
iconPath.should.eql(testIcon);
|
iconPath.should.eql(testIcon+"/test_icon.png");
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns the debug icon when getting an unknown module', function() {
|
it('returns the debug icon when getting an unknown module', function() {
|
||||||
@ -552,14 +580,26 @@ describe("red/nodes/registry/registry",function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('returns an icon list of registered node module', function() {
|
it('returns an icon list of registered node module', function() {
|
||||||
typeRegistry.addNodeSet("test-module/test-name",testNodeSet1,"0.0.1");
|
var testIcon = path.resolve(__dirname+'/resources/userDir/lib/icons/');
|
||||||
events.emit("node-icon-dir",{name:"test-module", path:"",icons:["test_icon1.png"]});
|
typeRegistry.init(settings,{},events);
|
||||||
|
typeRegistry.addModule({name: "test-module",version:"0.0.1",nodes: {
|
||||||
|
"test-name":{
|
||||||
|
id: "test-module/test-name",
|
||||||
|
module: "test-module",
|
||||||
|
name: "test-name",
|
||||||
|
enabled: true,
|
||||||
|
loaded: false,
|
||||||
|
config: "configA",
|
||||||
|
types: [ "test-a","test-b"],
|
||||||
|
file: "abc"
|
||||||
|
}
|
||||||
|
},icons: [{path:testIcon,icons:['test_icon.png']}]});
|
||||||
var iconList = typeRegistry.getNodeIcons();
|
var iconList = typeRegistry.getNodeIcons();
|
||||||
iconList.should.eql({"test-module":["test_icon1.png"]});
|
iconList.should.eql({"test-module":["test_icon.png"]});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns an icon list of unregistered node module', function() {
|
it.skip('returns an icon list of unregistered node module', function() {
|
||||||
events.emit("node-icon-dir",{name:"test-module", path:"", icons:["test_icon1.png", "test_icon2.png"]});
|
// events.emit("node-icon-dir",{name:"test-module", path:"", icons:["test_icon1.png", "test_icon2.png"]});
|
||||||
var iconList = typeRegistry.getNodeIcons();
|
var iconList = typeRegistry.getNodeIcons();
|
||||||
iconList.should.eql({"test-module":["test_icon1.png","test_icon2.png"]});
|
iconList.should.eql({"test-module":["test_icon1.png","test_icon2.png"]});
|
||||||
});
|
});
|
||||||
|
Binary file not shown.
After Width: | Height: | Size: 393 B |
@ -1,3 +0,0 @@
|
|||||||
This file exists just to ensure the 'icons' directory is in the repository.
|
|
||||||
TODO: a future test needs to ensure the right icon files are loaded - this
|
|
||||||
directory can be used for that
|
|
@ -1,3 +0,0 @@
|
|||||||
This file exists just to ensure the 'icons' directory is in the repository.
|
|
||||||
TODO: a future test needs to ensure the right icon files are loaded - this
|
|
||||||
directory can be used for that
|
|
Loading…
Reference in New Issue
Block a user