From e299baf1a0d4a3e57a750a5fdf734f2a6e247bc1 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Thu, 24 Jul 2014 23:16:41 +0100 Subject: [PATCH] Refactor inner workings of registry.js --- red/nodes/registry.js | 353 ++++++++++++++++++++---------------------- 1 file changed, 169 insertions(+), 184 deletions(-) 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