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) {
|
||||||
log.audit({event: "nodes.install",module:node.module},req);
|
if (node.module) {
|
||||||
res.json(redNodes.getModuleInfo(node.module));
|
log.audit({event: "nodes.install",module:node.module},req);
|
||||||
|
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 {
|
} else if (err.code) {
|
||||||
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,error:err.code},req);
|
||||||
|
res.json(400,{error:err.code, message:err.message});
|
||||||
|
} else {
|
||||||
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
res.json(redNodes.getModuleInfo(mod));
|
when.settle(promises).then(function() {
|
||||||
|
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,27 +219,30 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info.enabled === enabled && !info.err) {
|
return promise.then(function(info) {
|
||||||
comms.publish("node/"+(enabled?"enabled":"disabled"),info,false);
|
if (info.enabled === enabled && !info.err) {
|
||||||
log.info(" "+(enabled?"Enabled":"Disabled")+" node types:");
|
comms.publish("node/"+(enabled?"enabled":"disabled"),info,false);
|
||||||
for (var i=0;i<info.types.length;i++) {
|
log.info(" "+(enabled?"Enabled":"Disabled")+" node types:");
|
||||||
log.info(" - "+info.types[i]);
|
for (var i=0;i<info.types.length;i++) {
|
||||||
|
log.info(" - "+info.types[i]);
|
||||||
|
}
|
||||||
|
} else if (enabled && info.err) {
|
||||||
|
log.warn("Failed to enable node:");
|
||||||
|
log.warn(" - "+info.name+" : "+info.err);
|
||||||
}
|
}
|
||||||
} else if (enabled && info.err) {
|
return info;
|
||||||
log.warn("Failed to enable node:");
|
});
|
||||||
log.warn(" - "+info.name+" : "+info.err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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,28 +837,30 @@ 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);
|
||||||
|
|
||||||
var list2 = typeRegistry.getNodeList();
|
var list2 = typeRegistry.getNodeList();
|
||||||
list2.should.be.an.Array.and.have.lengthOf(1);
|
list2.should.be.an.Array.and.have.lengthOf(1);
|
||||||
list2[0].should.have.property("enabled",false);
|
list2[0].should.have.property("enabled",false);
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
var list3 = typeRegistry.getNodeList();
|
var list3 = typeRegistry.getNodeList();
|
||||||
list3.should.be.an.Array.and.have.lengthOf(1);
|
list3.should.be.an.Array.and.have.lengthOf(1);
|
||||||
list3[0].should.have.property("enabled",true);
|
list3[0].should.have.property("enabled",true);
|
||||||
|
|
||||||
var nodeConfig2 = typeRegistry.getNodeConfigs();
|
var nodeConfig2 = typeRegistry.getNodeConfigs();
|
||||||
nodeConfig2.should.eql(nodeConfig);
|
nodeConfig2.should.eql(nodeConfig);
|
||||||
|
|
||||||
done();
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
}).catch(function(e) {
|
}).catch(function(e) {
|
||||||
done(e);
|
done(e);
|
||||||
});
|
});
|
||||||
@ -879,30 +881,32 @@ 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);
|
||||||
|
|
||||||
var list2 = typeRegistry.getNodeList();
|
var list2 = typeRegistry.getNodeList();
|
||||||
list2.should.be.an.Array.and.have.lengthOf(1);
|
list2.should.be.an.Array.and.have.lengthOf(1);
|
||||||
list2[0].should.have.property("enabled",false);
|
list2[0].should.have.property("enabled",false);
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
var list3 = typeRegistry.getNodeList();
|
var list3 = typeRegistry.getNodeList();
|
||||||
list3.should.be.an.Array.and.have.lengthOf(1);
|
list3.should.be.an.Array.and.have.lengthOf(1);
|
||||||
list3[0].should.have.property("enabled",true);
|
list3[0].should.have.property("enabled",true);
|
||||||
|
|
||||||
var nodeConfig2 = typeRegistry.getNodeConfigs();
|
var nodeConfig2 = typeRegistry.getNodeConfigs();
|
||||||
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