Skip to content

Instantly share code, notes, and snippets.

@mattkime
Created February 4, 2012 06:31
Show Gist options
  • Select an option

  • Save mattkime/1735845 to your computer and use it in GitHub Desktop.

Select an option

Save mattkime/1735845 to your computer and use it in GitHub Desktop.
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