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

Register node message catalog directly, not via event

This commit is contained in:
Nick O'Leary 2015-11-23 14:14:55 +00:00
parent 1dd9984521
commit 043b8a3105
3 changed files with 11 additions and 21 deletions

View File

@ -26,18 +26,10 @@ var RED;
var settings; var settings;
var runtime; var runtime;
function registerMessageCatalog(info) {
runtime.i18n.registerMessageCatalog(info.namespace,info.dir,info.file);
}
function init(_runtime) { function init(_runtime) {
runtime = _runtime; runtime = _runtime;
settings = runtime.settings; settings = runtime.settings;
localfilesystem.init(runtime); localfilesystem.init(runtime);
if (runtime.events) {
runtime.events.removeListener("node-locales-dir", registerMessageCatalog);
runtime.events.on("node-locales-dir", registerMessageCatalog);
}
RED = require('../../../red'); RED = require('../../../red');
} }

View File

@ -20,6 +20,7 @@ var path = require("path");
var events; var events;
var log; var log;
var i18n;
var settings; var settings;
var defaultNodesDir = path.resolve(path.join(__dirname,"..","..","..","..","nodes")); var defaultNodesDir = path.resolve(path.join(__dirname,"..","..","..","..","nodes"));
@ -29,6 +30,7 @@ function init(runtime,_defaultNodesDir,_disableNodePathScan) {
settings = runtime.settings; settings = runtime.settings;
events = runtime.events; events = runtime.events;
log = runtime.log; log = runtime.log;
i18n = runtime.i18n;
if (_disableNodePathScan) { if (_disableNodePathScan) {
disableNodePathScan = _disableNodePathScan; disableNodePathScan = _disableNodePathScan;
@ -204,11 +206,7 @@ function getNodeFiles(_defaultNodesDir,disableNodePathScan) {
//console.log(nodeFiles); //console.log(nodeFiles);
var defaultLocalesPath = path.resolve(path.join(defaultNodesDir,"core","locales")); var defaultLocalesPath = path.resolve(path.join(defaultNodesDir,"core","locales"));
events.emit("node-locales-dir", { i18n.registerMessageCatalog("node-red",defaultLocalesPath,"messages.json");
namespace:"node-red",
dir: defaultLocalesPath,
file: "messages.json"
});
if (settings.userDir) { if (settings.userDir) {
dir = path.join(settings.userDir,"nodes"); dir = path.join(settings.userDir,"nodes");

View File

@ -45,7 +45,7 @@ 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({events:{emit:function(){}},settings:{}}); localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{}});
var nodeList = localfilesystem.getNodeFiles(resourcesDir,true); var nodeList = localfilesystem.getNodeFiles(resourcesDir,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'];
@ -56,7 +56,7 @@ 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({events:{emit:function(){}},settings:{nodesExcludes:['TestNode1.js']}}); localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{nodesExcludes:['TestNode1.js']}});
var nodeList = localfilesystem.getNodeFiles(resourcesDir,true); var nodeList = localfilesystem.getNodeFiles(resourcesDir,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'];
@ -66,7 +66,7 @@ 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({events:{emit:function(){}},settings:{userDir:userDir}}); localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{userDir:userDir}});
var nodeList = localfilesystem.getNodeFiles(__dirname,true); var nodeList = localfilesystem.getNodeFiles(__dirname,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'];
@ -77,7 +77,7 @@ 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({events:{emit:function(){}},settings:{nodesDir:userDir}}); localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{nodesDir:userDir}});
var nodeList = localfilesystem.getNodeFiles(__dirname,true); var nodeList = localfilesystem.getNodeFiles(__dirname,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'];
@ -87,7 +87,7 @@ 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({events:{emit:function(){}},settings:{nodesDir:[userDir]}}); localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{nodesDir:[userDir]}});
var nodeList = localfilesystem.getNodeFiles(__dirname,true); var nodeList = localfilesystem.getNodeFiles(__dirname,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'];
@ -106,7 +106,7 @@ describe("red/nodes/registry/localfilesystem",function() {
} }
return _join.apply(null,arguments); return _join.apply(null,arguments);
})); }));
localfilesystem.init({events:{emit:function(){}},settings:{}}); localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{}});
var nodeList = localfilesystem.getNodeFiles(moduleDir,false); var nodeList = localfilesystem.getNodeFiles(moduleDir,false);
nodeList.should.have.a.property("node-red"); nodeList.should.have.a.property("node-red");
var nm = nodeList['node-red']; var nm = nodeList['node-red'];
@ -141,7 +141,7 @@ describe("red/nodes/registry/localfilesystem",function() {
} }
return _join.apply(null,arguments); return _join.apply(null,arguments);
})); }));
localfilesystem.init({events:{emit:function(){}},settings:{}},moduleDir,true); localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{}},moduleDir,true);
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({events:{emit:function(){}},settings:{}},moduleDir,true); localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{}},moduleDir,true);
/*jshint immed: false */ /*jshint immed: false */
(function(){ (function(){
localfilesystem.getModuleFiles('WontExistModule'); localfilesystem.getModuleFiles('WontExistModule');