superconf 1.2.4 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Legacy.js +216 -0
- package/Superconf.js +257 -0
- package/app.js +22 -215
- package/package.json +20 -12
- package/.eslintrc.json +0 -3
- package/.gitlab-ci.yml +0 -4
- package/.travis.yml +0 -7
- package/tests/.eslintrc +0 -6
- package/tests/fixtures/.rccsontestrc.cson +0 -3
- package/tests/fixtures/.rcjsontestrc.json +0 -4
- package/tests/fixtures/.rctestrc +0 -5
- package/tests/fixtures/.rcyamltestrc.yaml +0 -2
- package/tests/fixtures/.rcymltestrc.yml +0 -2
- package/tests/fixtures/csontest.cson +0 -3
- package/tests/fixtures/defaultConf.json +0 -4
- package/tests/fixtures/jsontest.json +0 -4
- package/tests/fixtures/package.json +0 -7
- package/tests/fixtures/yamltest.yaml +0 -2
- package/tests/fixtures/ymltest.yml +0 -2
- package/tests/superconf.spec.js +0 -356
package/Legacy.js
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const CoffeeScript = require('coffeescript').compile
|
|
4
|
+
const fs = require('fs')
|
|
5
|
+
const path = require('path')
|
|
6
|
+
const yaml = require('js-yaml')
|
|
7
|
+
|
|
8
|
+
class Superconf {
|
|
9
|
+
constructor (opts) {
|
|
10
|
+
opts = opts || {}
|
|
11
|
+
|
|
12
|
+
this.files = opts.files || [
|
|
13
|
+
'%s.json',
|
|
14
|
+
'%s.cson',
|
|
15
|
+
'%s.yaml',
|
|
16
|
+
'%s.yml',
|
|
17
|
+
'.%src',
|
|
18
|
+
'.%src.json',
|
|
19
|
+
'.%src.cson',
|
|
20
|
+
'.%src.yaml',
|
|
21
|
+
'.%src.yml',
|
|
22
|
+
'package.json'
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
if (opts.defaultConf) {
|
|
26
|
+
this.files.push(opts.defaultConf)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
this.cwd = opts.cwd || process.cwd()
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
getFirstExisting (name) {
|
|
33
|
+
for (const file of this.files) {
|
|
34
|
+
const filepath = path.resolve(this.cwd, file.replace('%s', name))
|
|
35
|
+
try {
|
|
36
|
+
fs.accessSync(filepath)
|
|
37
|
+
if (file === 'package.json') {
|
|
38
|
+
const json = require(filepath)
|
|
39
|
+
if (json[name]) return filepath
|
|
40
|
+
} else {
|
|
41
|
+
return filepath
|
|
42
|
+
}
|
|
43
|
+
} catch (err) {
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return null
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
tryFiles (name) {
|
|
52
|
+
console.error('superconf.tryFiles() is deprecated. Use .load() instead')
|
|
53
|
+
if (!name) {
|
|
54
|
+
throw new Error('Name arg must be set!')
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const confFile = this.getFirstExisting(name)
|
|
58
|
+
|
|
59
|
+
if (!confFile) {
|
|
60
|
+
return null
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const ext = path.extname(confFile)
|
|
64
|
+
let json
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
if (ext === '.json') {
|
|
68
|
+
json = require(confFile)
|
|
69
|
+
if (path.basename(confFile) === 'package.json') {
|
|
70
|
+
json = json[name]
|
|
71
|
+
}
|
|
72
|
+
} else {
|
|
73
|
+
const source = fs.readFileSync(confFile, { encoding: 'utf8' })
|
|
74
|
+
|
|
75
|
+
if (ext === '.cson') {
|
|
76
|
+
const js = CoffeeScript('module.exports =\n' + source)
|
|
77
|
+
const module = {}
|
|
78
|
+
eval(js) // eslint-disable-line no-eval
|
|
79
|
+
json = module.exports
|
|
80
|
+
} else if (ext === '.yaml' || ext === '.yml') {
|
|
81
|
+
json = yaml.load(source)
|
|
82
|
+
} else {
|
|
83
|
+
const source = fs.readFileSync(confFile, { encoding: 'utf8' })
|
|
84
|
+
eval('json = ' + source) // eslint-disable-line no-eval
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
} catch (err) {
|
|
88
|
+
throw new SyntaxError('Could not parse config file: ' + confFile + '\n\n' + err)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (json) {
|
|
92
|
+
return json
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
config (conf) {
|
|
97
|
+
this.mergeConf = {
|
|
98
|
+
dept: conf.dept || 0
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (conf.cwd) {
|
|
102
|
+
this.cwd = conf.cwd
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return this
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// copy (obj) {
|
|
109
|
+
// if (typeof obj !== 'object' || obj === null) {
|
|
110
|
+
// return obj
|
|
111
|
+
// }
|
|
112
|
+
//
|
|
113
|
+
// if (Array.isArray(obj)) {
|
|
114
|
+
// return obj.map((item) => this.copy(item))
|
|
115
|
+
// }
|
|
116
|
+
//
|
|
117
|
+
// const copied = {}
|
|
118
|
+
// for (const key in obj) {
|
|
119
|
+
// if (obj.hasOwnProperty(key)) { //eslint-disable-line
|
|
120
|
+
// if (obj[key] === null) {
|
|
121
|
+
// copied[key] = null
|
|
122
|
+
// continue
|
|
123
|
+
// }
|
|
124
|
+
//
|
|
125
|
+
// if (Array.isArray(obj[key])) {
|
|
126
|
+
// copied[key] = obj[key].map((item) => this.copy(item))
|
|
127
|
+
// continue
|
|
128
|
+
// }
|
|
129
|
+
//
|
|
130
|
+
// if (typeof obj[key] === 'object') {
|
|
131
|
+
// copied[key] = this.copy(obj[key])
|
|
132
|
+
// continue
|
|
133
|
+
// }
|
|
134
|
+
//
|
|
135
|
+
// copied[key] = obj[key]
|
|
136
|
+
// }
|
|
137
|
+
// }
|
|
138
|
+
//
|
|
139
|
+
// return copied
|
|
140
|
+
// }
|
|
141
|
+
|
|
142
|
+
// merge () {
|
|
143
|
+
// let conf = {}
|
|
144
|
+
// const args = Array.prototype.slice.call(arguments)
|
|
145
|
+
//
|
|
146
|
+
// const dept = this.mergeConf ? this.mergeConf.dept : 0
|
|
147
|
+
//
|
|
148
|
+
// const merge = function (left, right, curdept) {
|
|
149
|
+
// if (left === undefined || left === null) {
|
|
150
|
+
// left = {}
|
|
151
|
+
// }
|
|
152
|
+
//
|
|
153
|
+
// if (typeof right !== 'object') {
|
|
154
|
+
// return left
|
|
155
|
+
// }
|
|
156
|
+
//
|
|
157
|
+
// for (const key in right) {
|
|
158
|
+
// if (right.hasOwnProperty(key)) { // eslint-disable-line
|
|
159
|
+
// if (right[key] === undefined) {
|
|
160
|
+
// continue
|
|
161
|
+
// }
|
|
162
|
+
//
|
|
163
|
+
// if (right[key] === null) {
|
|
164
|
+
// left[key] = null
|
|
165
|
+
// continue
|
|
166
|
+
// }
|
|
167
|
+
//
|
|
168
|
+
// if (Array.isArray(right[key])) {
|
|
169
|
+
// left[key] = right[key].map(item => {
|
|
170
|
+
// if (typeof item === 'object') {
|
|
171
|
+
// return JSON.parse(JSON.stringify(item))
|
|
172
|
+
// }
|
|
173
|
+
//
|
|
174
|
+
// return item
|
|
175
|
+
// })
|
|
176
|
+
// continue
|
|
177
|
+
// }
|
|
178
|
+
//
|
|
179
|
+
// if (typeof right[key] === 'object') {
|
|
180
|
+
// if (curdept) {
|
|
181
|
+
// left[key] = merge(left[key], right[key], left[key]--)
|
|
182
|
+
// continue
|
|
183
|
+
// }
|
|
184
|
+
//
|
|
185
|
+
// left[key] = Object.assign({}, right[key])
|
|
186
|
+
// continue
|
|
187
|
+
// }
|
|
188
|
+
//
|
|
189
|
+
// left[key] = right[key]
|
|
190
|
+
// }
|
|
191
|
+
// }
|
|
192
|
+
//
|
|
193
|
+
// return left
|
|
194
|
+
// }
|
|
195
|
+
//
|
|
196
|
+
// for (let i = 0; i < args.length; i++) {
|
|
197
|
+
// conf = merge(conf, args[i], dept)
|
|
198
|
+
// }
|
|
199
|
+
//
|
|
200
|
+
// return conf
|
|
201
|
+
// }
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// module.exports = function (name, opts) {
|
|
205
|
+
// const sc = new Superconf(opts)
|
|
206
|
+
// return sc.tryFiles(name)
|
|
207
|
+
// }
|
|
208
|
+
|
|
209
|
+
// module.exports.config = function (conf) {
|
|
210
|
+
// const sc = new Superconf()
|
|
211
|
+
// return sc.config(conf)
|
|
212
|
+
// }
|
|
213
|
+
|
|
214
|
+
module.exports.Superconf = Superconf
|
|
215
|
+
// module.exports.merge = Superconf.prototype.merge
|
|
216
|
+
// module.exports.copy = Superconf.prototype.copy.bind(Superconf.prototype)
|
package/Superconf.js
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
module.exports.__fsLocationMap = [[1, 21, 2, 7], [1, 33, 2, 24], [1, 8, 2, 36], [2, 13, 3, 7], [2, 26, 3, 25], [3, 13, 4, 7], [3, 23, 4, 22], [4, 8, 5, 7], [4, 20, 5, 24], [4, 8, 5, 45], [6, 1, 6, 1], [6, 7, 6, 7], [6, 13, 6, 13], [7, 1, 7, 1], [7, 7, 7, 7], [7, 14, 7, 14], [8, 1, 8, 1], [8, 7, 8, 7], [8, 16, 8, 16], [9, 1, 9, 1], [9, 7, 9, 7], [9, 15, 9, 15], [10, 1, 10, 1], [10, 7, 10, 7], [10, 15, 10, 15], [11, 1, 11, 1], [11, 7, 11, 7], [11, 15, 11, 15], [12, 1, 12, 1], [12, 7, 12, 7], [12, 17, 12, 17], [14, 8, 13, 1], [14, 14, 13, 7], [14, 24, 13, 17], [14, 32, 13, 25], [15, 5, 14, 3], [15, 18, 14, 16], [15, 18, 15, 5], [15, 18, 15, 12], [16, 9, 16, 5], [16, 15, 16, 11], [18, 9, 17, 5], [18, 14, 17, 10], [18, 27, 17, 23], [18, 32, 17, 28], [18, 46, 17, 42], [18, 54, 17, 50], [19, 9, 18, 5], [19, 14, 18, 10], [20, 9, 19, 5], [20, 14, 19, 10], [20, 24, 19, 20], [20, 29, 19, 25], [20, 40, 19, 36], [21, 9, 20, 5], [21, 14, 20, 10], [21, 26, 20, 22], [21, 31, 20, 27], [21, 39, 20, 35], [23, 9, 21, 5], [23, 14, 21, 10], [23, 22, 21, 18], [23, 27, 21, 23], [23, 36, 21, 32], [24, 13, 22, 7], [25, 13, 23, 7], [26, 13, 24, 7], [27, 13, 25, 7], [28, 13, 26, 7], [29, 13, 27, 7], [33, 5, 31, 3], [33, 12, 31, 10], [33, 20, 31, 18], [34, 9, 32, 5], [34, 12, 32, 9], [34, 17, 32, 14], [35, 17, 33, 19], [35, 25, 33, 27], [35, 32, 33, 34], [35, 47, 33, 49], [35, 55, 33, 57], [35, 60, 33, 62], [35, 69, 33, 71], [38, 5, 37, 3], [38, 13, 37, 11], [39, 9, 38, 5], [39, 14, 38, 10], [40, 9, 39, 5], [40, 16, 39, 12], [40, 24, 39, 20], [40, 38, 39, 34], [40, 46, 39, 42], [40, 47, 39, 43], [40, 48, 39, 45], [40, 53, 39, 50], [41, 13, 40, 7], [41, 19, 40, 13], [42, 17, 41, 9], [42, 23, 41, 15], [42, 29, 41, 21], [42, 37, 41, 29], [43, 17, 42, 9], [43, 27, 42, 19], [43, 33, 42, 25], [43, 45, 42, 37], [46, 13, 44, 7], [46, 16, 44, 11], [46, 23, 44, 18], [46, 29, 44, 24], [46, 41, 44, 36], [47, 17, 45, 9], [47, 24, 45, 16], [47, 34, 45, 26], [47, 40, 45, 32], [49, 13, 47, 7], [49, 16, 47, 11], [49, 23, 47, 18], [49, 29, 47, 24], [49, 44, 47, 39], [50, 17, 48, 9], [50, 24, 48, 16], [50, 37, 48, 29], [50, 43, 48, 35], [52, 13, 50, 7], [52, 18, 50, 12], [52, 31, 50, 25], [52, 38, 50, 32], [56, 5, 54, 3], [56, 20, 54, 18], [56, 28, 54, 26], [57, 9, 55, 5], [57, 16, 55, 12], [57, 23, 55, 19], [57, 31, 55, 27], [60, 5, 58, 3], [60, 15, 58, 13], [61, 9, 59, 5], [61, 12, 59, 9], [61, 13, 59, 10], [61, 18, 59, 15], [62, 13, 60, 7], [62, 20, 60, 14], [64, 9, 62, 5], [64, 14, 62, 10], [64, 33, 62, 29], [65, 9, 63, 5], [65, 15, 63, 11], [65, 33, 63, 29], [65, 41, 63, 37], [65, 46, 63, 42], [66, 9, 64, 5], [66, 15, 64, 11], [67, 13, 65, 7], [67, 19, 65, 13], [68, 13, 66, 7], [68, 25, 66, 19], [68, 30, 66, 24], [71, 9, 68, 5], [71, 14, 68, 10], [71, 31, 68, 27], [71, 50, 68, 46], [71, 60, 68, 56], [73, 9, 69, 5], [73, 16, 69, 12], [73, 21, 69, 17], [73, 38, 69, 34], [73, 49, 69, 45], [75, 5, 72, 3], [75, 23, 72, 21], [75, 31, 72, 29], [75, 37, 72, 35], [76, 9, 73, 5], [76, 14, 73, 10], [76, 20, 73, 16], [76, 41, 73, 37], [76, 60, 73, 56], [76, 70, 73, 66], [76, 88, 73, 84], [78, 9, 74, 5], [78, 12, 74, 9], [78, 13, 74, 10], [79, 13, 75, 7], [79, 20, 75, 14], [81, 9, 77, 5], [81, 12, 77, 9], [81, 13, 77, 10], [82, 13, 78, 7], [82, 16, 78, 11], [82, 23, 78, 18], [82, 36, 78, 31], [83, 17, 79, 9], [83, 22, 79, 14], [83, 39, 79, 31], [83, 44, 79, 36], [83, 52, 79, 44], [85, 13, 80, 9], [86, 17, 81, 9], [86, 24, 81, 16], [88, 9, 84, 5], [88, 12, 84, 9], [88, 19, 84, 16], [88, 28, 84, 25], [89, 13, 85, 7], [89, 16, 85, 11], [89, 23, 85, 18], [89, 36, 85, 31], [90, 17, 86, 9], [90, 22, 86, 14], [90, 39, 86, 31], [90, 44, 86, 36], [90, 52, 86, 44], [92, 9, 88, 7], [92, 14, 88, 16], [92, 21, 88, 23], [92, 30, 88, 32], [93, 13, 89, 7], [93, 16, 89, 11], [93, 23, 89, 18], [93, 36, 89, 31], [94, 17, 90, 9], [94, 22, 90, 14], [94, 39, 90, 31], [94, 44, 90, 36], [94, 52, 90, 44], [96, 9, 92, 7], [96, 14, 92, 16], [96, 21, 92, 23], [96, 30, 92, 32], [97, 13, 93, 7], [97, 16, 93, 11], [97, 23, 93, 18], [97, 36, 93, 31], [98, 17, 94, 9], [98, 22, 94, 14], [98, 39, 94, 31], [98, 44, 94, 36], [98, 52, 94, 44], [100, 9, 96, 7], [100, 14, 96, 16], [100, 21, 96, 23], [100, 30, 96, 32], [101, 13, 97, 7], [101, 16, 97, 11], [101, 17, 97, 12], [101, 23, 97, 18], [101, 31, 97, 26], [102, 17, 98, 9], [102, 22, 98, 14], [102, 39, 98, 31], [102, 44, 98, 36], [102, 52, 98, 44], [104, 9, 100, 7], [104, 14, 100, 16], [104, 21, 100, 23], [104, 30, 100, 32], [105, 13, 101, 7], [105, 16, 101, 11], [105, 23, 101, 18], [105, 36, 101, 31], [106, 17, 102, 9], [106, 22, 102, 14], [106, 39, 102, 31], [106, 44, 102, 36], [106, 52, 102, 44], [108, 13, 104, 7], [108, 20, 104, 14], [108, 28, 104, 22], [108, 38, 104, 32], [108, 46, 104, 40], [108, 47, 104, 41], [108, 48, 104, 43], [108, 53, 104, 48], [109, 17, 105, 9], [109, 23, 105, 15], [109, 35, 105, 27], [109, 40, 105, 32], [109, 54, 105, 46], [109, 61, 105, 53], [109, 73, 105, 65], [110, 17, 106, 9], [110, 22, 106, 14], [110, 39, 106, 31], [110, 50, 106, 42], [110, 53, 106, 45], [110, 61, 106, 53], [110, 68, 106, 60], [113, 13, 108, 7], [113, 20, 108, 14], [113, 28, 108, 22], [113, 35, 108, 29], [113, 47, 108, 41], [113, 55, 108, 49], [113, 56, 108, 50], [113, 57, 108, 52], [113, 62, 108, 57], [114, 17, 109, 9], [114, 20, 109, 13], [114, 21, 109, 14], [114, 30, 109, 23], [114, 38, 109, 31], [114, 48, 109, 41], [115, 21, 110, 11], [115, 26, 110, 16], [115, 32, 110, 22], [115, 66, 110, 56], [115, 77, 110, 67], [115, 87, 110, 77], [116, 21, 111, 11], [116, 30, 111, 20], [116, 37, 111, 27], [116, 47, 111, 37], [118, 17, 112, 11], [118, 22, 112, 20], [118, 23, 112, 21], [118, 32, 112, 30], [118, 40, 112, 38], [118, 50, 112, 48], [118, 59, 112, 57], [119, 21, 113, 11], [119, 30, 113, 20], [121, 17, 115, 9], [121, 22, 115, 14], [121, 39, 115, 31], [121, 50, 115, 42], [121, 53, 115, 45], [121, 61, 115, 53], [121, 68, 115, 60], [121, 77, 115, 69], [124, 5, 120, 3], [124, 11, 120, 9], [124, 21, 120, 19], [125, 9, 121, 5], [125, 15, 121, 11], [125, 20, 121, 16], [125, 26, 121, 22], [125, 33, 121, 29], [125, 38, 121, 34], [127, 9, 122, 5], [127, 12, 122, 9], [127, 13, 122, 10], [127, 16, 122, 13], [128, 13, 123, 7], [128, 18, 123, 12], [128, 24, 123, 18], [128, 36, 123, 30], [129, 13, 124, 7], [129, 20, 124, 14], [131, 9, 126, 5], [131, 14, 126, 10], [131, 20, 126, 16], [131, 38, 126, 34], [132, 9, 127, 5], [132, 12, 127, 9], [132, 15, 127, 12], [132, 23, 127, 20], [133, 13, 128, 7], [133, 20, 128, 14], [133, 23, 128, 17], [135, 9, 130, 5], [135, 12, 130, 9], [135, 15, 130, 12], [135, 23, 130, 20], [135, 33, 130, 30], [135, 36, 130, 33], [135, 44, 130, 41], [136, 13, 131, 7], [136, 19, 131, 13], [136, 26, 131, 20], [136, 34, 131, 28], [137, 13, 132, 7], [137, 19, 132, 13], [137, 28, 132, 22], [137, 34, 132, 28], [137, 37, 132, 31], [138, 13, 133, 7], [138, 20, 133, 14], [138, 25, 133, 19], [138, 30, 133, 24], [140, 9, 135, 5], [140, 16, 135, 12], [142, 5, 138, 3], [142, 18, 138, 16], [143, 9, 139, 5], [143, 16, 139, 12], [143, 24, 139, 20], [143, 29, 139, 25], [143, 43, 139, 39], [143, 51, 139, 47], [143, 52, 139, 48], [143, 53, 139, 50], [143, 58, 139, 55], [144, 13, 140, 7], [144, 16, 140, 11], [144, 23, 140, 18], [144, 30, 140, 25], [144, 39, 140, 34], [144, 54, 140, 49], [144, 61, 140, 56], [144, 67, 140, 62], [144, 79, 140, 74], [145, 17, 141, 9], [145, 24, 141, 16], [145, 31, 141, 23], [145, 37, 141, 29], [149, 5, 146, 3], [149, 11, 146, 9], [149, 17, 146, 15], [150, 9, 147, 5], [150, 14, 147, 10], [150, 20, 147, 16], [150, 35, 147, 31], [152, 9, 148, 5], [152, 13, 148, 10], [152, 19, 148, 16], [152, 27, 148, 24], [152, 32, 148, 29], [153, 13, 149, 7], [153, 19, 149, 13], [153, 30, 149, 24], [153, 35, 149, 29], [153, 43, 149, 37], [153, 48, 149, 42], [153, 60, 149, 54], [153, 65, 149, 59], [153, 73, 149, 67], [153, 79, 149, 73], [154, 13, 150, 7], [154, 19, 150, 13], [154, 28, 150, 22], [154, 34, 150, 28], [154, 39, 150, 33], [154, 48, 150, 42], [156, 13, 151, 7], [156, 16, 151, 11], [156, 27, 151, 22], [157, 17, 152, 9], [162, 13, 156, 7], [162, 16, 156, 11], [162, 17, 156, 12], [162, 22, 156, 17], [162, 31, 156, 26], [163, 17, 157, 9], [163, 23, 157, 15], [163, 42, 157, 34], [163, 47, 157, 39], [163, 64, 157, 56], [163, 69, 157, 61], [164, 17, 158, 9], [164, 23, 158, 15], [164, 27, 158, 19], [164, 33, 158, 25], [164, 62, 158, 57], [166, 13, 160, 7], [166, 18, 160, 12], [166, 27, 160, 21], [167, 13, 161, 7], [167, 20, 161, 14], [169, 9, 163, 5], [169, 16, 163, 12], [171, 5, 166, 3], [171, 15, 166, 13], [172, 9, 167, 5], [172, 15, 167, 11], [174, 9, 168, 5], [174, 15, 168, 11], [174, 23, 168, 19], [174, 24, 168, 20], [174, 30, 168, 26], [174, 37, 168, 33], [175, 13, 169, 7], [175, 16, 169, 11], [175, 25, 169, 20], [175, 38, 169, 33], [175, 47, 169, 42], [176, 17, 170, 9], [178, 13, 172, 7], [178, 16, 172, 11], [178, 23, 172, 18], [178, 33, 172, 28], [179, 17, 173, 9], [179, 24, 173, 16], [182, 13, 175, 7], [182, 17, 175, 12], [182, 23, 175, 18], [182, 30, 175, 25], [183, 17, 176, 9], [183, 20, 176, 13], [183, 26, 176, 19], [183, 41, 176, 34], [184, 21, 177, 11], [184, 24, 177, 15], [184, 30, 177, 21], [184, 39, 177, 30], [185, 25, 178, 13], [187, 21, 180, 11], [187, 24, 180, 15], [187, 30, 180, 21], [187, 39, 180, 30], [188, 25, 181, 13], [188, 30, 181, 18], [188, 37, 181, 25], [189, 25, 182, 13], [191, 21, 184, 11], [191, 24, 184, 15], [191, 30, 184, 21], [191, 38, 184, 29], [191, 44, 184, 35], [192, 25, 185, 13], [192, 30, 185, 18], [192, 37, 185, 25], [192, 43, 185, 31], [192, 48, 185, 36], [192, 52, 185, 40], [192, 53, 185, 41], [193, 29, 186, 15], [193, 32, 186, 19], [193, 39, 186, 26], [193, 48, 186, 35], [194, 33, 187, 17], [194, 40, 187, 24], [194, 45, 187, 29], [194, 51, 187, 35], [194, 56, 187, 40], [194, 66, 187, 50], [196, 29, 189, 15], [196, 36, 189, 22], [199, 25, 191, 13], [201, 21, 193, 11], [201, 24, 193, 15], [201, 31, 193, 22], [201, 37, 193, 28], [201, 46, 193, 37], [202, 25, 194, 13], [202, 28, 194, 17], [203, 29, 195, 15], [203, 34, 195, 20], [203, 41, 195, 27], [203, 47, 195, 33], [203, 52, 195, 38], [203, 58, 195, 44], [203, 64, 195, 50], [203, 70, 195, 56], [203, 75, 195, 61], [204, 29, 196, 15], [206, 25, 198, 13], [206, 30, 198, 18], [206, 37, 198, 25], [206, 44, 198, 32], [206, 55, 198, 43], [206, 61, 198, 49], [207, 25, 199, 13], [209, 21, 201, 11], [209, 26, 201, 16], [209, 33, 201, 23], [209, 39, 201, 29], [211, 13, 204, 7], [211, 20, 204, 14], [213, 9, 206, 5], [213, 13, 206, 10], [213, 17, 206, 14], [213, 21, 206, 18], [213, 24, 206, 21], [213, 28, 206, 25], [213, 33, 206, 30], [213, 41, 206, 38], [214, 13, 207, 7], [214, 19, 207, 13], [214, 25, 207, 19], [214, 30, 207, 24], [214, 34, 207, 28], [214, 39, 207, 33], [216, 9, 209, 5], [216, 16, 209, 12], [218, 5, 212, 3], [218, 11, 212, 9], [219, 9, 213, 5], [219, 12, 213, 9], [219, 19, 213, 16], [219, 27, 213, 24], [219, 39, 213, 36], [219, 47, 213, 44], [220, 13, 214, 7], [220, 20, 214, 14], [222, 9, 216, 5], [222, 12, 216, 9], [222, 18, 216, 15], [222, 26, 216, 23], [223, 13, 217, 7], [223, 20, 217, 14], [223, 24, 217, 18], [223, 28, 217, 22], [223, 29, 217, 23], [224, 17, 218, 9], [224, 22, 218, 14], [224, 27, 218, 19], [227, 9, 221, 5], [227, 15, 221, 11], [228, 9, 222, 5], [228, 13, 222, 10], [228, 19, 222, 16], [228, 26, 222, 23], [229, 13, 223, 7], [229, 16, 223, 11], [229, 20, 223, 15], [229, 35, 223, 30], [230, 17, 224, 9], [230, 20, 224, 13], [230, 24, 224, 17], [230, 33, 224, 26], [231, 21, 225, 11], [231, 28, 225, 18], [231, 35, 225, 25], [232, 21, 226, 11], [234, 17, 228, 9], [234, 20, 228, 13], [234, 26, 228, 19], [234, 34, 228, 27], [234, 38, 228, 31], [235, 21, 229, 11], [235, 28, 229, 18], [235, 35, 229, 25], [235, 39, 229, 29], [235, 44, 229, 34], [235, 48, 229, 38], [235, 49, 229, 39], [236, 25, 230, 13], [236, 30, 230, 18], [236, 35, 230, 23], [239, 21, 232, 11], [241, 17, 234, 9], [241, 20, 234, 13], [241, 27, 234, 20], [241, 31, 234, 24], [241, 40, 234, 33], [242, 21, 235, 11], [242, 28, 235, 18], [242, 35, 235, 25], [242, 40, 235, 30], [242, 45, 235, 35], [242, 49, 235, 39], [243, 21, 236, 11], [245, 17, 238, 9], [245, 24, 238, 16], [245, 31, 238, 23], [245, 35, 238, 27], [247, 9, 241, 5], [247, 16, 241, 12], [249, 5, 244, 3], [249, 10, 244, 8], [250, 9, 245, 5], [250, 15, 245, 11], [250, 22, 245, 18], [250, 33, 245, 29], [250, 39, 245, 35], [251, 9, 246, 5], [251, 13, 246, 9], [251, 20, 246, 16], [251, 25, 246, 21], [253, 9, 247, 5], [253, 13, 247, 10], [253, 19, 247, 16], [253, 26, 247, 23], [254, 13, 248, 7], [254, 20, 248, 14], [254, 25, 248, 19], [255, 13, 249, 7], [255, 16, 249, 11], [255, 17, 249, 12], [256, 17, 250, 9], [256, 24, 250, 16], [258, 9, 253, 5], [258, 16, 253, 12], [14, 14, 256, 16], [14, 14, 256, 28]];
|
|
2
|
+
module.exports.__esModule = true;
|
|
3
|
+
const Legacy = require('./Legacy').Superconf;
|
|
4
|
+
const colorfy = require('colorfy');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const FireFS = require('firescript-firefs').FireFS;
|
|
7
|
+
const red = '\u001b[38;5;160m';
|
|
8
|
+
const ored = '\u001b[38;5;202m';
|
|
9
|
+
const yellow = '\u001b[38;5;226m';
|
|
10
|
+
const dgrey = '\u001b[38;5;244m';
|
|
11
|
+
const lgrey = '\u001b[38;5;250m';
|
|
12
|
+
const azure = '\u001b[38;5;39m';
|
|
13
|
+
const uncolor = '\u001b[m';
|
|
14
|
+
class Superconf extends Legacy {
|
|
15
|
+
constructor (opts) {
|
|
16
|
+
opts = opts || {};
|
|
17
|
+
super(opts);
|
|
18
|
+
this.workingDir = opts.workingDir || process.cwd();
|
|
19
|
+
this.config = {};
|
|
20
|
+
this.verbose = opts.verbose || false;
|
|
21
|
+
this.mergeDept = opts.dept || 0;
|
|
22
|
+
this.files = opts.files || [
|
|
23
|
+
'%s.json',
|
|
24
|
+
'%s.yaml',
|
|
25
|
+
'%s.yml',
|
|
26
|
+
'.%src.json',
|
|
27
|
+
'.%src.yaml',
|
|
28
|
+
'.%src.yml'
|
|
29
|
+
];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
debug (msg, ...data) {
|
|
33
|
+
if (this.verbose) {
|
|
34
|
+
console.log(colorfy.yellow('Superconf:'), colorfy.grey(msg), ...data);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
schema (configSchema) {
|
|
39
|
+
this.configSchema = {};
|
|
40
|
+
Object.entries(configSchema).forEach(([ key, value ]) => {
|
|
41
|
+
const schema = {
|
|
42
|
+
type: value.type || 'str',
|
|
43
|
+
required: value.required || false
|
|
44
|
+
};
|
|
45
|
+
if (typeof value.default !== 'undefined') {
|
|
46
|
+
schema.default = value.default;
|
|
47
|
+
}
|
|
48
|
+
if (typeof value.properties !== 'undefined') {
|
|
49
|
+
schema.properties = value.properties;
|
|
50
|
+
}
|
|
51
|
+
this.configSchema[key] = schema;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
getSchemaItem (schema, key) {
|
|
56
|
+
return schema[key] || null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
validate (conf) {
|
|
60
|
+
if (!this.configSchema) {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
this.validationErrors = [ ];
|
|
64
|
+
const validateionData = conf || this.config;
|
|
65
|
+
const validateionSchema = {
|
|
66
|
+
type: 'obj',
|
|
67
|
+
properties: this.configSchema
|
|
68
|
+
};
|
|
69
|
+
this.validateProperty(validateionSchema, 'config', validateionData);
|
|
70
|
+
return this.validationErrors.length === 0;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
validateProperty (schema, name, property) {
|
|
74
|
+
this.debug(`Validate property ${name} with value`, property, 'against schema', schema);
|
|
75
|
+
if (!schema) {
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
if (!property) {
|
|
79
|
+
if (schema.required === true) {
|
|
80
|
+
this.validationErrors.push(`Item ${name} is required but not set`);
|
|
81
|
+
} else {
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (schema.type === 'str') {
|
|
86
|
+
if (typeof property !== 'string') {
|
|
87
|
+
this.validationErrors.push(`Item ${name} is not of type string`);
|
|
88
|
+
}
|
|
89
|
+
} else if (schema.type === 'num') {
|
|
90
|
+
if (typeof property !== 'number') {
|
|
91
|
+
this.validationErrors.push(`Item ${name} is not of type number`);
|
|
92
|
+
}
|
|
93
|
+
} else if (schema.type === 'bool') {
|
|
94
|
+
if (typeof property !== 'boolean') {
|
|
95
|
+
this.validationErrors.push(`Item ${name} is not of type boolean`);
|
|
96
|
+
}
|
|
97
|
+
} else if (schema.type === 'arr') {
|
|
98
|
+
if (!Array.isArray(property)) {
|
|
99
|
+
this.validationErrors.push(`Item ${name} is not of type array`);
|
|
100
|
+
}
|
|
101
|
+
} else if (schema.type === 'obj') {
|
|
102
|
+
if (typeof property !== 'object') {
|
|
103
|
+
this.validationErrors.push(`Item ${name} is not of type object`);
|
|
104
|
+
}
|
|
105
|
+
Object.entries(property).forEach(([ key, value ]) => {
|
|
106
|
+
const subSchema = this.getSchemaItem(schema.properties, key);
|
|
107
|
+
this.validateProperty(subSchema, `${name}.${key}`, value);
|
|
108
|
+
});
|
|
109
|
+
Object.entries(schema.properties).forEach(([ key, subSchema ]) => {
|
|
110
|
+
if (!property[key] && subSchema.default) {
|
|
111
|
+
this.debug(`Set default value for property ${name} to`, subSchema.default);
|
|
112
|
+
property[key] = subSchema.default;
|
|
113
|
+
} else if (!property[key] && subSchema.type === 'obj') {
|
|
114
|
+
property[key] = {};
|
|
115
|
+
}
|
|
116
|
+
this.validateProperty(subSchema, `${name}.${key}`, property[key]);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async fromFile (filepath) {
|
|
122
|
+
const fl = await FireFS.file(filepath);
|
|
123
|
+
if (!fl.exists) {
|
|
124
|
+
this.debug('Try file', filepath);
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
this.debug('Load from file', filepath);
|
|
128
|
+
if (fl.ext === 'json') {
|
|
129
|
+
return fl.readJSON();
|
|
130
|
+
}
|
|
131
|
+
if (fl.ext === 'yaml' || fl.ext === 'yml') {
|
|
132
|
+
const yaml = require('js-yaml');
|
|
133
|
+
const source = await fl.read();
|
|
134
|
+
return yaml.load(source);
|
|
135
|
+
}
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
setDefaults (config) {
|
|
140
|
+
Object.entries(this.configSchema).forEach(([ key, value ]) => {
|
|
141
|
+
if (typeof config[key] === 'undefined' && typeof value.default !== 'undefined') {
|
|
142
|
+
config[key] = value.default;
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async load (name) {
|
|
148
|
+
this.debug('Load config', name);
|
|
149
|
+
for (const file of this.files) {
|
|
150
|
+
const filepath = path.resolve(this.workingDir, file.replace('%s', name));
|
|
151
|
+
const config = await this.fromFile(filepath);
|
|
152
|
+
if (config === null) {
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
// if config
|
|
156
|
+
// this.setDefaults(config)
|
|
157
|
+
if (!this.validate(config)) {
|
|
158
|
+
const validationErrors = this.validationErrors.join(' \n');
|
|
159
|
+
throw new Error(`Invalid config loaded!////n ${validationErrors}`);
|
|
160
|
+
}
|
|
161
|
+
this.config = config;
|
|
162
|
+
return config;
|
|
163
|
+
}
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
merge (...args) {
|
|
168
|
+
const conf = {};
|
|
169
|
+
const merge = (left, right, curdept) => {
|
|
170
|
+
if (left === undefined || left === null) {
|
|
171
|
+
left = {};
|
|
172
|
+
}
|
|
173
|
+
if (typeof right !== 'object') {
|
|
174
|
+
return left;
|
|
175
|
+
}
|
|
176
|
+
for (const key in right) {
|
|
177
|
+
if (right.hasOwnProperty(key)) {
|
|
178
|
+
if (right[key] === undefined) {
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
if (right[key] === null) {
|
|
182
|
+
left[key] = null;
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
if (Array.isArray(right[key])) {
|
|
186
|
+
left[key] = right[key].map((item) => {
|
|
187
|
+
if (typeof item === 'object') {
|
|
188
|
+
return JSON.parse(JSON.stringify(item));
|
|
189
|
+
}
|
|
190
|
+
return item;
|
|
191
|
+
});
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
if (typeof right[key] === 'object') {
|
|
195
|
+
if (curdept) {
|
|
196
|
+
left[key] = merge(left[key], right[key], left[key]--);
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
left[key] = Object.assign({}, right[key]);
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
left[key] = right[key];
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return left;
|
|
206
|
+
};
|
|
207
|
+
for (let i = 0; i < args.length; i++) {
|
|
208
|
+
merge(conf, args[i], this.mergeDept);
|
|
209
|
+
}
|
|
210
|
+
return conf;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
copy (obj) {
|
|
214
|
+
if (typeof obj !== 'object' || obj === null) {
|
|
215
|
+
return obj;
|
|
216
|
+
}
|
|
217
|
+
if (Array.isArray(obj)) {
|
|
218
|
+
return obj.map((item) => {
|
|
219
|
+
this.copy(item);
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
const copied = {};
|
|
223
|
+
for (const key in obj) {
|
|
224
|
+
if (obj.hasOwnProperty(key)) {
|
|
225
|
+
if (obj[key] === null) {
|
|
226
|
+
copied[key] = null;
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
if (Array.isArray(obj[key])) {
|
|
230
|
+
copied[key] = obj[key].map((item) => {
|
|
231
|
+
this.copy(item);
|
|
232
|
+
});
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
if (typeof obj[key] === 'object') {
|
|
236
|
+
copied[key] = this.copy(obj[key]);
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
copied[key] = obj[key];
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return copied;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
get (configPath) {
|
|
246
|
+
const keys = configPath.split('.');
|
|
247
|
+
let conf = this.config;
|
|
248
|
+
for (const key of keys) {
|
|
249
|
+
conf = conf[key];
|
|
250
|
+
if (!conf) {
|
|
251
|
+
return null;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return conf;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
module.exports.Superconf = Superconf;
|
package/app.js
CHANGED
|
@@ -1,216 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
'.%src.json',
|
|
19
|
-
'.%src.cson',
|
|
20
|
-
'.%src.yaml',
|
|
21
|
-
'.%src.yml',
|
|
22
|
-
'package.json'
|
|
23
|
-
]
|
|
24
|
-
|
|
25
|
-
if (opts.defaultConf) {
|
|
26
|
-
this.files.push(opts.defaultConf)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
this.cwd = opts.cwd || process.cwd()
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
getFirstExisting (name) {
|
|
33
|
-
for (const file of this.files) {
|
|
34
|
-
const filepath = path.resolve(this.cwd, file.replace('%s', name))
|
|
35
|
-
try {
|
|
36
|
-
fs.accessSync(filepath)
|
|
37
|
-
if (file === 'package.json') {
|
|
38
|
-
const json = require(filepath)
|
|
39
|
-
if (json[name]) return filepath
|
|
40
|
-
} else {
|
|
41
|
-
return filepath
|
|
42
|
-
}
|
|
43
|
-
} catch (err) {
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return null
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
tryFiles (name) {
|
|
52
|
-
if (!name) {
|
|
53
|
-
throw new Error('Name arg must be set!')
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const confFile = this.getFirstExisting(name)
|
|
57
|
-
|
|
58
|
-
if (!confFile) {
|
|
59
|
-
return null
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const ext = path.extname(confFile)
|
|
63
|
-
let json
|
|
64
|
-
|
|
65
|
-
try {
|
|
66
|
-
if (ext === '.json') {
|
|
67
|
-
json = require(confFile)
|
|
68
|
-
if (path.basename(confFile) === 'package.json') {
|
|
69
|
-
json = json[name]
|
|
70
|
-
}
|
|
71
|
-
} else {
|
|
72
|
-
const source = fs.readFileSync(confFile, { encoding: 'utf8' })
|
|
73
|
-
|
|
74
|
-
if (ext === '.cson') {
|
|
75
|
-
const js = CoffeeScript('module.exports =\n' + source)
|
|
76
|
-
const module = {}
|
|
77
|
-
eval(js) // eslint-disable-line no-eval
|
|
78
|
-
json = module.exports
|
|
79
|
-
} else if (ext === '.yaml' || ext === '.yml') {
|
|
80
|
-
json = yaml.load(source)
|
|
81
|
-
} else {
|
|
82
|
-
const source = fs.readFileSync(confFile, { encoding: 'utf8' })
|
|
83
|
-
eval('json = ' + source) // eslint-disable-line no-eval
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
} catch (err) {
|
|
87
|
-
throw new SyntaxError('Could not parse config file: ' + confFile + '\n\n' + err)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (json) {
|
|
91
|
-
return json
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
config (conf) {
|
|
96
|
-
this.mergeConf = {
|
|
97
|
-
dept: conf.dept || 0
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (conf.cwd) {
|
|
101
|
-
this.cwd = conf.cwd
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return this
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
copy (obj) {
|
|
108
|
-
if (typeof obj !== 'object' || obj === null) {
|
|
109
|
-
return obj
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (Array.isArray(obj)) {
|
|
113
|
-
return obj.map((item) => this.copy(item))
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const copied = {}
|
|
117
|
-
for (const key in obj) {
|
|
118
|
-
if (obj.hasOwnProperty(key)) { //eslint-disable-line
|
|
119
|
-
if (obj[key] === null) {
|
|
120
|
-
copied[key] = null
|
|
121
|
-
continue
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (Array.isArray(obj[key])) {
|
|
125
|
-
copied[key] = obj[key].map((item) => this.copy(item))
|
|
126
|
-
continue
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (typeof obj[key] === 'object') {
|
|
130
|
-
copied[key] = this.copy(obj[key])
|
|
131
|
-
continue
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
copied[key] = obj[key]
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
return copied
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
merge () {
|
|
142
|
-
let conf = {}
|
|
143
|
-
const args = Array.prototype.slice.call(arguments)
|
|
144
|
-
|
|
145
|
-
const dept = this.mergeConf ? this.mergeConf.dept : 0
|
|
146
|
-
|
|
147
|
-
const merge = function (left, right, curdept) {
|
|
148
|
-
if (left === undefined || left === null) {
|
|
149
|
-
left = {}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if (typeof right !== 'object') {
|
|
153
|
-
return left
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
for (const key in right) {
|
|
157
|
-
if (right.hasOwnProperty(key)) { // eslint-disable-line
|
|
158
|
-
if (right[key] === undefined) {
|
|
159
|
-
continue
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
if (right[key] === null) {
|
|
163
|
-
left[key] = null
|
|
164
|
-
continue
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
if (Array.isArray(right[key])) {
|
|
168
|
-
left[key] = right[key].map(item => {
|
|
169
|
-
if (typeof item === 'object') {
|
|
170
|
-
return JSON.parse(JSON.stringify(item))
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
return item
|
|
174
|
-
})
|
|
175
|
-
continue
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
if (typeof right[key] === 'object') {
|
|
179
|
-
if (curdept) {
|
|
180
|
-
left[key] = merge(left[key], right[key], left[key]--)
|
|
181
|
-
continue
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
left[key] = Object.assign({}, right[key])
|
|
185
|
-
continue
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
left[key] = right[key]
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
return left
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
for (let i = 0; i < args.length; i++) {
|
|
196
|
-
conf = merge(conf, args[i], dept)
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
return conf
|
|
200
|
-
}
|
|
1
|
+
module.exports.__fsLocationMap = [[1, 8, 2, 7], [1, 23, 2, 27], [1, 8, 2, 42], [3, 1, 3, 1], [3, 6, 3, 10], [3, 17, 3, 21], [3, 23, 3, 27], [5, 1, 4, 1], [5, 7, 4, 7], [5, 24, 4, 24], [5, 31, 4, 31], [6, 1, 5, 1], [6, 8, 5, 8], [6, 18, 5, 18], [6, 19, 5, 19], [6, 25, 5, 25], [7, 9, 6, 15], [8, 5, 7, 3], [8, 11, 7, 9], [8, 20, 7, 18], [8, 24, 7, 22], [8, 34, 7, 32], [9, 5, 8, 3], [9, 12, 8, 10], [9, 19, 8, 17], [9, 28, 8, 26], [11, 1, 10, 1], [11, 8, 10, 8], [11, 15, 10, 15], [11, 22, 10, 22], [11, 31, 10, 31], [12, 11, 11, 26], [15, 5, 12, 16], [15, 5, 12, 28], [16, 5, 13, 16], [16, 5, 13, 28], [18, 8, 14, 1], [18, 13, 14, 10], [18, 21, 14, 18], [20, 5, 16, 3], [20, 12, 16, 10], [20, 16, 16, 14], [20, 26, 16, 24], [18, 13, 18, 16], [18, 13, 18, 25], [22, 8, 19, 1], [22, 14, 19, 7], [22, 22, 19, 15], [22, 32, 19, 25], [22, 42, 19, 35], [22, 14, 20, 16], [22, 14, 20, 24], [23, 8, 21, 1], [23, 14, 21, 7], [23, 21, 21, 14], [23, 31, 21, 24], [23, 41, 21, 34], [23, 14, 22, 16], [23, 14, 22, 23]];
|
|
2
|
+
module.exports.__esModule = true;
|
|
3
|
+
const Superconf = require('./Superconf').Superconf;
|
|
4
|
+
function superconf (name, opts) {}
|
|
5
|
+
const defaultExports = module.exports;
|
|
6
|
+
module.exports = (name, opts) => {
|
|
7
|
+
console.log('Superconf: Import namespace method is deprecated. Use named imports instead');
|
|
8
|
+
const config = new Superconf(opts);
|
|
9
|
+
return config.tryFiles(name);
|
|
10
|
+
};
|
|
11
|
+
Object.assign(module.exports, defaultExports);
|
|
12
|
+
module.exports.default = superconf;
|
|
13
|
+
module.exports.Superconf = Superconf;
|
|
14
|
+
module.exports.superconf = superconf;
|
|
15
|
+
function config (opts) {
|
|
16
|
+
// log 'Superconf: Import of config() method is deprecated. Use named imports instead'
|
|
17
|
+
return new Superconf(opts);
|
|
201
18
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
module.exports.config = function (conf) {
|
|
209
|
-
const sc = new Superconf()
|
|
210
|
-
return sc.config(conf)
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
module.exports.Superconf = Superconf
|
|
214
|
-
module.exports.merge = Superconf.prototype.merge
|
|
215
|
-
module.exports.copy = Superconf.prototype.copy.bind(Superconf.prototype)
|
|
216
|
-
module.exports.Superconf = Superconf
|
|
19
|
+
module.exports.config = config;
|
|
20
|
+
const merge = Superconf.prototype.merge;
|
|
21
|
+
module.exports.merge = merge;
|
|
22
|
+
const copy = Superconf.prototype.copy;
|
|
23
|
+
module.exports.copy = copy;
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "superconf",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Smart configuration loader",
|
|
5
5
|
"main": "app.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "
|
|
8
|
-
"lint": "
|
|
7
|
+
"test": "inspectio run",
|
|
8
|
+
"lint": "firelint",
|
|
9
|
+
"build": "firescript build"
|
|
9
10
|
},
|
|
10
11
|
"keywords": [
|
|
11
12
|
"conf",
|
|
@@ -15,19 +16,25 @@
|
|
|
15
16
|
"author": "Andifeind <andifeind@noname-media.com>",
|
|
16
17
|
"license": "MIT",
|
|
17
18
|
"devDependencies": {
|
|
18
|
-
"eslint": "^
|
|
19
|
-
"eslint-config-standard": "^
|
|
20
|
-
"eslint-plugin-import": "^2.
|
|
19
|
+
"eslint": "^8.23.1",
|
|
20
|
+
"eslint-config-standard": "^17.0.0",
|
|
21
|
+
"eslint-plugin-import": "^2.26.0",
|
|
21
22
|
"eslint-plugin-node": "^11.1.0",
|
|
22
|
-
"eslint-plugin-promise": "^
|
|
23
|
+
"eslint-plugin-promise": "^6.0.1",
|
|
23
24
|
"eslint-plugin-standard": "^5.0.0",
|
|
24
|
-
"
|
|
25
|
-
"
|
|
25
|
+
"firelint": "^0.10.0",
|
|
26
|
+
"firescript": "^0.21.1",
|
|
27
|
+
"firescript-test": "^0.11.10",
|
|
28
|
+
"inspect.js": "^1.13.1",
|
|
29
|
+
"inspectio": "^0.5.0",
|
|
30
|
+
"mocha": "^10.0.0"
|
|
26
31
|
},
|
|
27
32
|
"dependencies": {
|
|
28
|
-
"coffeescript": "^2.
|
|
33
|
+
"coffeescript": "^2.7.0",
|
|
34
|
+
"firescript-firefs": "^0.3.3",
|
|
35
|
+
"firescript-runtime": "^0.3.13",
|
|
29
36
|
"js-yaml": "^4.1.0",
|
|
30
|
-
"lagoon-reporter": "^0.7.
|
|
37
|
+
"lagoon-reporter": "^0.7.9"
|
|
31
38
|
},
|
|
32
39
|
"directories": {
|
|
33
40
|
"test": "tests"
|
|
@@ -39,5 +46,6 @@
|
|
|
39
46
|
"bugs": {
|
|
40
47
|
"url": "https://github.com/Andifeind/superconf/issues"
|
|
41
48
|
},
|
|
42
|
-
"homepage": "https://github.com/Andifeind/superconf#readme"
|
|
49
|
+
"homepage": "https://github.com/Andifeind/superconf#readme",
|
|
50
|
+
"firescript": "0.21.1"
|
|
43
51
|
}
|
package/.eslintrc.json
DELETED
package/.gitlab-ci.yml
DELETED
package/.travis.yml
DELETED
package/tests/.eslintrc
DELETED
package/tests/fixtures/.rctestrc
DELETED
package/tests/superconf.spec.js
DELETED
|
@@ -1,356 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const path = require('path')
|
|
4
|
-
|
|
5
|
-
const inspect = require('inspect.js')
|
|
6
|
-
const superconf = require('../app.js')
|
|
7
|
-
|
|
8
|
-
process.chdir(path.join(__dirname, '/fixtures/'))
|
|
9
|
-
|
|
10
|
-
describe('Superconf', () => {
|
|
11
|
-
describe('JSON', () => {
|
|
12
|
-
it('Should load a JSON conf', () => {
|
|
13
|
-
let conf = superconf('jsontest')
|
|
14
|
-
inspect(conf).isObject()
|
|
15
|
-
inspect(conf).isEql({
|
|
16
|
-
foo: 'bar',
|
|
17
|
-
bla: 'blub'
|
|
18
|
-
})
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
it('Should load a CSON conf', () => {
|
|
22
|
-
let conf = superconf('csontest')
|
|
23
|
-
inspect(conf).isObject()
|
|
24
|
-
inspect(conf).isEql({
|
|
25
|
-
foo: 'bar',
|
|
26
|
-
bla: 'blub'
|
|
27
|
-
})
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
it('Should load a YAML conf', () => {
|
|
31
|
-
let conf = superconf('yamltest')
|
|
32
|
-
inspect(conf).isObject()
|
|
33
|
-
inspect(conf).isEql({
|
|
34
|
-
foo: 'bar',
|
|
35
|
-
bla: 'blub'
|
|
36
|
-
})
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
it('Should load a YML conf', () => {
|
|
40
|
-
let conf = superconf('ymltest')
|
|
41
|
-
inspect(conf).isObject()
|
|
42
|
-
inspect(conf).isEql({
|
|
43
|
-
foo: 'bar',
|
|
44
|
-
bla: 'blub'
|
|
45
|
-
})
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
it('Should load a RC file', () => {
|
|
49
|
-
let conf = superconf('rctest')
|
|
50
|
-
inspect(conf).isObject()
|
|
51
|
-
inspect(conf).isEql({
|
|
52
|
-
foo: 'bar',
|
|
53
|
-
bla: 'blub'
|
|
54
|
-
})
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
it('Should load a JSON conf', () => {
|
|
58
|
-
let conf = superconf('rcjsontest')
|
|
59
|
-
inspect(conf).isObject()
|
|
60
|
-
inspect(conf).isEql({
|
|
61
|
-
foo: 'bar',
|
|
62
|
-
bla: 'blub'
|
|
63
|
-
})
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
it('Should load a CSON conf', () => {
|
|
67
|
-
let conf = superconf('rccsontest')
|
|
68
|
-
inspect(conf).isObject()
|
|
69
|
-
inspect(conf).isEql({
|
|
70
|
-
foo: 'bar',
|
|
71
|
-
bla: 'blub'
|
|
72
|
-
})
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
it('Should load a YAML conf', () => {
|
|
76
|
-
let conf = superconf('rcyamltest')
|
|
77
|
-
inspect(conf).isObject()
|
|
78
|
-
inspect(conf).isEql({
|
|
79
|
-
foo: 'bar',
|
|
80
|
-
bla: 'blub'
|
|
81
|
-
})
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
it('Should load a YML conf', () => {
|
|
85
|
-
let conf = superconf('rcymltest')
|
|
86
|
-
inspect(conf).isObject()
|
|
87
|
-
inspect(conf).isEql({
|
|
88
|
-
foo: 'bar',
|
|
89
|
-
bla: 'blub'
|
|
90
|
-
})
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
it('Should load a JSON conf', () => {
|
|
94
|
-
let conf = superconf('pkgtest')
|
|
95
|
-
inspect(conf).isObject()
|
|
96
|
-
inspect(conf).isEql({
|
|
97
|
-
foo: 'bar',
|
|
98
|
-
bla: 'blub'
|
|
99
|
-
})
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
it('Should load a JSON conf', () => {
|
|
103
|
-
let conf = superconf('pkgtest')
|
|
104
|
-
inspect(conf).isObject()
|
|
105
|
-
inspect(conf).isEql({
|
|
106
|
-
foo: 'bar',
|
|
107
|
-
bla: 'blub'
|
|
108
|
-
})
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
it('Should load a JSON from defaultConf', () => {
|
|
112
|
-
let conf = superconf('defaulttest', {
|
|
113
|
-
defaultConf: path.join(__dirname, './fixtures/defaultConf.json')
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
inspect(conf).isObject()
|
|
117
|
-
inspect(conf).isEql({
|
|
118
|
-
foo: 'bar',
|
|
119
|
-
bla: 'blub'
|
|
120
|
-
})
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
it('Should not load a JSON from defaultConf', () => {
|
|
124
|
-
let conf = superconf('defaulttest')
|
|
125
|
-
|
|
126
|
-
inspect(conf).isNull()
|
|
127
|
-
})
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
describe('merge()', function () {
|
|
131
|
-
it('Should merge object using Object.assign()', function () {
|
|
132
|
-
let left = {
|
|
133
|
-
fruit: 'Apple',
|
|
134
|
-
vegetable: 'Carrot'
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
let right = {
|
|
138
|
-
fruit: 'Banana',
|
|
139
|
-
vegetable: undefined
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
let conf = Object.assign(left, right)
|
|
143
|
-
inspect(conf).isEql({
|
|
144
|
-
fruit: 'Banana',
|
|
145
|
-
vegetable: undefined
|
|
146
|
-
})
|
|
147
|
-
})
|
|
148
|
-
|
|
149
|
-
it('Should merge config objects', function () {
|
|
150
|
-
let left = {
|
|
151
|
-
fruit: 'Apple',
|
|
152
|
-
vegetable: 'Carrot'
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
let right = {
|
|
156
|
-
fruit: 'Banana',
|
|
157
|
-
vegetable: undefined
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
let conf = superconf.merge(left, right)
|
|
161
|
-
inspect(conf).isEql({
|
|
162
|
-
fruit: 'Banana',
|
|
163
|
-
vegetable: 'Carrot'
|
|
164
|
-
})
|
|
165
|
-
})
|
|
166
|
-
|
|
167
|
-
it('Should overwrite objects', function () {
|
|
168
|
-
let left = {
|
|
169
|
-
fruit: 'Apple',
|
|
170
|
-
vegetables: {
|
|
171
|
-
red: 'Tomato',
|
|
172
|
-
green: 'Curcumber',
|
|
173
|
-
blue: 'Red cabbage'
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
let right = {
|
|
178
|
-
fruit: 'Banana',
|
|
179
|
-
vegetables: {
|
|
180
|
-
red: 'Capsicum'
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
let conf = superconf.merge(left, right)
|
|
185
|
-
inspect(conf).isEql({
|
|
186
|
-
fruit: 'Banana',
|
|
187
|
-
vegetables: {
|
|
188
|
-
red: 'Capsicum'
|
|
189
|
-
}
|
|
190
|
-
})
|
|
191
|
-
})
|
|
192
|
-
|
|
193
|
-
it('Should overwrite arrays', function () {
|
|
194
|
-
let left = {
|
|
195
|
-
fruit: 'Apple',
|
|
196
|
-
vegetables: [
|
|
197
|
-
'Tomato',
|
|
198
|
-
'Curcumber',
|
|
199
|
-
'Red cabbage'
|
|
200
|
-
]
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
let right = {
|
|
204
|
-
fruit: 'Banana',
|
|
205
|
-
vegetables: [
|
|
206
|
-
'Capsicum'
|
|
207
|
-
]
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
let conf = superconf.merge(left, right)
|
|
211
|
-
inspect(conf).isEql({
|
|
212
|
-
fruit: 'Banana',
|
|
213
|
-
vegetables: [
|
|
214
|
-
'Capsicum'
|
|
215
|
-
]
|
|
216
|
-
})
|
|
217
|
-
})
|
|
218
|
-
|
|
219
|
-
it('Should merge the first level together', function () {
|
|
220
|
-
let left = {
|
|
221
|
-
fruit: 'Apple',
|
|
222
|
-
vegetables: {
|
|
223
|
-
red: 'Tomato',
|
|
224
|
-
green: 'Curcumber',
|
|
225
|
-
blue: 'Red cabbage'
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
let right = {
|
|
230
|
-
fruit: 'Banana',
|
|
231
|
-
vegetables: {
|
|
232
|
-
red: 'Capsicum'
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
let conf = superconf.config({
|
|
237
|
-
dept: 1
|
|
238
|
-
}).merge(left, right)
|
|
239
|
-
|
|
240
|
-
inspect(conf).isEql({
|
|
241
|
-
fruit: 'Banana',
|
|
242
|
-
vegetables: {
|
|
243
|
-
red: 'Capsicum',
|
|
244
|
-
green: 'Curcumber',
|
|
245
|
-
blue: 'Red cabbage'
|
|
246
|
-
}
|
|
247
|
-
})
|
|
248
|
-
})
|
|
249
|
-
|
|
250
|
-
it('Should merge the first level together, using arrays', function () {
|
|
251
|
-
let left = {
|
|
252
|
-
fruit: 'Apple',
|
|
253
|
-
vegetables: {
|
|
254
|
-
red: [
|
|
255
|
-
'Tomato',
|
|
256
|
-
'Capsicum'
|
|
257
|
-
]
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
let right = {
|
|
262
|
-
fruit: 'Banana',
|
|
263
|
-
vegetables: {
|
|
264
|
-
green: [
|
|
265
|
-
'Curcumber'
|
|
266
|
-
]
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
let conf = superconf.config({
|
|
271
|
-
dept: 1
|
|
272
|
-
}).merge(left, right)
|
|
273
|
-
inspect(conf).isEql({
|
|
274
|
-
fruit: 'Banana',
|
|
275
|
-
vegetables: {
|
|
276
|
-
red: ['Tomato', 'Capsicum'],
|
|
277
|
-
green: ['Curcumber']
|
|
278
|
-
}
|
|
279
|
-
})
|
|
280
|
-
})
|
|
281
|
-
})
|
|
282
|
-
|
|
283
|
-
describe('copy()', () => {
|
|
284
|
-
it('copies a config object', () => {
|
|
285
|
-
const obj = {
|
|
286
|
-
foo: 'foo',
|
|
287
|
-
bar: 'bar',
|
|
288
|
-
bla: {
|
|
289
|
-
blub: 123
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
const copied = superconf.copy(obj)
|
|
294
|
-
inspect(copied).isEql(obj)
|
|
295
|
-
inspect(copied).isNotEqual(obj)
|
|
296
|
-
inspect(copied.bla).isNotEqual(obj.bla)
|
|
297
|
-
})
|
|
298
|
-
|
|
299
|
-
it('copies a config object with an array', () => {
|
|
300
|
-
const three = {
|
|
301
|
-
number: {
|
|
302
|
-
digit: 3
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
const obj = {
|
|
307
|
-
foo: 'foo',
|
|
308
|
-
bar: 'bar',
|
|
309
|
-
bla: [
|
|
310
|
-
'one',
|
|
311
|
-
'zwo',
|
|
312
|
-
three
|
|
313
|
-
]
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
const copied = superconf.copy(obj)
|
|
317
|
-
inspect(copied).isEql(obj)
|
|
318
|
-
inspect(copied).isNotEqual(obj)
|
|
319
|
-
inspect(copied.bla).isArray().hasLength(3)
|
|
320
|
-
inspect(copied.bla).isNotEqual(obj.bla)
|
|
321
|
-
inspect(copied.bla[2]).isEql(three).isNotEqual(three)
|
|
322
|
-
})
|
|
323
|
-
|
|
324
|
-
it('copies a config object with all existing shit', () => {
|
|
325
|
-
const three = {
|
|
326
|
-
number: {
|
|
327
|
-
digit: 3,
|
|
328
|
-
str: 'three',
|
|
329
|
-
used: null,
|
|
330
|
-
none: undefined
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
const obj = {
|
|
335
|
-
foo: 'foo',
|
|
336
|
-
bar: 'bar',
|
|
337
|
-
bla: [
|
|
338
|
-
'one',
|
|
339
|
-
'zwo',
|
|
340
|
-
three,
|
|
341
|
-
123,
|
|
342
|
-
null,
|
|
343
|
-
undefined,
|
|
344
|
-
['sub-one']
|
|
345
|
-
]
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
const copied = superconf.copy(obj)
|
|
349
|
-
inspect(copied).isEql(obj)
|
|
350
|
-
inspect(copied).isNotEqual(obj)
|
|
351
|
-
inspect(copied.bla).isArray().hasLength(7)
|
|
352
|
-
inspect(copied.bla).isNotEqual(obj.bla)
|
|
353
|
-
inspect(copied.bla[2]).isEql(three).isNotEqual(three)
|
|
354
|
-
})
|
|
355
|
-
})
|
|
356
|
-
})
|