mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Restore ability to add nodes by filename
This commit is contained in:
parent
4f174308b9
commit
53258eeede
@ -53,20 +53,30 @@ module.exports = {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
promise = server.installModule(node.module);
|
promise = server.installModule(node.module);
|
||||||
|
} else if (node.file) {
|
||||||
|
promise = server.installNode(node.file);
|
||||||
} else {
|
} else {
|
||||||
log.audit({event: "nodes.install",module:node.module,error:"invalid_request"},req);
|
log.audit({event: "nodes.install",module:node.module,error:"invalid_request"},req);
|
||||||
res.json(400,{error:"invalid_request", message:"Invalid request"});
|
res.json(400,{error:"invalid_request", message:"Invalid request"});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
promise.then(function(info) {
|
promise.then(function(info) {
|
||||||
|
if (node.module) {
|
||||||
log.audit({event: "nodes.install",module:node.module},req);
|
log.audit({event: "nodes.install",module:node.module},req);
|
||||||
res.json(redNodes.getModuleInfo(node.module));
|
res.json(redNodes.getModuleInfo(node.module));
|
||||||
|
} else if (node.file) {
|
||||||
|
log.audit({event: "nodes.install",file:node.file},req);
|
||||||
|
res.json(info.nodes[0]);
|
||||||
|
}
|
||||||
}).otherwise(function(err) {
|
}).otherwise(function(err) {
|
||||||
if (err.code === 404) {
|
if (err.code === 404) {
|
||||||
log.audit({event: "nodes.install",module:node.module,error:"not_found"},req);
|
log.audit({event: "nodes.install",module:node.module,file:node.file,error:"not_found"},req);
|
||||||
res.send(404);
|
res.send(404);
|
||||||
|
} else if (err.code) {
|
||||||
|
log.audit({event: "nodes.install",module:node.module,error:err.code},req);
|
||||||
|
res.json(400,{error:err.code, message:err.message});
|
||||||
} else {
|
} else {
|
||||||
log.audit({event: "nodes.install",module:node.module,error:err.code||"unexpected_error",message:err.toString()},req);
|
log.audit({event: "nodes.install",module:node.module,file:node.file,error:err.code||"unexpected_error",message:err.toString()},req);
|
||||||
res.json(400,{error:err.code||"unexpected_error", message:err.toString()});
|
res.json(400,{error:err.code||"unexpected_error", message:err.toString()});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -161,9 +171,10 @@ module.exports = {
|
|||||||
res.send(404);
|
res.send(404);
|
||||||
} else {
|
} else {
|
||||||
delete node.loaded;
|
delete node.loaded;
|
||||||
var result = putNode(node, body.enabled);
|
putNode(node, body.enabled).then(function(result) {
|
||||||
log.audit({event: "nodes.info.set",id:id,enabled:body.enabled},req);
|
log.audit({event: "nodes.info.set",id:id,enabled:body.enabled},req);
|
||||||
res.json(result);
|
res.json(result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
log.audit({event: "nodes.info.set",id:id,enabled:body.enabled,error:err.code||"unexpected_error",message:err.toString()},req);
|
log.audit({event: "nodes.info.set",id:id,enabled:body.enabled,error:err.code||"unexpected_error",message:err.toString()},req);
|
||||||
@ -192,28 +203,13 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var nodes = module.nodes;
|
var nodes = module.nodes;
|
||||||
|
var promises = [];
|
||||||
for (var i = 0; i < nodes.length; ++i) {
|
for (var i = 0; i < nodes.length; ++i) {
|
||||||
var node = nodes[i];
|
promises.push(putNode(nodes[i],body.enabled));
|
||||||
var info;
|
|
||||||
if (node.err || node.enabled !== body.enabled) {
|
|
||||||
if (body.enabled) {
|
|
||||||
info = redNodes.enableNode(node.id);
|
|
||||||
} else {
|
|
||||||
info = redNodes.disableNode(node.id);
|
|
||||||
}
|
|
||||||
if (info.enabled === body.enabled && !info.err) {
|
|
||||||
comms.publish("node/"+(body.enabled?"enabled":"disabled"),info,false);
|
|
||||||
log.info(" "+(body.enabled?"Enabled":"Disabled")+" node types:");
|
|
||||||
for (var j = 0; j < info.types.length; j++) {
|
|
||||||
log.info(" - " + info.types[j]);
|
|
||||||
}
|
|
||||||
} else if (body.enabled && info.err) {
|
|
||||||
log.warn("Failed to enable node:");
|
|
||||||
log.warn(" - "+info.name+" : "+info.err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
when.settle(promises).then(function() {
|
||||||
res.json(redNodes.getModuleInfo(mod));
|
res.json(redNodes.getModuleInfo(mod));
|
||||||
|
});
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
log.audit({event: "nodes.module.set",module:mod,enabled:body.enabled,error:err.code||"unexpected_error",message:err.toString()},req);
|
log.audit({event: "nodes.module.set",module:mod,enabled:body.enabled,error:err.code||"unexpected_error",message:err.toString()},req);
|
||||||
res.json(400,{error:err.code||"unexpected_error", message:err.toString()});
|
res.json(400,{error:err.code||"unexpected_error", message:err.toString()});
|
||||||
@ -223,16 +219,17 @@ module.exports = {
|
|||||||
|
|
||||||
function putNode(node, enabled) {
|
function putNode(node, enabled) {
|
||||||
var info;
|
var info;
|
||||||
|
var promise;
|
||||||
if (!node.err && node.enabled === enabled) {
|
if (!node.err && node.enabled === enabled) {
|
||||||
info = node;
|
promise = when.resolve(node);
|
||||||
} else {
|
} else {
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
info = redNodes.enableNode(node.id);
|
promise = redNodes.enableNode(node.id);
|
||||||
} else {
|
} else {
|
||||||
info = redNodes.disableNode(node.id);
|
promise = redNodes.disableNode(node.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return promise.then(function(info) {
|
||||||
if (info.enabled === enabled && !info.err) {
|
if (info.enabled === enabled && !info.err) {
|
||||||
comms.publish("node/"+(enabled?"enabled":"disabled"),info,false);
|
comms.publish("node/"+(enabled?"enabled":"disabled"),info,false);
|
||||||
log.info(" "+(enabled?"Enabled":"Disabled")+" node types:");
|
log.info(" "+(enabled?"Enabled":"Disabled")+" node types:");
|
||||||
@ -243,7 +240,9 @@ function putNode(node, enabled) {
|
|||||||
log.warn("Failed to enable node:");
|
log.warn("Failed to enable node:");
|
||||||
log.warn(" - "+info.name+" : "+info.err);
|
log.warn(" - "+info.name+" : "+info.err);
|
||||||
}
|
}
|
||||||
|
return info;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return info;
|
return promise;
|
||||||
}
|
}
|
||||||
|
@ -115,6 +115,7 @@ module.exports = {
|
|||||||
getNode: flows.get,
|
getNode: flows.get,
|
||||||
eachNode: flows.eachNode,
|
eachNode: flows.eachNode,
|
||||||
|
|
||||||
|
addFile: registry.addFile,
|
||||||
addModule: registry.addModule,
|
addModule: registry.addModule,
|
||||||
removeModule: removeModule,
|
removeModule: removeModule,
|
||||||
|
|
||||||
|
@ -36,6 +36,12 @@ function load(defaultNodesDir,disableNodePathScan) {
|
|||||||
return loader.load(defaultNodesDir,disableNodePathScan);
|
return loader.load(defaultNodesDir,disableNodePathScan);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addFile(file) {
|
||||||
|
var info = "node-red/"+path.basename(file).replace(/^\d+-/,"").replace(/\.js$/,"");
|
||||||
|
return loader.addFile(file).then(function() {
|
||||||
|
return registry.getNodeInfo(info);
|
||||||
|
});
|
||||||
|
}
|
||||||
function addModule(module) {
|
function addModule(module) {
|
||||||
return loader.addModule(module).then(function() {
|
return loader.addModule(module).then(function() {
|
||||||
return registry.getModuleInfo(module);
|
return registry.getModuleInfo(module);
|
||||||
@ -43,13 +49,15 @@ function addModule(module) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function enableNodeSet(typeOrId) {
|
function enableNodeSet(typeOrId) {
|
||||||
registry.enableNodeSet(typeOrId);
|
return registry.enableNodeSet(typeOrId).then(function() {
|
||||||
var nodeSet = registry.getNodeInfo(typeOrId);
|
var nodeSet = registry.getNodeInfo(typeOrId);
|
||||||
if (!nodeSet.loaded) {
|
if (!nodeSet.loaded) {
|
||||||
loader.loadNodeSet(nodeSet);
|
return loader.loadNodeSet(registry.getFullNodeInfo(typeOrId)).then(function() {
|
||||||
return registry.getNodeInfo(typeOrId);
|
return registry.getNodeInfo(typeOrId);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return nodeSet;
|
return when.resolve(nodeSet);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
@ -71,6 +79,7 @@ module.exports = {
|
|||||||
enableNode: enableNodeSet,
|
enableNode: enableNodeSet,
|
||||||
disableNode: registry.disableNodeSet,
|
disableNode: registry.disableNodeSet,
|
||||||
|
|
||||||
|
addFile: addFile,
|
||||||
addModule: addModule,
|
addModule: addModule,
|
||||||
removeModule: registry.removeModule,
|
removeModule: registry.removeModule,
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ function loadNodeFiles(nodeFiles) {
|
|||||||
for (var module in nodeFiles) {
|
for (var module in nodeFiles) {
|
||||||
/* istanbul ignore else */
|
/* istanbul ignore else */
|
||||||
if (nodeFiles.hasOwnProperty(module)) {
|
if (nodeFiles.hasOwnProperty(module)) {
|
||||||
if (!registry.getModuleInfo(module)) {
|
if (module == "node-red" || !registry.getModuleInfo(module)) {
|
||||||
var first = true;
|
var first = true;
|
||||||
for (var node in nodeFiles[module].nodes) {
|
for (var node in nodeFiles[module].nodes) {
|
||||||
/* istanbul ignore else */
|
/* istanbul ignore else */
|
||||||
@ -174,6 +174,7 @@ function loadNodeSet(node) {
|
|||||||
var nodeFn = path.basename(node.file);
|
var nodeFn = path.basename(node.file);
|
||||||
if (!node.enabled) {
|
if (!node.enabled) {
|
||||||
return when.resolve(node);
|
return when.resolve(node);
|
||||||
|
} else {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
var loadPromise = null;
|
var loadPromise = null;
|
||||||
@ -228,7 +229,9 @@ function addModule(module) {
|
|||||||
}
|
}
|
||||||
var nodes = [];
|
var nodes = [];
|
||||||
if (registry.getModuleInfo(module)) {
|
if (registry.getModuleInfo(module)) {
|
||||||
return when.reject(new Error("Module already loaded"));
|
var e = new Error("Module already loaded");
|
||||||
|
e.code = "module_already_loaded";
|
||||||
|
return when.reject(e);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
var moduleFiles = localfilesystem.getModuleFiles(module);
|
var moduleFiles = localfilesystem.getModuleFiles(module);
|
||||||
@ -238,9 +241,38 @@ function addModule(module) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addFile(file) {
|
||||||
|
if (!settings.available()) {
|
||||||
|
throw new Error("Settings unavailable");
|
||||||
|
}
|
||||||
|
var info = registry.getNodeInfo("node-red/"+path.basename(file).replace(/^\d+-/,"").replace(/\.js$/,""));
|
||||||
|
if (info) {
|
||||||
|
var err = new Error("File already loaded");
|
||||||
|
err.code = "file_already_loaded";
|
||||||
|
return when.reject(err);
|
||||||
|
}
|
||||||
|
var nodeFiles = localfilesystem.getLocalFile(file);
|
||||||
|
if (nodeFiles) {
|
||||||
|
var fileObj = {};
|
||||||
|
fileObj[nodeFiles.module] = {
|
||||||
|
name: nodeFiles.module,
|
||||||
|
version: nodeFiles.version,
|
||||||
|
nodes: {}
|
||||||
|
};
|
||||||
|
fileObj[nodeFiles.module].nodes[nodeFiles.name] = nodeFiles;
|
||||||
|
|
||||||
|
return loadNodeFiles(fileObj);
|
||||||
|
} else {
|
||||||
|
var e = new Error();
|
||||||
|
e.code = 404;
|
||||||
|
return when.reject(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
init: init,
|
init: init,
|
||||||
load: load,
|
load: load,
|
||||||
addModule: addModule,
|
addModule: addModule,
|
||||||
|
addFile: addFile,
|
||||||
loadNodeSet: loadNodeSet
|
loadNodeSet: loadNodeSet
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,26 @@ function init(_settings,_defaultNodesDir,_disableNodePathScan) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getLocalFile(file) {
|
||||||
|
if (settings.nodesExcludes) {
|
||||||
|
for (var i=0;i<settings.nodesExcludes.length;i++) {
|
||||||
|
if (settings.nodesExcludes[i] == path.basename(file)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fs.existsSync(file.replace(/\.js$/,".html"))) {
|
||||||
|
return {
|
||||||
|
file: file,
|
||||||
|
module: "node-red",
|
||||||
|
name: path.basename(file).replace(/^\d+-/,"").replace(/\.js$/,""),
|
||||||
|
version: settings.version
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Synchronously walks the directory looking for node files.
|
* Synchronously walks the directory looking for node files.
|
||||||
@ -54,24 +74,9 @@ function getLocalNodeFiles(dir) {
|
|||||||
var stats = fs.statSync(path.join(dir,fn));
|
var stats = fs.statSync(path.join(dir,fn));
|
||||||
if (stats.isFile()) {
|
if (stats.isFile()) {
|
||||||
if (/\.js$/.test(fn)) {
|
if (/\.js$/.test(fn)) {
|
||||||
var valid = true;
|
var info = getLocalFile(path.join(dir,fn));
|
||||||
if (settings.nodesExcludes) {
|
if (info) {
|
||||||
for (var i=0;i<settings.nodesExcludes.length;i++) {
|
result.push(info);
|
||||||
if (settings.nodesExcludes[i] == fn) {
|
|
||||||
valid = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
valid = valid && fs.existsSync(path.join(dir,fn.replace(/\.js$/,".html")));
|
|
||||||
|
|
||||||
if (valid) {
|
|
||||||
result.push({
|
|
||||||
file: path.join(dir,fn),
|
|
||||||
module: "node-red",
|
|
||||||
name: path.basename(fn).replace(/^\d+-/,"").replace(/\.js$/,""),
|
|
||||||
version: settings.version
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (stats.isDirectory()) {
|
} else if (stats.isDirectory()) {
|
||||||
@ -256,5 +261,6 @@ function getModuleFiles(module) {
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
init: init,
|
init: init,
|
||||||
getNodeFiles: getNodeFiles,
|
getNodeFiles: getNodeFiles,
|
||||||
|
getLocalFile: getLocalFile,
|
||||||
getModuleFiles: getModuleFiles
|
getModuleFiles: getModuleFiles
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ function init(_settings) {
|
|||||||
|
|
||||||
function filterNodeInfo(n) {
|
function filterNodeInfo(n) {
|
||||||
var r = {
|
var r = {
|
||||||
id: n.id,
|
id: n.id||n.module+"/"+n.name,
|
||||||
name: n.name,
|
name: n.name,
|
||||||
types: n.types,
|
types: n.types,
|
||||||
enabled: n.enabled
|
enabled: n.enabled
|
||||||
@ -220,7 +220,6 @@ function getNodeInfo(typeOrId) {
|
|||||||
if (nodeTypeToId[typeOrId]) {
|
if (nodeTypeToId[typeOrId]) {
|
||||||
id = nodeTypeToId[typeOrId];
|
id = nodeTypeToId[typeOrId];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* istanbul ignore else */
|
/* istanbul ignore else */
|
||||||
if (id) {
|
if (id) {
|
||||||
var module = moduleConfigs[getModule(id)];
|
var module = moduleConfigs[getModule(id)];
|
||||||
@ -239,6 +238,23 @@ function getNodeInfo(typeOrId) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getFullNodeInfo(typeOrId) {
|
||||||
|
// Used by index.enableNodeSet so that .file can be retrieved to pass
|
||||||
|
// to loader.loadNodeSet
|
||||||
|
var id = typeOrId;
|
||||||
|
if (nodeTypeToId[typeOrId]) {
|
||||||
|
id = nodeTypeToId[typeOrId];
|
||||||
|
}
|
||||||
|
/* istanbul ignore else */
|
||||||
|
if (id) {
|
||||||
|
var module = moduleConfigs[getModule(id)];
|
||||||
|
if (module) {
|
||||||
|
return module.nodes[getNode(id)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
function getNodeList(filter) {
|
function getNodeList(filter) {
|
||||||
var list = [];
|
var list = [];
|
||||||
for (var module in moduleConfigs) {
|
for (var module in moduleConfigs) {
|
||||||
@ -380,22 +396,18 @@ function enableNodeSet(typeOrId) {
|
|||||||
if (nodeTypeToId[typeOrId]) {
|
if (nodeTypeToId[typeOrId]) {
|
||||||
id = nodeTypeToId[typeOrId];
|
id = nodeTypeToId[typeOrId];
|
||||||
}
|
}
|
||||||
|
|
||||||
var config;
|
var config;
|
||||||
try {
|
try {
|
||||||
config = moduleConfigs[getModule(id)].nodes[getNode(id)];
|
config = moduleConfigs[getModule(id)].nodes[getNode(id)];
|
||||||
delete config.err;
|
delete config.err;
|
||||||
config.enabled = true;
|
config.enabled = true;
|
||||||
//if (!config.loaded) {
|
|
||||||
// // TODO: honour the promise this returns
|
|
||||||
// loadNodeModule(config);
|
|
||||||
//}
|
|
||||||
nodeConfigCache = null;
|
nodeConfigCache = null;
|
||||||
saveNodeList();
|
return saveNodeList().then(function() {
|
||||||
|
return filterNodeInfo(config);
|
||||||
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new Error("Unrecognised id: "+typeOrId);
|
throw new Error("Unrecognised id: "+typeOrId);
|
||||||
}
|
}
|
||||||
return filterNodeInfo(config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function disableNodeSet(typeOrId) {
|
function disableNodeSet(typeOrId) {
|
||||||
@ -412,11 +424,12 @@ function disableNodeSet(typeOrId) {
|
|||||||
// TODO: persist setting
|
// TODO: persist setting
|
||||||
config.enabled = false;
|
config.enabled = false;
|
||||||
nodeConfigCache = null;
|
nodeConfigCache = null;
|
||||||
saveNodeList();
|
return saveNodeList().then(function() {
|
||||||
|
return filterNodeInfo(config);
|
||||||
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new Error("Unrecognised id: "+id);
|
throw new Error("Unrecognised id: "+id);
|
||||||
}
|
}
|
||||||
return filterNodeInfo(config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function cleanModuleList() {
|
function cleanModuleList() {
|
||||||
@ -472,6 +485,7 @@ var registry = module.exports = {
|
|||||||
removeModule: removeModule,
|
removeModule: removeModule,
|
||||||
|
|
||||||
getNodeInfo: getNodeInfo,
|
getNodeInfo: getNodeInfo,
|
||||||
|
getFullNodeInfo: getFullNodeInfo,
|
||||||
getNodeList: getNodeList,
|
getNodeList: getNodeList,
|
||||||
getModuleList: getModuleList,
|
getModuleList: getModuleList,
|
||||||
getModuleInfo: getModuleInfo,
|
getModuleInfo: getModuleInfo,
|
||||||
|
@ -142,6 +142,19 @@ function reportRemovedModules(removedNodes) {
|
|||||||
return removedNodes;
|
return removedNodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function installNode(file) {
|
||||||
|
return when.promise(function(resolve,reject) {
|
||||||
|
resolve(redNodes.addFile(file).then(function(info) {
|
||||||
|
var module = redNodes.getModuleInfo(info.module);
|
||||||
|
module.nodes = module.nodes.filter(function(d) {
|
||||||
|
return d.id==info.id;
|
||||||
|
});
|
||||||
|
return reportAddedModules(module);
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function installModule(module) {
|
function installModule(module) {
|
||||||
//TODO: ensure module is 'safe'
|
//TODO: ensure module is 'safe'
|
||||||
return when.promise(function(resolve,reject) {
|
return when.promise(function(resolve,reject) {
|
||||||
@ -149,6 +162,14 @@ function installModule(module) {
|
|||||||
reject(new Error("Invalid module name"));
|
reject(new Error("Invalid module name"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (redNodes.getModuleInfo(module)) {
|
||||||
|
var err = new Error("Module already loaded");
|
||||||
|
err.code = "module_already_loaded";
|
||||||
|
reject(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
log.info("Installing module: "+module);
|
log.info("Installing module: "+module);
|
||||||
var installDir = settings.userDir || process.env.NODE_RED_HOME || ".";
|
var installDir = settings.userDir || process.env.NODE_RED_HOME || ".";
|
||||||
var child = child_process.exec('npm install --production '+module,
|
var child = child_process.exec('npm install --production '+module,
|
||||||
@ -252,6 +273,7 @@ var serverAPI = module.exports = {
|
|||||||
reportRemovedModules: reportRemovedModules,
|
reportRemovedModules: reportRemovedModules,
|
||||||
installModule: installModule,
|
installModule: installModule,
|
||||||
uninstallModule: uninstallModule,
|
uninstallModule: uninstallModule,
|
||||||
|
installNode: installNode,
|
||||||
|
|
||||||
get app() { return app },
|
get app() { return app },
|
||||||
get nodeApp() { return nodeApp },
|
get nodeApp() { return nodeApp },
|
||||||
|
@ -528,7 +528,7 @@ describe("nodes api", function() {
|
|||||||
return {id:"123",enabled: false};
|
return {id:"123",enabled: false};
|
||||||
});
|
});
|
||||||
var enableNode = sinon.stub(redNodes,'enableNode',function(id) {
|
var enableNode = sinon.stub(redNodes,'enableNode',function(id) {
|
||||||
return {id:"123",enabled: true,types:['a']};
|
return when.resolve({id:"123",enabled: true,types:['a']});
|
||||||
});
|
});
|
||||||
|
|
||||||
request(app)
|
request(app)
|
||||||
@ -557,7 +557,7 @@ describe("nodes api", function() {
|
|||||||
return {id:"123",enabled: true};
|
return {id:"123",enabled: true};
|
||||||
});
|
});
|
||||||
var disableNode = sinon.stub(redNodes,'disableNode',function(id) {
|
var disableNode = sinon.stub(redNodes,'disableNode',function(id) {
|
||||||
return {id:"123",enabled: false,types:['a']};
|
return when.resolve({id:"123",enabled: false,types:['a']});
|
||||||
});
|
});
|
||||||
|
|
||||||
request(app)
|
request(app)
|
||||||
@ -587,11 +587,11 @@ describe("nodes api", function() {
|
|||||||
return {id:"123",enabled: state};
|
return {id:"123",enabled: state};
|
||||||
});
|
});
|
||||||
var enableNode = sinon.stub(redNodes,'enableNode',function(id) {
|
var enableNode = sinon.stub(redNodes,'enableNode',function(id) {
|
||||||
return {id:"123",enabled: true,types:['a']};
|
return when.resolve({id:"123",enabled: true,types:['a']});
|
||||||
});
|
});
|
||||||
|
|
||||||
var disableNode = sinon.stub(redNodes,'disableNode',function(id) {
|
var disableNode = sinon.stub(redNodes,'disableNode',function(id) {
|
||||||
return {id:"123",enabled: false,types:['a']};
|
return when.resolve({id:"123",enabled: false,types:['a']});
|
||||||
});
|
});
|
||||||
|
|
||||||
request(app)
|
request(app)
|
||||||
@ -633,11 +633,11 @@ describe("nodes api", function() {
|
|||||||
return {id:"123",enabled: state, err:"foo" };
|
return {id:"123",enabled: state, err:"foo" };
|
||||||
});
|
});
|
||||||
var enableNode = sinon.stub(redNodes,'enableNode',function(id) {
|
var enableNode = sinon.stub(redNodes,'enableNode',function(id) {
|
||||||
return {id:"123",enabled: true,types:['a']};
|
return when.resolve({id:"123",enabled: true,types:['a']});
|
||||||
});
|
});
|
||||||
|
|
||||||
var disableNode = sinon.stub(redNodes,'disableNode',function(id) {
|
var disableNode = sinon.stub(redNodes,'disableNode',function(id) {
|
||||||
return {id:"123",enabled: false,types:['a']};
|
return when.resolve({id:"123",enabled: false,types:['a']});
|
||||||
});
|
});
|
||||||
|
|
||||||
request(app)
|
request(app)
|
||||||
@ -683,11 +683,11 @@ describe("nodes api", function() {
|
|||||||
var enableNode = sinon.stub(redNodes,'enableNode');
|
var enableNode = sinon.stub(redNodes,'enableNode');
|
||||||
enableNode.onFirstCall().returns((function() {
|
enableNode.onFirstCall().returns((function() {
|
||||||
n1.enabled = true;
|
n1.enabled = true;
|
||||||
return n1;
|
return when.resolve(n1);
|
||||||
})());
|
})());
|
||||||
enableNode.onSecondCall().returns((function() {
|
enableNode.onSecondCall().returns((function() {
|
||||||
n2.enabled = true;
|
n2.enabled = true;
|
||||||
return n2;
|
return when.resolve(n2);
|
||||||
})());
|
})());
|
||||||
enableNode.returns(null);
|
enableNode.returns(null);
|
||||||
|
|
||||||
@ -724,11 +724,11 @@ describe("nodes api", function() {
|
|||||||
var disableNode = sinon.stub(redNodes,'disableNode');
|
var disableNode = sinon.stub(redNodes,'disableNode');
|
||||||
disableNode.onFirstCall().returns((function() {
|
disableNode.onFirstCall().returns((function() {
|
||||||
n1.enabled = false;
|
n1.enabled = false;
|
||||||
return n1;
|
return when.resolve(n1);
|
||||||
})());
|
})());
|
||||||
disableNode.onSecondCall().returns((function() {
|
disableNode.onSecondCall().returns((function() {
|
||||||
n2.enabled = false;
|
n2.enabled = false;
|
||||||
return n2;
|
return when.resolve(n2);
|
||||||
})());
|
})());
|
||||||
disableNode.returns(null);
|
disableNode.returns(null);
|
||||||
|
|
||||||
@ -763,11 +763,11 @@ describe("nodes api", function() {
|
|||||||
});
|
});
|
||||||
var enableNode = sinon.stub(redNodes,'enableNode',function(id) {
|
var enableNode = sinon.stub(redNodes,'enableNode',function(id) {
|
||||||
node.enabled = true;
|
node.enabled = true;
|
||||||
return node;
|
return when.resolve(node);
|
||||||
});
|
});
|
||||||
var disableNode = sinon.stub(redNodes,'disableNode',function(id) {
|
var disableNode = sinon.stub(redNodes,'disableNode',function(id) {
|
||||||
node.enabled = false;
|
node.enabled = false;
|
||||||
return node;
|
return when.resolve(node);
|
||||||
});
|
});
|
||||||
|
|
||||||
request(app)
|
request(app)
|
||||||
@ -812,11 +812,11 @@ describe("nodes api", function() {
|
|||||||
});
|
});
|
||||||
var enableNode = sinon.stub(redNodes,'enableNode',function(id) {
|
var enableNode = sinon.stub(redNodes,'enableNode',function(id) {
|
||||||
node.enabled = true;
|
node.enabled = true;
|
||||||
return node;
|
return when.resolve(node);
|
||||||
});
|
});
|
||||||
var disableNode = sinon.stub(redNodes,'disableNode',function(id) {
|
var disableNode = sinon.stub(redNodes,'disableNode',function(id) {
|
||||||
node.enabled = false;
|
node.enabled = false;
|
||||||
return node;
|
return when.resolve(node);
|
||||||
});
|
});
|
||||||
|
|
||||||
request(app)
|
request(app)
|
||||||
|
@ -837,7 +837,7 @@ describe('red/nodes/registry/index', function() {
|
|||||||
var nodeConfig = typeRegistry.getNodeConfigs();
|
var nodeConfig = typeRegistry.getNodeConfigs();
|
||||||
nodeConfig.length.should.be.greaterThan(0);
|
nodeConfig.length.should.be.greaterThan(0);
|
||||||
|
|
||||||
var info = typeRegistry.disableNode(list[0].id);
|
typeRegistry.disableNode(list[0].id).then(function(info) {
|
||||||
info.should.have.property("id",list[0].id);
|
info.should.have.property("id",list[0].id);
|
||||||
info.should.have.property("enabled",false);
|
info.should.have.property("enabled",false);
|
||||||
|
|
||||||
@ -847,7 +847,7 @@ describe('red/nodes/registry/index', function() {
|
|||||||
|
|
||||||
typeRegistry.getNodeConfigs().length.should.equal(0);
|
typeRegistry.getNodeConfigs().length.should.equal(0);
|
||||||
|
|
||||||
var info2 = typeRegistry.enableNode(list[0].id);
|
typeRegistry.enableNode(list[0].id).then(function(info2) {
|
||||||
info2.should.have.property("id",list[0].id);
|
info2.should.have.property("id",list[0].id);
|
||||||
info2.should.have.property("enabled",true);
|
info2.should.have.property("enabled",true);
|
||||||
|
|
||||||
@ -859,6 +859,8 @@ describe('red/nodes/registry/index', function() {
|
|||||||
nodeConfig2.should.eql(nodeConfig);
|
nodeConfig2.should.eql(nodeConfig);
|
||||||
|
|
||||||
done();
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
}).catch(function(e) {
|
}).catch(function(e) {
|
||||||
done(e);
|
done(e);
|
||||||
});
|
});
|
||||||
@ -879,7 +881,7 @@ describe('red/nodes/registry/index', function() {
|
|||||||
var nodeConfig = typeRegistry.getNodeConfigs();
|
var nodeConfig = typeRegistry.getNodeConfigs();
|
||||||
nodeConfig.length.should.be.greaterThan(0);
|
nodeConfig.length.should.be.greaterThan(0);
|
||||||
|
|
||||||
var info = typeRegistry.disableNode(list[0].types[0]);
|
typeRegistry.disableNode(list[0].types[0]).then(function(info) {;
|
||||||
info.should.have.property("id",list[0].id);
|
info.should.have.property("id",list[0].id);
|
||||||
info.should.have.property("types",list[0].types);
|
info.should.have.property("types",list[0].types);
|
||||||
info.should.have.property("enabled",false);
|
info.should.have.property("enabled",false);
|
||||||
@ -890,7 +892,7 @@ describe('red/nodes/registry/index', function() {
|
|||||||
|
|
||||||
typeRegistry.getNodeConfigs().length.should.equal(0);
|
typeRegistry.getNodeConfigs().length.should.equal(0);
|
||||||
|
|
||||||
var info2 = typeRegistry.enableNode(list[0].types[0]);
|
typeRegistry.enableNode(list[0].types[0]).then(function(info2) {
|
||||||
info2.should.have.property("id",list[0].id);
|
info2.should.have.property("id",list[0].id);
|
||||||
info2.should.have.property("types",list[0].types);
|
info2.should.have.property("types",list[0].types);
|
||||||
info2.should.have.property("enabled",true);
|
info2.should.have.property("enabled",true);
|
||||||
@ -903,6 +905,8 @@ describe('red/nodes/registry/index', function() {
|
|||||||
nodeConfig2.should.eql(nodeConfig);
|
nodeConfig2.should.eql(nodeConfig);
|
||||||
|
|
||||||
done();
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
}).catch(function(e) {
|
}).catch(function(e) {
|
||||||
done(e);
|
done(e);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user