-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.js
84 lines (69 loc) · 1.53 KB
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
* Config
* A wrapper for the configurations
*
* @author Mohammad Fares <[email protected]>
*/
var fs = require('fs-extra')
, yaml = require('js-yaml');
/**
* The path of the config file
* @type {String}
*/
var CONFIG_FILE_NAME = __dirname + '/config.yml';
/**
* The path of the default config file
* @type {String}
*/
var DEFAULT_CONFIG_FILE_NAME = __dirname + '/config.default.yml';
/**
* The content of the config file in YAML
* @type {String}
*/
var configContent = null;
/**
* To store the configurations
* @type {Object}
*/
var config = null;
// The config file is not exist
if (!fs.existsSync(CONFIG_FILE_NAME)) {
// Copy the default config file
fs.copySync(DEFAULT_CONFIG_FILE_NAME, CONFIG_FILE_NAME);
}
// Read the config file
configContent = fs.readFileSync(CONFIG_FILE_NAME, 'utf8');
// Parse the config file into an object
config = yaml.load(configContent);
/**
* Get username and password formatted Basic Auth
*
* @return {String} base64(username:password)
*/
module.exports.getAuthString = function() {
return new Buffer(config.account.username + ':' + config.account.password).toString('base64');
};
/**
* Get all the added project
*
* @return {Array}
*/
module.exports.getProjects = function() {
return config.projects;
};
/**
* Get server's base url
*
* @return {Object}
*/
module.exports.getBaseURL = function() {
return config.account.base_url;
};
/**
* Get the the config file's content
*
* @return {Object}
*/
module.exports.getContent = function() {
return configContent;
};