diff --git a/red/nodes/registry.js b/red/nodes/registry.js index 978120a7c..305e89502 100644 --- a/red/nodes/registry.js +++ b/red/nodes/registry.js @@ -31,60 +31,122 @@ var node_types = {}; var node_configs = []; var node_scripts = []; -function loadTemplate(templateFilename) { - return when.promise(function(resolve,reject) { - whenNode.call(fs.readFile,templateFilename,'utf8').done(function(content) { - try { - registerConfig(content); - } catch(err) { - reject("invalid template file: "+err.message); +/** + * Synchronously walks the directory looking for node files. + * Emits 'node-icon-dir' events for an icon dirs found + * @param dir the directory to search + * @return an array of fully-qualified paths to .js files + */ +function getNodeFiles(dir) { + var result = []; + var files = fs.readdirSync(dir); + files.sort(); + files.forEach(function(fn) { + var stats = fs.statSync(path.join(dir,fn)); + if (stats.isFile()) { + if (/\.js$/.test(fn)) { + result.push(path.join(dir,fn)); } - resolve(); - }, function(err) { - reject("missing template file"); - }); - - }); -} - -// Return a promise that resolves to: -// success: {fn,path} -// failure: {fn.path,err} -function loadNode(nodeDir, nodeFn, nodeLabel) { - return when.promise(function(resolve,reject) { - if (settings.nodesExcludes) { - for (var i=0;i