Resync with master

This commit is contained in:
Nick O'Leary
2017-03-01 17:45:09 +00:00
24 changed files with 318 additions and 184 deletions

View File

@@ -170,7 +170,7 @@
this.handleDebugMessage = function(t,o) {
var sourceNode = RED.nodes.node(o.id) || RED.nodes.node(o.z);
if (sourceNode) {
o._source = {id:sourceNode.id,z:sourceNode.z};
o._source = {id:sourceNode.id,z:sourceNode.z,name:sourceNode.name};
}
RED.debug.handleDebugMessage(o);

View File

@@ -47,10 +47,13 @@
<p>Calls out to a system command.<br/></p>
<p>Provides 3 outputs: stdout, stderr, and return code.</p>
<p>By default uses the <code>exec</code> system call which calls the command, then gets a callback
on completion, returning the complete result in one message, along with any errors.</p>
on completion, returning stdout as the payload to the first, the error code as the third
and, if available, stderr to the second output. If no error occurred, a zero is returned on the third output.</p>
<p>Optionally can use <code>spawn</code> instead, which returns the output from stdout and stderr
as the command runs (usually one line at a time). On completion it then returns a return code
(on the 3rd output).</p>
<p>The <code>exec</code> method spawns a subshell and therefore can be used for more complicated
commands involving pipes. However, it waits for completion of the whole command before returing anything.</p>
<p>The optional append gets added to the command after <code>msg.payload</code> - so you can do
things like pipe the result to another command.</p>
<p>Commands or parameters with spaces should be enclosed in quotes - <i>"This is a single parameter"</i></p>

View File

@@ -115,12 +115,17 @@ module.exports = function(RED) {
child = exec(cl, {encoding: 'binary', maxBuffer:10000000}, function (error, stdout, stderr) {
msg.payload = new Buffer(stdout,"binary");
if (isUtf8(msg.payload)) { msg.payload = msg.payload.toString(); }
var msg2 = {payload:stderr};
var msg3 = null;
var msg2 = null;
if(stderr) {
msg2 = {payload: stderr};
}
var msg3 = {payload:0};
node.status({});
//console.log('[exec] stdout: ' + stdout);
//console.log('[exec] stderr: ' + stderr);
if (error !== null) {
msg3 = {payload:error};
msg3 = {payload:error.code};
node.status({fill:"red",shape:"dot",text:"error: "+error.code});
//console.log('[exec] error: ' + error);
}
if (!msg3) { node.status({}); }

View File

@@ -22,8 +22,8 @@ module.exports = function(RED) {
* Custom Mustache Context capable to resolve message property and node
* flow and global context
*/
function NodeContext(msg, nodeContext) {
this.msgContext = new mustache.Context(msg);
function NodeContext(msg, nodeContext,parent) {
this.msgContext = new mustache.Context(msg,parent);
this.nodeContext = nodeContext;
}
@@ -31,26 +31,34 @@ module.exports = function(RED) {
NodeContext.prototype.lookup = function (name) {
// try message first:
var value = this.msgContext.lookup(name);
if (value !== undefined) {
return value;
}
// try node context:
var dot = name.indexOf(".");
if (dot > 0) {
var contextName = name.substr(0, dot);
var variableName = name.substr(dot + 1);
if (contextName === "flow" && this.nodeContext.flow) {
return this.nodeContext.flow.get(variableName);
try {
var value = this.msgContext.lookup(name);
if (value !== undefined) {
return value;
}
else if (contextName === "global" && this.nodeContext.global) {
return this.nodeContext.global.get(variableName);
// try node context:
var dot = name.indexOf(".");
if (dot > 0) {
var contextName = name.substr(0, dot);
var variableName = name.substr(dot + 1);
if (contextName === "flow" && this.nodeContext.flow) {
return this.nodeContext.flow.get(variableName);
}
else if (contextName === "global" && this.nodeContext.global) {
return this.nodeContext.global.get(variableName);
}
}
}catch(err) {
throw err;
}
}
NodeContext.prototype.push = function push (view) {
return new NodeContext(view, this.nodeContext,this.msgContext);
};
function TemplateNode(n) {
RED.nodes.createNode(this,n);
this.name = n.name;
@@ -65,7 +73,7 @@ module.exports = function(RED) {
try {
var value;
if (node.syntax === "mustache") {
value = mustache.render(node.template, new NodeContext(msg, node.context()));
value = mustache.render(node.template,new NodeContext(msg, node.context()));
} else {
value = node.template;
}

View File

@@ -205,7 +205,7 @@ RED.debug = (function() {
var metaRow = $('<div class="debug-message-meta"></div>').appendTo(msg);
$('<span class="debug-message-date">'+ getTimestamp()+'</span>').appendTo(metaRow);
if (sourceNode) {
$('<a>',{href:"#",class:"debug-message-name"}).html('node: '+sourceNode.id)
$('<a>',{href:"#",class:"debug-message-name"}).html('node: '+(sourceNode.name||sourceNode.id))
.appendTo(metaRow)
.click(function(evt) {
evt.preventDefault();