mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Allow node modules to declare supported versions of node-red
This commit is contained in:
parent
999cf66b27
commit
846ab08661
@ -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.*"
|
||||
|
@ -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 = /<script ([^>]*)data-template-name=['"]([^'"]*)['"]/gi;
|
||||
var match = null;
|
||||
|
||||
|
||||
while((match = regExp.exec(content)) !== null) {
|
||||
types.push(match[2]);
|
||||
}
|
||||
node.types = types;
|
||||
|
||||
|
||||
var langRegExp = /^<script[^>]* data-lang=['"](.+?)['"]/i;
|
||||
regExp = /(<script[^>]* data-help-name=[\s\S]*?<\/script>)/gi;
|
||||
match = null;
|
||||
@ -165,7 +171,7 @@ function loadNodeConfig(fileInfo) {
|
||||
mainContent += content.substring(index,regExp.lastIndex-match[1].length);
|
||||
index = regExp.lastIndex;
|
||||
var help = content.substring(regExp.lastIndex-match[1].length,regExp.lastIndex);
|
||||
|
||||
|
||||
var lang = "en-US";
|
||||
if ((match = langRegExp.exec(help)) !== null) {
|
||||
lang = match[1];
|
||||
@ -173,7 +179,7 @@ function loadNodeConfig(fileInfo) {
|
||||
if (!helpContent.hasOwnProperty(lang)) {
|
||||
helpContent[lang] = "";
|
||||
}
|
||||
|
||||
|
||||
helpContent[lang] += help;
|
||||
}
|
||||
mainContent += content.substring(index);
|
||||
@ -215,9 +221,9 @@ function loadNodeConfig(fileInfo) {
|
||||
// credentials: RED.credentials,
|
||||
// events: RED.events,
|
||||
// log: RED.log,
|
||||
//
|
||||
//
|
||||
// }
|
||||
//
|
||||
//
|
||||
//}
|
||||
|
||||
|
||||
@ -240,7 +246,7 @@ function loadNodeSet(node) {
|
||||
var loadPromise = null;
|
||||
var r = require(node.file);
|
||||
if (typeof r === "function") {
|
||||
|
||||
|
||||
var red = {};
|
||||
for (var i in RED) {
|
||||
if (RED.hasOwnProperty(i) && !/^(init|start|stop)$/.test(i)) {
|
||||
@ -334,7 +340,7 @@ function addFile(file) {
|
||||
nodes: {}
|
||||
};
|
||||
fileObj[nodeFiles.module].nodes[nodeFiles.name] = nodeFiles;
|
||||
|
||||
|
||||
return loadNodeFiles(fileObj);
|
||||
} else {
|
||||
var e = new Error();
|
||||
|
@ -58,7 +58,7 @@ function getLocalFile(file) {
|
||||
};
|
||||
}
|
||||
return null;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -141,7 +141,7 @@ function scanTreeForNodesModules(moduleName) {
|
||||
userDir = path.join(settings.userDir,"node_modules");
|
||||
results = results.concat(scanDirForNodesModules(userDir,moduleName));
|
||||
}
|
||||
|
||||
|
||||
var up = path.resolve(path.join(dir,".."));
|
||||
while (up !== dir) {
|
||||
var pm = path.join(dir,"node_modules");
|
||||
@ -155,14 +155,14 @@ function scanTreeForNodesModules(moduleName) {
|
||||
}
|
||||
|
||||
function getModuleNodeFiles(module) {
|
||||
|
||||
|
||||
var moduleDir = module.dir;
|
||||
var pkg = module.package;
|
||||
|
||||
|
||||
var nodes = pkg['node-red'].nodes||{};
|
||||
var results = [];
|
||||
var iconDirs = [];
|
||||
|
||||
|
||||
for (var n in nodes) {
|
||||
/* istanbul ignore else */
|
||||
if (nodes.hasOwnProperty(n)) {
|
||||
@ -186,24 +186,24 @@ function getModuleNodeFiles(module) {
|
||||
}
|
||||
|
||||
function getNodeFiles(_defaultNodesDir,disableNodePathScan) {
|
||||
|
||||
|
||||
if (_defaultNodesDir) {
|
||||
defaultNodesDir = _defaultNodesDir;
|
||||
}
|
||||
|
||||
|
||||
var dir;
|
||||
// Find all of the nodes to load
|
||||
//console.log(defaultNodesDir);
|
||||
var nodeFiles = getLocalNodeFiles(path.resolve(defaultNodesDir));
|
||||
//console.log(nodeFiles);
|
||||
|
||||
|
||||
var defaultLocalesPath = path.resolve(path.join(defaultNodesDir,"core","locales"));
|
||||
events.emit("node-locales-dir", {
|
||||
namespace:"node-red",
|
||||
dir: defaultLocalesPath,
|
||||
file: "messages.json"
|
||||
});
|
||||
|
||||
|
||||
if (settings.userDir) {
|
||||
dir = path.join(settings.userDir,"nodes");
|
||||
nodeFiles = nodeFiles.concat(getLocalNodeFiles(dir));
|
||||
@ -217,7 +217,7 @@ function getNodeFiles(_defaultNodesDir,disableNodePathScan) {
|
||||
nodeFiles = nodeFiles.concat(getLocalNodeFiles(dir[i]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var nodeList = {
|
||||
"node-red": {
|
||||
name: "node-red",
|
||||
@ -228,7 +228,7 @@ function getNodeFiles(_defaultNodesDir,disableNodePathScan) {
|
||||
nodeFiles.forEach(function(node) {
|
||||
nodeList["node-red"].nodes[node.name] = node;
|
||||
});
|
||||
|
||||
|
||||
if (!disableNodePathScan) {
|
||||
var moduleFiles = scanTreeForNodesModules();
|
||||
moduleFiles.forEach(function(moduleFile) {
|
||||
@ -238,6 +238,9 @@ function getNodeFiles(_defaultNodesDir,disableNodePathScan) {
|
||||
version: moduleFile.package.version,
|
||||
nodes: {}
|
||||
};
|
||||
if (moduleFile.package['node-red'].version) {
|
||||
nodeList[moduleFile.package.name].redVersion = moduleFile.package['node-red'].version;
|
||||
}
|
||||
nodeModuleFiles.forEach(function(node) {
|
||||
nodeList[moduleFile.package.name].nodes[node.name] = node;
|
||||
});
|
||||
@ -249,7 +252,7 @@ function getNodeFiles(_defaultNodesDir,disableNodePathScan) {
|
||||
|
||||
function getModuleFiles(module) {
|
||||
var nodeList = {};
|
||||
|
||||
|
||||
var moduleFiles = scanTreeForNodesModules(module);
|
||||
if (moduleFiles.length === 0) {
|
||||
var err = new Error(log._("nodes.registry.localfilesystem.module-not-found", {module:module}));
|
||||
@ -264,6 +267,9 @@ function getModuleFiles(module) {
|
||||
version: moduleFile.package.version,
|
||||
nodes: {}
|
||||
};
|
||||
if (moduleFile.package['node-red'].version) {
|
||||
nodeList[moduleFile.package.name].redVersion = moduleFile.package['node-red'].version;
|
||||
}
|
||||
nodeModuleFiles.forEach(function(node) {
|
||||
nodeList[moduleFile.package.name].nodes[node.name] = node;
|
||||
});
|
||||
|
@ -67,7 +67,7 @@ var RED = {
|
||||
var p = require(path.join(process.env.NODE_RED_HOME,"package.json")).version;
|
||||
/* istanbul ignore else */
|
||||
if (fs.existsSync(path.join(process.env.NODE_RED_HOME,".git"))) {
|
||||
p += ".git";
|
||||
p += "-git";
|
||||
}
|
||||
return p;
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user