-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.js
93 lines (75 loc) · 1.96 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
84
85
86
87
88
89
90
91
92
93
// Contains all environment variables
const env = {};
// Contains all configuration settings for mikrocms
const source = {};
/**
* Applies the mikrocms configuration settings.
*
* @param object
* @return void
*/
function setConfig(conf) {
if (typeof conf !== 'object') {
throw new Error('Invalid mikrocms config');
}
if (typeof conf.env === 'object') {
for (var name in conf.env) {
env[name] = conf.env[name];
}
}
if (typeof conf.modules !== 'object') {
throw new Error('Invalid module config');
}
for (var moduleName in conf.modules) {
if (source[moduleName]) {
throw new Error(`Duplicate module name: "${moduleName}"`);
}
const mdul = conf.modules[moduleName];
source[moduleName] = {
database: null,
schema: null,
model: null,
locale: null,
view: null,
middleware: null,
router: null,
service: null,
public: null
};
if (typeof mdul !== 'object') {
throw new Error(`Invalid configuration for module "${moduleName}"`);
}
if (typeof mdul.database === 'object') {
source[moduleName].database = mdul.database;
}
if (typeof mdul.schema === 'object') {
source[moduleName].schema = mdul.schema;
}
if (typeof mdul.model === 'object') {
source[moduleName].model = mdul.model;
}
if (typeof mdul.locale === 'object') {
source[moduleName].locale = mdul.locale;
}
if (typeof mdul.view === 'object') {
source[moduleName].view = mdul.view;
}
if (typeof mdul.middleware === 'object') {
source[moduleName].middleware = mdul.middleware;
}
if (typeof mdul.router === 'object') {
source[moduleName].router = mdul.router;
}
if (typeof mdul.service === 'object') {
source[moduleName].service = mdul.service;
}
if (typeof mdul.public === 'object') {
source[moduleName].public = mdul.public;
}
}
}
module.exports = {
env,
source,
setConfig
};