Created
February 4, 2012 06:31
-
-
Save mattkime/1735845 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| exports.load = function(configPath,onComplete){ | |
| var config = { | |
| ip : "10.254.2.93", | |
| port : 80 | |
| }; | |
| if(process.argv[2] !== "config" && pathUtil.existsSync(configPath)){ | |
| underscore.extend(exports,require(configPath)); | |
| onComplete(); | |
| return; | |
| } | |
| if(pathUtil.existsSync(configPath)){ | |
| config = require(configPath); | |
| } | |
| var stdin = rl.createInterface(process.stdin, process.stdout, null), | |
| varArray = ['ip','port']; | |
| async.forEachSeries(varArray,function(item,callback){ | |
| stdin.question(item + " [" + config[item] + "] : ",function(answer){ | |
| if(answer){ | |
| config[item] = answer; | |
| } | |
| callback(); | |
| }); | |
| },function(err){ | |
| var output = ""; | |
| stdin.close(); | |
| underscore.each(config,function(value,key,list){ | |
| output += "exports." + key + " = \"" + value + "\";\r" | |
| }) | |
| fs.writeFile(configPath, output, function(err) { | |
| util.log('configuration complete'); | |
| underscore.extend(exports,require(configPath)); | |
| onComplete(); | |
| }); | |
| }); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment