From 846ab08661ba482bbf3d9a30bd1e93856f61df67 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Fri, 10 Jul 2015 21:42:14 +0100 Subject: [PATCH] Allow node modules to declare supported versions of node-red --- package.json | 1 + red/nodes/registry/loader.js | 40 +++++++++++++++------------ red/nodes/registry/localfilesystem.js | 30 ++++++++++++-------- red/red.js | 2 +- 4 files changed, 43 insertions(+), 30 deletions(-) diff --git a/package.json b/package.json index 85444960e..01688e081 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,7 @@ "passport-oauth2-client-password":"0.1.2", "oauth2orize":"1.0.1", "i18next":"1.7.10", + "semver": "4.3.6", "node-red-node-feedparser":"0.0.*", "node-red-node-email":"0.0.*", "node-red-node-twitter":"0.0.*" diff --git a/red/nodes/registry/loader.js b/red/nodes/registry/loader.js index 636f84e7e..5d6f84baf 100644 --- a/red/nodes/registry/loader.js +++ b/red/nodes/registry/loader.js @@ -17,6 +17,7 @@ var when = require("when"); var fs = require("fs"); var path = require("path"); +var semver = require("semver"); var events = require("../../events"); @@ -35,7 +36,7 @@ events.on("node-locales-dir", function(info) { function init(_settings) { settings = _settings; localfilesystem.init(settings); - + RED = require('../../red'); } @@ -45,7 +46,7 @@ function load(defaultNodesDir,disableNodePathScan) { // We should expose that as an option at some point, although the // performance gains are minimal. //return loadNodeFiles(registry.getModuleList()); - + var nodeFiles = localfilesystem.getNodeFiles(defaultNodesDir,disableNodePathScan); return loadNodeFiles(nodeFiles); } @@ -55,6 +56,11 @@ function loadNodeFiles(nodeFiles) { for (var module in nodeFiles) { /* istanbul ignore else */ if (nodeFiles.hasOwnProperty(module)) { + if (nodeFiles[module].redVersion && + !semver.satisfies(RED.version().replace("-git",""), nodeFiles[module].redVersion)) { + //TODO: log it + continue; + } if (module == "node-red" || !registry.getModuleInfo(module)) { var first = true; for (var node in nodeFiles[module].nodes) { @@ -72,7 +78,7 @@ function loadNodeFiles(nodeFiles) { } } var moduleFn = parts.slice(0,i+2).join("/"); - + try { var stat = fs.statSync(moduleFn); } catch(err) { @@ -80,7 +86,7 @@ function loadNodeFiles(nodeFiles) { break; } } - + try { promises.push(loadNodeConfig(nodeFiles[module].nodes[node])) } catch(err) { @@ -106,7 +112,7 @@ function loadNodeConfig(fileInfo) { var module = fileInfo.module; var name = fileInfo.name; var version = fileInfo.version; - + var id = module + "/" + name; var info = registry.getNodeInfo(id); var isEnabled = true; @@ -116,7 +122,7 @@ function loadNodeConfig(fileInfo) { } isEnabled = info.enabled; } - + var node = { id: id, module: module, @@ -130,7 +136,7 @@ function loadNodeConfig(fileInfo) { if (fileInfo.hasOwnProperty("types")) { node.types = fileInfo.types; } - + fs.readFile(node.template,'utf8', function(err,content) { if (err) { node.types = []; @@ -144,17 +150,17 @@ function loadNodeConfig(fileInfo) { node.err = err.toString(); } resolve(node); - } else { + } else { var types = []; - + var regExp = /