1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Migrate to new node function style

This commit is contained in:
Nick O'Leary 2014-05-03 23:32:04 +01:00
parent 5afc5857c4
commit ff49d2b217
37 changed files with 3194 additions and 3170 deletions

View File

@ -17,7 +17,7 @@
<!-- Sample html file that corresponds to the 99-sample.js file --> <!-- Sample html file that corresponds to the 99-sample.js file -->
<!-- This creates and configures the onscreen elements of the node --> <!-- This creates and configures the onscreen elements of the node -->
<!-- If you use this as a template, replace IBM Corp. with your own name. --> <!-- If you use this as a template, update the copyright with your own name. -->
<!-- First, the content of the edit dialog is defined. --> <!-- First, the content of the edit dialog is defined. -->

View File

@ -14,12 +14,12 @@
* limitations under the License. * limitations under the License.
**/ **/
// If you use this as a template, replace IBM Corp. with your own name. // If you use this as a template, update the copyright with your own name.
// Sample Node-RED node file // Sample Node-RED node file
// Require main module
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.export = function(RED) {
// The main node definition - most things happen in here // The main node definition - most things happen in here
function SampleNode(n) { function SampleNode(n) {
@ -50,3 +50,5 @@ function SampleNode(n) {
// Register the node by name. This must be called before overriding any of the // Register the node by name. This must be called before overriding any of the
// Node functions. // Node functions.
RED.nodes.registerType("sample",SampleNode); RED.nodes.registerType("sample",SampleNode);
}

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var sentiment = require('sentiment'); var sentiment = require('sentiment');
function SentimentNode(n) { function SentimentNode(n) {
@ -29,3 +29,4 @@ function SentimentNode(n) {
}); });
} }
RED.nodes.registerType("sentiment",SentimentNode); RED.nodes.registerType("sentiment",SentimentNode);
}

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var util = require("util"); var util = require("util");
var parseString = require('xml2js').parseString; var parseString = require('xml2js').parseString;
var useColors = true; var useColors = true;
@ -42,3 +42,4 @@ function Xml2jsNode(n) {
}); });
} }
RED.nodes.registerType("xml2js",Xml2jsNode); RED.nodes.registerType("xml2js",Xml2jsNode);
}

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var js2xmlparser = require("js2xmlparser"); var js2xmlparser = require("js2xmlparser");
function Js2XmlNode(n) { function Js2XmlNode(n) {
@ -34,3 +34,4 @@ function Js2XmlNode(n) {
}); });
} }
RED.nodes.registerType("json2xml",Js2XmlNode); RED.nodes.registerType("json2xml",Js2XmlNode);
}

View File

@ -1,5 +1,5 @@
/** /**
* Copyright 2013 IBM Corp. * Copyright 2013, 2014 IBM Corp.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -14,12 +14,8 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
try {
var cron = require("cron"); var cron = require("cron");
} catch(err) {
require("util").log("[inject] Warning: cannot find module 'cron'");
}
function InjectNode(n) { function InjectNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
@ -98,3 +94,4 @@ RED.httpAdmin.post("/inject/:id", function(req,res) {
res.send(404); res.send(404);
} }
}); });
}

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var util = require("util"); var util = require("util");
var ws = require("ws"); var ws = require("ws");
var events = require("events"); var events = require("events");
@ -168,3 +168,4 @@ RED.httpAdmin.post("/debug/:id/:state", function(req,res) {
res.send(404); res.send(404);
} }
}); });
}

View File

@ -14,8 +14,7 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var spawn = require('child_process').spawn; var spawn = require('child_process').spawn;
var exec = require('child_process').exec; var exec = require('child_process').exec;
@ -79,3 +78,4 @@ function ExecNode(n) {
} }
RED.nodes.registerType("exec",ExecNode); RED.nodes.registerType("exec",ExecNode);
}

View File

@ -14,8 +14,7 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var util = require("util"); var util = require("util");
var vm = require("vm"); var vm = require("vm");
var fs = require('fs'); var fs = require('fs');
@ -69,3 +68,4 @@ function FunctionNode(n) {
RED.nodes.registerType("function",FunctionNode); RED.nodes.registerType("function",FunctionNode);
RED.library.register("functions"); RED.library.register("functions");
}

View File

@ -14,8 +14,7 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var mustache = require("mustache"); var mustache = require("mustache");
var util = require("util"); var util = require("util");
var fs = require('fs'); var fs = require('fs');
@ -39,3 +38,4 @@ function TemplateNode(n) {
RED.nodes.registerType("template",TemplateNode); RED.nodes.registerType("template",TemplateNode);
RED.library.register("templates"); RED.library.register("templates");
}

View File

@ -15,8 +15,7 @@
**/ **/
//Simple node to introduce a pause into a flow //Simple node to introduce a pause into a flow
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
function random(n) { function random(n) {
var wait = n.randomFirst + (n.diff * Math.random()); var wait = n.randomFirst + (n.diff * Math.random());
if (n.buffer.length > 0) { if (n.buffer.length > 0) {
@ -152,3 +151,4 @@ function DelayNode(n) {
} }
} }
RED.nodes.registerType("delay",DelayNode); RED.nodes.registerType("delay",DelayNode);
}

View File

@ -14,10 +14,10 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
function CommentNode(n) { function CommentNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
} }
RED.nodes.registerType("comment",CommentNode); RED.nodes.registerType("comment",CommentNode);
}

View File

@ -14,9 +14,9 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
function UnknownNode(n) { function UnknownNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
} }
RED.nodes.registerType("unknown",UnknownNode); RED.nodes.registerType("unknown",UnknownNode);
}

View File

@ -14,7 +14,8 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var util = require("util"); var util = require("util");
var firmata = require("firmata"); var firmata = require("firmata");
var arduinoReady = false; var arduinoReady = false;
@ -185,3 +186,4 @@ function DuinoNodeOut(n) {
} }
} }
RED.nodes.registerType("arduino out",DuinoNodeOut); RED.nodes.registerType("arduino out",DuinoNodeOut);
}

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var util = require("util"); var util = require("util");
var exec = require('child_process').exec; var exec = require('child_process').exec;
var fs = require('fs'); var fs = require('fs');
@ -156,3 +156,4 @@ exec("gpio mode 0 in",function(err,stdout,stderr) {
RED.nodes.registerType("rpi-gpio in",GPIOInNode); RED.nodes.registerType("rpi-gpio in",GPIOInNode);
RED.nodes.registerType("rpi-gpio out",GPIOOutNode); RED.nodes.registerType("rpi-gpio out",GPIOOutNode);
}

View File

@ -14,7 +14,8 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var connectionPool = require("./lib/mqttConnectionPool"); var connectionPool = require("./lib/mqttConnectionPool");
var util = require("util"); var util = require("util");
@ -132,4 +133,5 @@ MQTTOutNode.prototype.close = function() {
this.client.disconnect(); this.client.disconnect();
} }
} }
}

View File

@ -14,7 +14,8 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var util = require("util"); var util = require("util");
var http = require("follow-redirects").http; var http = require("follow-redirects").http;
var https = require("follow-redirects").https; var https = require("follow-redirects").https;
@ -243,3 +244,4 @@ RED.httpAdmin.post('/http-request/:id',function(req,res) {
res.send(200); res.send(200);
}); });
}); });
}

View File

@ -14,9 +14,9 @@
* limitations under the License. * limitations under the License.
**/ **/
// Require main module module.exports = function(RED) {
var RED = require(process.env.NODE_RED_HOME+"/red/red"),
ws = require("ws"), var ws = require("ws"),
inspect = require("sys").inspect; inspect = require("sys").inspect;
// A node red node that sets up a local websocket server // A node red node that sets up a local websocket server
@ -170,3 +170,4 @@ function WebSocketOutNode(n) {
}); });
} }
RED.nodes.registerType("websocket out",WebSocketOutNode); RED.nodes.registerType("websocket out",WebSocketOutNode);
}

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var notify = require("fs.notify"); var notify = require("fs.notify");
var fs = require("fs"); var fs = require("fs");
var sep = require("path").sep; var sep = require("path").sep;
@ -40,3 +40,4 @@ function WatchNode(n) {
} }
} }
RED.nodes.registerType("watch",WatchNode); RED.nodes.registerType("watch",WatchNode);
}

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var settings = RED.settings; var settings = RED.settings;
var events = require("events"); var events = require("events");
var util = require("util"); var util = require("util");
@ -210,3 +210,4 @@ RED.httpAdmin.get("/serialports",function(req,res) {
res.end(); res.end();
}); });
}); });
}

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var reconnectTime = RED.settings.socketReconnectTime||10000; var reconnectTime = RED.settings.socketReconnectTime||10000;
var socketTimeout = RED.settings.socketTimeout||null; var socketTimeout = RED.settings.socketTimeout||null;
var net = require('net'); var net = require('net');
@ -304,3 +304,4 @@ function TcpOut(n) {
} }
RED.nodes.registerType("tcp out",TcpOut); RED.nodes.registerType("tcp out",TcpOut);
}

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var dgram = require('dgram'); var dgram = require('dgram');
// The Input Node // The Input Node
@ -166,3 +166,4 @@ function UDPout(n) {
}); });
} }
RED.nodes.registerType("udp out",UDPout); RED.nodes.registerType("udp out",UDPout);
}

View File

@ -14,8 +14,7 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME + "/red/red"); module.exports = function(RED) {
var operators = { var operators = {
'eq': function(a, b) { return a == b; }, 'eq': function(a, b) { return a == b; },
'neq': function(a, b) { return a != b; }, 'neq': function(a, b) { return a != b; },
@ -71,3 +70,4 @@ function SwitchNode(n) {
}); });
} }
RED.nodes.registerType("switch", SwitchNode); RED.nodes.registerType("switch", SwitchNode);
}

View File

@ -14,8 +14,7 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME + "/red/red"); module.exports = function(RED) {
function ChangeNode(n) { function ChangeNode(n) {
RED.nodes.createNode(this, n); RED.nodes.createNode(this, n);
this.action = n.action; this.action = n.action;
@ -71,3 +70,4 @@ function ChangeNode(n) {
}); });
} }
RED.nodes.registerType("change", ChangeNode); RED.nodes.registerType("change", ChangeNode);
}

View File

@ -14,8 +14,7 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME + "/red/red"); module.exports = function(RED) {
function RangeNode(n) { function RangeNode(n) {
RED.nodes.createNode(this, n); RED.nodes.createNode(this, n);
this.action = n.action; this.action = n.action;
@ -45,3 +44,4 @@ function RangeNode(n) {
}); });
} }
RED.nodes.registerType("range", RangeNode); RED.nodes.registerType("range", RangeNode);
}

View File

@ -14,8 +14,7 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
function CSVNode(n) { function CSVNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.template = n.temp.split(","); this.template = n.temp.split(",");
@ -76,3 +75,4 @@ function CSVNode(n) {
}); });
} }
RED.nodes.registerType("csv",CSVNode); RED.nodes.registerType("csv",CSVNode);
}

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var util = require("util"); var util = require("util");
function JSONNode(n) { function JSONNode(n) {
@ -42,3 +42,4 @@ function JSONNode(n) {
}); });
} }
RED.nodes.registerType("json",JSONNode); RED.nodes.registerType("json",JSONNode);
}

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var xml2js = require('xml2js'); var xml2js = require('xml2js');
var parseString = xml2js.parseString; var parseString = xml2js.parseString;
var builder = new xml2js.Builder({renderOpts:{pretty:false}}); var builder = new xml2js.Builder({renderOpts:{pretty:false}});
@ -48,3 +48,4 @@ function XMLNode(n) {
}); });
} }
RED.nodes.registerType("xml",XMLNode); RED.nodes.registerType("xml",XMLNode);
}

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var ntwitter = require('twitter-ng'); var ntwitter = require('twitter-ng');
var OAuth= require('oauth').OAuth; var OAuth= require('oauth').OAuth;
@ -320,3 +320,4 @@ RED.httpAdmin.get('/twitter/:id/auth/callback', function(req, res, next){
} }
); );
}); });
}

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var FeedParser = require("feedparser"); var FeedParser = require("feedparser");
var request = require("request"); var request = require("request");
@ -67,5 +67,5 @@ FeedParseNode.prototype.close = function() {
clearInterval(this.interval_id); clearInterval(this.interval_id);
} }
} }
}

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var util = require('util'); var util = require('util');
var nodemailer = require("nodemailer"); var nodemailer = require("nodemailer");
var Imap = null; var Imap = null;
@ -258,3 +258,4 @@ RED.httpAdmin.post('/email/:id',function(req,res) {
res.send(200); res.send(200);
}); });
}); });
}

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var irc = require("irc"); var irc = require("irc");
var util = require("util"); var util = require("util");
@ -138,3 +138,4 @@ function IrcOutNode(n) {
}); });
} }
RED.nodes.registerType("irc out",IrcOutNode); RED.nodes.registerType("irc out",IrcOutNode);
}

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var fs = require("fs"); var fs = require("fs");
var spawn = require('child_process').spawn; var spawn = require('child_process').spawn;
@ -54,3 +54,4 @@ function TailNode(n) {
} }
RED.nodes.registerType("tail",TailNode); RED.nodes.registerType("tail",TailNode);
}

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var fs = require("fs"); var fs = require("fs");
function FileNode(n) { function FileNode(n) {
@ -88,3 +88,4 @@ function FileInNode(n) {
}); });
} }
RED.nodes.registerType("file in",FileInNode); RED.nodes.registerType("file in",FileInNode);
}

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var util = require("util"); var util = require("util");
var redis = require("redis"); var redis = require("redis");
@ -93,4 +93,5 @@ RED.nodes.registerType("redis out",RedisOutNode);
RedisOutNode.prototype.close = function() { RedisOutNode.prototype.close = function() {
redisConnectionPool.close(this.client); redisConnectionPool.close(this.client);
} }
}

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var mongo = require('mongodb'); var mongo = require('mongodb');
var MongoClient = mongo.MongoClient; var MongoClient = mongo.MongoClient;
@ -176,3 +176,4 @@ function MongoInNode(n) {
}); });
} }
RED.nodes.registerType("mongodb in",MongoInNode); RED.nodes.registerType("mongodb in",MongoInNode);
}

View File

@ -54,7 +54,7 @@ function loadNode(nodeDir, nodeFn) {
var r = require(nodeFilename); var r = require(nodeFilename);
if (typeof r === "function") { if (typeof r === "function") {
try { try {
var promise = r(RED); var promise = r(require('../red'));
if (promise != null && typeof promise.then === "function") { if (promise != null && typeof promise.then === "function") {
promise.then(function() { promise.then(function() {
resolve(loadTemplate(templateFilename)); resolve(loadTemplate(templateFilename));