Better method for searching for config file

Project: http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/commit/3ac6d422
Tree: http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/tree/3ac6d422
Diff: http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/diff/3ac6d422

Branch: refs/heads/master
Commit: 3ac6d422330320190f291e28ef8076afc819db83
Parents: 3ae94f5
Author: brandon <[email protected]>
Authored: Wed Feb 17 14:35:47 2016 -0800
Committer: brandon <[email protected]>
Committed: Wed Feb 17 14:35:47 2016 -0800

----------------------------------------------------------------------
 helpers/config.js | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/3ac6d422/helpers/config.js
----------------------------------------------------------------------
diff --git a/helpers/config.js b/helpers/config.js
index 63efdaa..1de27e7 100644
--- a/helpers/config.js
+++ b/helpers/config.js
@@ -18,15 +18,21 @@ if (/mocha$/i.test(process.argv[1])) {
 } else {
     try {
         file.walkSync(appRoot, function(start, dirs, names) {
-            if (_.includes(dirs, "config") && _.includes(names, 
"usergrid.json")) {
-                module.exports = require(appRoot + '/config/usergrid.json')
-            } else if (_.includes(dirs, "usergrid") && _.includes(names, 
"config.json")) {
-                module.exports = require(appRoot + '/usergrid/config.json')
-            } else if (_.includes(names, "config.json")) {
-                module.exports = require(appRoot + '/config.json')
+            if (_.includes(names, "config.json") || _.includes(names, 
"usergrid.json")) {
+                var name = _.first(names.filter(function(name) {
+                    return name == "config.json" || name == "usergrid.json"
+                }).sort().reverse())
+                var configPath = util.format("%s/%s", start, name)
+                module.exports = require(configPath)
+                if (module.exports.orgId === undefined || module.exports.appId 
=== undefined) {
+                    console.log(util.format("Config file '%s' is not a valid 
Usergrid configuration file", configPath))
+                    module.exports = {}
+                } else {
+                    console.log(util.format("Using config file '%s'", 
configPath))
+                }
             }
         })
     } catch (e) {
-        
+
     }
 }
\ No newline at end of file

Reply via email to