mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-19 09:24:51 +00:00
feature(config) add
This commit is contained in:
parent
7d93c9930c
commit
cd296f84be
5 changed files with 81 additions and 115 deletions
76
cloudcmd.js
76
cloudcmd.js
|
|
@ -5,84 +5,32 @@
|
|||
DIR_LIB = DIR + 'lib/',
|
||||
DIR_SERVER = DIR + 'lib/server/',
|
||||
|
||||
fs = require('fs'),
|
||||
|
||||
win = require(DIR_SERVER + 'win'),
|
||||
main = require(DIR_SERVER + 'main'),
|
||||
update = require(DIR_SERVER + 'update'),
|
||||
tryRequire = require(DIR_SERVER + 'tryRequire'),
|
||||
|
||||
Util = require(DIR_LIB + 'util'),
|
||||
server = require(DIR_LIB + 'server'),
|
||||
|
||||
Config = main.config;
|
||||
config = require(DIR_SERVER + 'config');
|
||||
|
||||
module.exports = function(params) {
|
||||
readConfig(function(error, config) {
|
||||
var keys;
|
||||
var keys;
|
||||
|
||||
if (params) {
|
||||
keys = Object.keys(params);
|
||||
|
||||
if (error)
|
||||
Util.log(error.message);
|
||||
|
||||
if (!config)
|
||||
config = {};
|
||||
|
||||
if (params) {
|
||||
keys = Object.keys(params);
|
||||
|
||||
keys.forEach(function(item) {
|
||||
config[item] = params[item];
|
||||
});
|
||||
}
|
||||
|
||||
init(config);
|
||||
});
|
||||
keys.forEach(function(name) {
|
||||
config(name, params[name]);
|
||||
});
|
||||
}
|
||||
|
||||
win.prepareCodePage();
|
||||
};
|
||||
|
||||
function init(config) {
|
||||
Util.log('server dir: ' + DIR);
|
||||
|
||||
if (update)
|
||||
update.get();
|
||||
|
||||
if (config) {
|
||||
main.config = Config = config;
|
||||
|
||||
if (config.test)
|
||||
Config.server = false;
|
||||
}
|
||||
|
||||
if (Config.logs) {
|
||||
Util.log('log param setted up in config.json\n' +
|
||||
'from now all logs will be writed to log.txt');
|
||||
|
||||
writeLogsToFile();
|
||||
}
|
||||
if (config('test'))
|
||||
config(server, false);
|
||||
|
||||
server();
|
||||
}
|
||||
|
||||
function readConfig(callback) {
|
||||
var error,
|
||||
configPath = DIR + 'json/config.json',
|
||||
config = tryRequire(configPath, function(err) {
|
||||
if (err)
|
||||
error = err;
|
||||
});
|
||||
|
||||
Util.checkArgs(arguments, ['callback']);
|
||||
|
||||
callback(error, config);
|
||||
}
|
||||
|
||||
/* function sets stdout to file log.txt */
|
||||
function writeLogsToFile() {
|
||||
var stdout = process.stdout,
|
||||
writeFile = fs.createWriteStream('log.txt'),
|
||||
write = writeFile.write.bind(writeFile);
|
||||
|
||||
stdout.write = write;
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue