mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Allow core nodes dir to be provided to runtime via settings
This commit is contained in:
parent
4a91c27e4b
commit
05b58e9263
@ -44,11 +44,15 @@ module.exports = {
|
|||||||
userSettings = httpServer;
|
userSettings = httpServer;
|
||||||
httpServer = null;
|
httpServer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!userSettings.SKIP_BUILD_CHECK) {
|
if (!userSettings.SKIP_BUILD_CHECK) {
|
||||||
checkBuild();
|
checkBuild();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!userSettings.coreNodesDir) {
|
||||||
|
userSettings.coreNodesDir = path.resolve(path.join(__dirname,"..","nodes"));
|
||||||
|
}
|
||||||
|
|
||||||
if (userSettings.httpAdminRoot !== false || userSettings.httpNodeRoot !== false) {
|
if (userSettings.httpAdminRoot !== false || userSettings.httpNodeRoot !== false) {
|
||||||
runtime.init(userSettings,api);
|
runtime.init(userSettings,api);
|
||||||
api.init(httpServer,runtime);
|
api.init(httpServer,runtime);
|
||||||
|
@ -23,21 +23,13 @@ var log;
|
|||||||
var i18n;
|
var i18n;
|
||||||
|
|
||||||
var settings;
|
var settings;
|
||||||
var defaultNodesDir = path.resolve(path.join(__dirname,"..","..","..","..","nodes"));
|
|
||||||
var disableNodePathScan = false;
|
var disableNodePathScan = false;
|
||||||
|
|
||||||
function init(runtime,_defaultNodesDir,_disableNodePathScan) {
|
function init(runtime) {
|
||||||
settings = runtime.settings;
|
settings = runtime.settings;
|
||||||
events = runtime.events;
|
events = runtime.events;
|
||||||
log = runtime.log;
|
log = runtime.log;
|
||||||
i18n = runtime.i18n;
|
i18n = runtime.i18n;
|
||||||
|
|
||||||
if (_disableNodePathScan) {
|
|
||||||
disableNodePathScan = _disableNodePathScan;
|
|
||||||
}
|
|
||||||
if (_defaultNodesDir) {
|
|
||||||
defaultNodesDir = path.resolve(_defaultNodesDir);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function isExcluded(name) {
|
function isExcluded(name) {
|
||||||
@ -139,7 +131,7 @@ function scanDirForNodesModules(dir,moduleName) {
|
|||||||
* @return a list of node modules: {dir,package}
|
* @return a list of node modules: {dir,package}
|
||||||
*/
|
*/
|
||||||
function scanTreeForNodesModules(moduleName) {
|
function scanTreeForNodesModules(moduleName) {
|
||||||
var dir = defaultNodesDir;
|
var dir = settings.coreNodesDir;
|
||||||
var results = [];
|
var results = [];
|
||||||
var userDir;
|
var userDir;
|
||||||
|
|
||||||
@ -193,19 +185,13 @@ function getModuleNodeFiles(module) {
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getNodeFiles(_defaultNodesDir,disableNodePathScan) {
|
function getNodeFiles(disableNodePathScan) {
|
||||||
|
|
||||||
if (_defaultNodesDir) {
|
|
||||||
defaultNodesDir = _defaultNodesDir;
|
|
||||||
}
|
|
||||||
|
|
||||||
var dir;
|
var dir;
|
||||||
// Find all of the nodes to load
|
// Find all of the nodes to load
|
||||||
//console.log(defaultNodesDir);
|
var nodeFiles = getLocalNodeFiles(path.resolve(settings.coreNodesDir));
|
||||||
var nodeFiles = getLocalNodeFiles(path.resolve(defaultNodesDir));
|
|
||||||
//console.log(nodeFiles);
|
//console.log(nodeFiles);
|
||||||
|
|
||||||
var defaultLocalesPath = path.resolve(path.join(defaultNodesDir,"core","locales"));
|
var defaultLocalesPath = path.resolve(path.join(settings.coreNodesDir,"core","locales"));
|
||||||
i18n.registerMessageCatalog("node-red",defaultLocalesPath,"messages.json");
|
i18n.registerMessageCatalog("node-red",defaultLocalesPath,"messages.json");
|
||||||
|
|
||||||
if (settings.userDir) {
|
if (settings.userDir) {
|
||||||
@ -250,6 +236,8 @@ function getNodeFiles(_defaultNodesDir,disableNodePathScan) {
|
|||||||
});
|
});
|
||||||
nodeFiles = nodeFiles.concat(nodeModuleFiles);
|
nodeFiles = nodeFiles.concat(nodeModuleFiles);
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
console.log("node path scan disabled");
|
||||||
}
|
}
|
||||||
return nodeList;
|
return nodeList;
|
||||||
}
|
}
|
||||||
|
@ -45,8 +45,8 @@ describe("red/nodes/registry/localfilesystem",function() {
|
|||||||
}
|
}
|
||||||
describe("#getNodeFiles",function() {
|
describe("#getNodeFiles",function() {
|
||||||
it("Finds all the node files in the resources tree",function(done) {
|
it("Finds all the node files in the resources tree",function(done) {
|
||||||
localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{}});
|
localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{coreNodesDir:resourcesDir}});
|
||||||
var nodeList = localfilesystem.getNodeFiles(resourcesDir,true);
|
var nodeList = localfilesystem.getNodeFiles(true);
|
||||||
nodeList.should.have.a.property("node-red");
|
nodeList.should.have.a.property("node-red");
|
||||||
var nm = nodeList['node-red'];
|
var nm = nodeList['node-red'];
|
||||||
nm.should.have.a.property('name','node-red');
|
nm.should.have.a.property('name','node-red');
|
||||||
@ -56,8 +56,8 @@ describe("red/nodes/registry/localfilesystem",function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
it("Excludes node files from settings",function(done) {
|
it("Excludes node files from settings",function(done) {
|
||||||
localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{nodesExcludes:['TestNode1.js']}});
|
localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{nodesExcludes:['TestNode1.js'],coreNodesDir:resourcesDir}});
|
||||||
var nodeList = localfilesystem.getNodeFiles(resourcesDir,true);
|
var nodeList = localfilesystem.getNodeFiles(true);
|
||||||
nodeList.should.have.a.property("node-red");
|
nodeList.should.have.a.property("node-red");
|
||||||
var nm = nodeList['node-red'];
|
var nm = nodeList['node-red'];
|
||||||
nm.should.have.a.property('name','node-red');
|
nm.should.have.a.property('name','node-red');
|
||||||
@ -66,8 +66,8 @@ describe("red/nodes/registry/localfilesystem",function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
it("Finds nodes in userDir/nodes",function(done) {
|
it("Finds nodes in userDir/nodes",function(done) {
|
||||||
localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{userDir:userDir}});
|
localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{userDir:userDir,coreNodesDir:__dirname}});
|
||||||
var nodeList = localfilesystem.getNodeFiles(__dirname,true);
|
var nodeList = localfilesystem.getNodeFiles(true);
|
||||||
nodeList.should.have.a.property("node-red");
|
nodeList.should.have.a.property("node-red");
|
||||||
var nm = nodeList['node-red'];
|
var nm = nodeList['node-red'];
|
||||||
nm.should.have.a.property('name','node-red');
|
nm.should.have.a.property('name','node-red');
|
||||||
@ -77,8 +77,8 @@ describe("red/nodes/registry/localfilesystem",function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("Finds nodes in settings.nodesDir (string)",function(done) {
|
it("Finds nodes in settings.nodesDir (string)",function(done) {
|
||||||
localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{nodesDir:userDir}});
|
localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{nodesDir:userDir,coreNodesDir:__dirname}});
|
||||||
var nodeList = localfilesystem.getNodeFiles(__dirname,true);
|
var nodeList = localfilesystem.getNodeFiles(true);
|
||||||
nodeList.should.have.a.property("node-red");
|
nodeList.should.have.a.property("node-red");
|
||||||
var nm = nodeList['node-red'];
|
var nm = nodeList['node-red'];
|
||||||
nm.should.have.a.property('name','node-red');
|
nm.should.have.a.property('name','node-red');
|
||||||
@ -87,8 +87,8 @@ describe("red/nodes/registry/localfilesystem",function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
it("Finds nodes in settings.nodesDir (array)",function(done) {
|
it("Finds nodes in settings.nodesDir (array)",function(done) {
|
||||||
localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{nodesDir:[userDir]}});
|
localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{nodesDir:[userDir],coreNodesDir:__dirname}});
|
||||||
var nodeList = localfilesystem.getNodeFiles(__dirname,true);
|
var nodeList = localfilesystem.getNodeFiles(true);
|
||||||
nodeList.should.have.a.property("node-red");
|
nodeList.should.have.a.property("node-red");
|
||||||
var nm = nodeList['node-red'];
|
var nm = nodeList['node-red'];
|
||||||
nm.should.have.a.property('name','node-red');
|
nm.should.have.a.property('name','node-red');
|
||||||
@ -106,8 +106,8 @@ describe("red/nodes/registry/localfilesystem",function() {
|
|||||||
}
|
}
|
||||||
return _join.apply(null,arguments);
|
return _join.apply(null,arguments);
|
||||||
}));
|
}));
|
||||||
localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{}});
|
localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{coreNodesDir:moduleDir}});
|
||||||
var nodeList = localfilesystem.getNodeFiles(moduleDir,false);
|
var nodeList = localfilesystem.getNodeFiles();
|
||||||
nodeList.should.have.a.property("node-red");
|
nodeList.should.have.a.property("node-red");
|
||||||
var nm = nodeList['node-red'];
|
var nm = nodeList['node-red'];
|
||||||
nm.should.have.a.property('name','node-red');
|
nm.should.have.a.property('name','node-red');
|
||||||
@ -141,7 +141,7 @@ describe("red/nodes/registry/localfilesystem",function() {
|
|||||||
}
|
}
|
||||||
return _join.apply(null,arguments);
|
return _join.apply(null,arguments);
|
||||||
}));
|
}));
|
||||||
localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{}},moduleDir,true);
|
localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{coreNodesDir:moduleDir}});
|
||||||
var nodeModule = localfilesystem.getModuleFiles('TestNodeModule');
|
var nodeModule = localfilesystem.getModuleFiles('TestNodeModule');
|
||||||
nodeModule.should.have.a.property('TestNodeModule');
|
nodeModule.should.have.a.property('TestNodeModule');
|
||||||
nodeModule['TestNodeModule'].should.have.a.property('name','TestNodeModule');
|
nodeModule['TestNodeModule'].should.have.a.property('name','TestNodeModule');
|
||||||
@ -165,7 +165,7 @@ describe("red/nodes/registry/localfilesystem",function() {
|
|||||||
}
|
}
|
||||||
return _join.apply(null,arguments);
|
return _join.apply(null,arguments);
|
||||||
}));
|
}));
|
||||||
localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{}},moduleDir,true);
|
localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{coreNodesDir:moduleDir}});
|
||||||
/*jshint immed: false */
|
/*jshint immed: false */
|
||||||
(function(){
|
(function(){
|
||||||
localfilesystem.getModuleFiles('WontExistModule');
|
localfilesystem.getModuleFiles('WontExistModule');
|
||||||
|
Loading…
Reference in New Issue
Block a user