-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
119 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<script> | ||
RED.nodes.registerType('test-node', { | ||
category: 'function', | ||
defaults: { | ||
name: { value: '', }, | ||
multiplyBy: { value: 2, }, | ||
}, | ||
inputs: 1, | ||
outputs: 1, | ||
icon: 'function.png', | ||
label: function () { | ||
return this.name || 'test-node'; | ||
}, | ||
}); | ||
</script> | ||
|
||
<script type="text/x-red" data-template-name="test-node"> | ||
<div class="form-row"> | ||
<label for="node-input-name"><i class="icon-tag"></i> Name</label> | ||
<input type="text" id="node-input-name" placeholder="Name" /> | ||
</div> | ||
<div class="form-row"> | ||
<label for="node-input-multiplyBy"><i class="icon-tag"></i> Multiply by</label> | ||
<input type="number" id="node-input-multiplyBy" placeholder="2" /> | ||
</div> | ||
</script> | ||
|
||
<script type="text/x-red" data-help-name="test-node"> | ||
<p> | ||
This test node will multiply the payload by the value given in the <code>multiplyBy</code> property. | ||
</p> | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* jshint esversion:8, node:true, strict:true */ | ||
/** | ||
* Node-RED test node. | ||
*/ | ||
|
||
module.exports = RED => { | ||
"use strict"; | ||
|
||
function TestNode(config) { | ||
RED.nodes.createNode(this, config); | ||
const node = this; | ||
const multiplyBy = config.multiplyBy; | ||
|
||
node.on('input', async msg => { | ||
node.debug('test-node just received a message'); | ||
try { | ||
msg.payload *= multiplyBy; | ||
node.send(msg); | ||
} catch (ex) { | ||
msg.error = 'Error: ' + ex; | ||
} | ||
}); | ||
} | ||
|
||
RED.nodes.registerType('test-node', TestNode); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* jshint esversion:8, node:true, strict:true */ | ||
"use strict"; | ||
/** | ||
* Command-line interface for the json-multi-schema Node-RED nodes. | ||
* | ||
* Script to run our Node-RED nodes from terminal without Node-RED and using STDIN / STDOUT. | ||
* | ||
*/ | ||
|
||
//Load fake/mocked Node-RED: | ||
//const RED = require('node-red-contrib-mock-cli'); //Use that in real projects | ||
const RED = require('./index.js'); //Only for this local test | ||
|
||
const noderedNode = RED.load(require.main); | ||
|
||
if (noderedNode) { | ||
noderedNode.on('debug', msg => console.warn('Caught event: ' + msg)); | ||
RED.run(); | ||
} else { | ||
console.error('Error loading Node-RED node!'); | ||
} |