mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Change node config load to be async
This commit is contained in:
parent
9dd7e2e43d
commit
2fe9c1e55f
@ -36,7 +36,7 @@ function load(defaultNodesDir,disableNodePathScan) {
|
||||
}
|
||||
|
||||
function loadNodeFiles(nodeFiles) {
|
||||
var nodes = [];
|
||||
var promises = [];
|
||||
for (var module in nodeFiles) {
|
||||
/* istanbul ignore else */
|
||||
if (nodeFiles.hasOwnProperty(module)) {
|
||||
@ -45,7 +45,7 @@ function loadNodeFiles(nodeFiles) {
|
||||
/* istanbul ignore else */
|
||||
if (nodeFiles[module].nodes.hasOwnProperty(node)) {
|
||||
try {
|
||||
nodes.push(loadNodeConfig(nodeFiles[module].nodes[node]))
|
||||
promises.push(loadNodeConfig(nodeFiles[module].nodes[node]))
|
||||
} catch(err) {
|
||||
//
|
||||
}
|
||||
@ -54,10 +54,14 @@ function loadNodeFiles(nodeFiles) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return when.settle(promises).then(function(results) {
|
||||
var nodes = results.map(function(r) { return r.value; });
|
||||
return loadNodeSetList(nodes);
|
||||
});
|
||||
}
|
||||
|
||||
function loadNodeConfig(fileInfo) {
|
||||
return when.promise(function(resolve) {
|
||||
var file = fileInfo.file;
|
||||
var module = fileInfo.module;
|
||||
var name = fileInfo.name;
|
||||
@ -83,9 +87,15 @@ function loadNodeConfig(fileInfo) {
|
||||
loaded:false
|
||||
};
|
||||
|
||||
try {
|
||||
var content = fs.readFileSync(node.template,'utf8');
|
||||
|
||||
fs.readFile(node.template,'utf8', function(err,content) {
|
||||
if (err) {
|
||||
node.types = [];
|
||||
if (err.code === 'ENOENT') {
|
||||
node.err = "Error: "+file+" does not exist";
|
||||
} else {
|
||||
node.err = err.toString();
|
||||
}
|
||||
} else {
|
||||
var types = [];
|
||||
|
||||
var regExp = /<script ([^>]*)data-template-name=['"]([^'"]*)['"]/gi;
|
||||
@ -105,17 +115,11 @@ function loadNodeConfig(fileInfo) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch(err) {
|
||||
node.types = [];
|
||||
if (err.code === 'ENOENT') {
|
||||
node.err = "Error: "+file+" does not exist";
|
||||
} else {
|
||||
node.err = err.toString();
|
||||
}
|
||||
}
|
||||
|
||||
registry.addNodeSet(id,node,version);
|
||||
return node;
|
||||
resolve(node);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user