superconf 1.2.3 → 1.3.0

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 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 ADDED
@@ -0,0 +1,23 @@
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);
18
+ }
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,10 +1,12 @@
1
1
  {
2
2
  "name": "superconf",
3
- "version": "1.2.3",
3
+ "version": "1.3.0",
4
4
  "description": "Smart configuration loader",
5
- "main": "index.js",
5
+ "main": "app.js",
6
6
  "scripts": {
7
- "test": "mocha --recursive tests/*.spec.js"
7
+ "test": "inspectio run",
8
+ "lint": "firelint",
9
+ "build": "firescript build"
8
10
  },
9
11
  "keywords": [
10
12
  "conf",
@@ -14,19 +16,24 @@
14
16
  "author": "Andifeind <andifeind@noname-media.com>",
15
17
  "license": "MIT",
16
18
  "devDependencies": {
17
- "eslint": "^6.1.0",
18
- "eslint-config-standard": "^13.0.1",
19
- "eslint-plugin-import": "^2.18.2",
20
- "eslint-plugin-node": "^9.1.0",
21
- "eslint-plugin-promise": "^4.2.1",
22
- "eslint-plugin-standard": "^4.0.0",
23
- "inspect.js": "^1.11.8",
24
- "mocha": "^6.2.0"
19
+ "eslint": "^8.23.1",
20
+ "eslint-config-standard": "^17.0.0",
21
+ "eslint-plugin-import": "^2.26.0",
22
+ "eslint-plugin-node": "^11.1.0",
23
+ "eslint-plugin-promise": "^6.0.1",
24
+ "eslint-plugin-standard": "^5.0.0",
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"
25
31
  },
26
32
  "dependencies": {
27
- "coffeescript": "^2.4.1",
28
- "js-yaml": "^3.13.1",
29
- "lagoon-reporter": "^0.7.5"
33
+ "coffeescript": "^2.7.0",
34
+ "firescript-runtime": "^0.3.13",
35
+ "js-yaml": "^4.1.0",
36
+ "lagoon-reporter": "^0.7.9"
30
37
  },
31
38
  "directories": {
32
39
  "test": "tests"
@@ -38,5 +45,6 @@
38
45
  "bugs": {
39
46
  "url": "https://github.com/Andifeind/superconf/issues"
40
47
  },
41
- "homepage": "https://github.com/Andifeind/superconf#readme"
48
+ "homepage": "https://github.com/Andifeind/superconf#readme",
49
+ "firescript": "0.21.1"
42
50
  }
package/.eslintrc DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "extends": "standard"
3
- }
package/.gitlab-ci.yml DELETED
@@ -1,19 +0,0 @@
1
- image: node:6
2
- stages:
3
- - test
4
- - publish
5
-
6
- test:
7
- stage: test
8
- before_script:
9
- - npm install
10
- script:
11
- - npm run test
12
-
13
- publish:
14
- stage: publish
15
- only:
16
- - /^v\d+\.\d+\.\d+$/
17
- script:
18
- - echo "//registry.npmjs.org/:_authToken=$NPM_AUTH_TOKEN" >> ~/.npmrc
19
- - npm publish
package/.npmignore DELETED
@@ -1,2 +0,0 @@
1
- node_modules/
2
- log/
package/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- language: node_js
2
- node_js:
3
- - "6"
4
- - "7"
5
- - "8"
6
- - "9"
7
- - "10"