feature(config) default path: ~/.cloudcmd.json

This commit is contained in:
coderaiser 2014-10-17 02:37:42 -04:00
parent 46f283fb4e
commit 1f7a41ced1
2 changed files with 38 additions and 43 deletions

View file

@ -5,14 +5,23 @@
DIR_LIB = DIR_SERVER + '../',
DIR = DIR_SERVER + '../../',
HOME_WIN = process.env.HOMEPATH,
HOME_UNIX = process.env.HOME,
HOME = (HOME_UNIX || HOME_WIN) + '/',
fs = require('fs'),
Util = require(DIR_LIB + 'util'),
tryRequire = require(DIR_SERVER + 'tryRequire'),
ConfigPath = DIR + 'json/config.json',
ConfigPath = DIR + 'json/config.json',
ConfigHome = HOME + '.cloudcmd.json',
config = tryRequire(ConfigPath, {log: true}) || {};
config =
tryRequire(ConfigHome) ||
tryRequire(ConfigPath, {log: true}) || {};
module.exports = function(key, value) {
var result;
@ -31,7 +40,7 @@
Util.checkArgs(arguments, ['callback']);
if (data)
fs.writeFile(ConfigPath, data, callback);
fs.writeFile(ConfigHome, data, callback);
else
callback({
message: 'Error: config is empty!'