mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
refactor(cloudcmd) readConfig: mv to bin
This commit is contained in:
parent
882252432d
commit
985c900b05
2 changed files with 44 additions and 32 deletions
|
|
@ -5,8 +5,13 @@
|
|||
|
||||
var Info = require('../package'),
|
||||
|
||||
fs = require('fs'),
|
||||
|
||||
DIR = '../lib/',
|
||||
|
||||
Util = require(DIR + 'util'),
|
||||
CloudFunc = require(DIR + 'cloudfunc'),
|
||||
|
||||
argv = process.argv,
|
||||
length = argv.length - 1,
|
||||
argvLast = argv[length];
|
||||
|
|
@ -41,7 +46,36 @@
|
|||
function start(params) {
|
||||
var cloudcmd = require('../cloudcmd');
|
||||
|
||||
cloudcmd.start(params);
|
||||
readConfig(function(config) {
|
||||
if (params && params.test)
|
||||
config.test = params.test;
|
||||
|
||||
cloudcmd.start(config);
|
||||
});
|
||||
}
|
||||
|
||||
function readConfig(callback) {
|
||||
var path = __dirname + '/../json/config.json';
|
||||
|
||||
Util.checkArgs(arguments, ['callback']);
|
||||
|
||||
fs.readFile(path, 'utf8', function(error, data) {
|
||||
var status, config, msg;
|
||||
|
||||
if (error) {
|
||||
status = 'error';
|
||||
Util.log(error.code);
|
||||
} else {
|
||||
status = 'ok';
|
||||
config = Util.parseJSON(data);
|
||||
}
|
||||
|
||||
msg = CloudFunc.formatMsg('read', 'config', status);
|
||||
|
||||
Util.log(msg);
|
||||
|
||||
callback(config);
|
||||
});
|
||||
}
|
||||
|
||||
})();
|
||||
|
|
|
|||
40
cloudcmd.js
40
cloudcmd.js
|
|
@ -9,7 +9,6 @@
|
|||
mellow = require(DIR_SERVER + 'mellow'),
|
||||
|
||||
HTMLDIR = main.HTMLDIR,
|
||||
JSONDIR = main.JSONDIR,
|
||||
|
||||
fs = main.fs,
|
||||
files = main.files,
|
||||
|
|
@ -25,8 +24,6 @@
|
|||
|
||||
win = require(DIR_SERVER + 'win'),
|
||||
|
||||
CONFIG_PATH = JSONDIR + 'config.json',
|
||||
|
||||
KEY = DIR + 'ssl/ssl.key',
|
||||
CERT = DIR + 'ssl/ssl.crt',
|
||||
|
||||
|
|
@ -48,10 +45,8 @@
|
|||
/* reinit main dir os if we on Win32 should be backslashes */
|
||||
DIR = main.DIR;
|
||||
|
||||
exports.start = function(params) {
|
||||
readConfig(function() {
|
||||
init(params);
|
||||
});
|
||||
exports.start = function(config) {
|
||||
init(config);
|
||||
|
||||
win.prepareCodePage();
|
||||
};
|
||||
|
|
@ -117,7 +112,7 @@
|
|||
}
|
||||
|
||||
|
||||
function init(params) {
|
||||
function init(config) {
|
||||
var paramsStart;
|
||||
|
||||
Util.log('server dir: ' + DIR);
|
||||
|
|
@ -125,8 +120,12 @@
|
|||
if (update)
|
||||
update.get();
|
||||
|
||||
if (params && params.test)
|
||||
Config.server = false;
|
||||
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' +
|
||||
|
|
@ -192,27 +191,6 @@
|
|||
});
|
||||
}
|
||||
|
||||
function readConfig(callback) {
|
||||
Util.checkArgs(arguments, ['callback']);
|
||||
|
||||
fs.readFile(CONFIG_PATH, 'utf8', function(error, data) {
|
||||
var status, json, msg;
|
||||
|
||||
if (error)
|
||||
status = 'error';
|
||||
else {
|
||||
status = 'ok';
|
||||
json = Util.parseJSON(data);
|
||||
main.config = Config = json;
|
||||
}
|
||||
|
||||
msg = CloudFunc.formatMsg('read', 'config', status);
|
||||
|
||||
Util.log(msg);
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* routing of server queries
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue