-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.js
35 lines (30 loc) · 883 Bytes
/
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
const { readFileSync } = require('fs')
const { red } = require('ansi-colors')
const { config } = require('./config.default')
module.exports.loadConfig = () => {
let code
let userConfig
try {
code = readFileSync('trimmings.config.js', 'utf-8')
} catch (error) {} // silent fail
if (code) {
try {
code = code.replace(/ +/g, ' ').replace('export default', 'module.exports =')
const Module = module.constructor
const mod = new Module()
mod._compile(code, 'trimmings.config.js')
userConfig = mod.exports
} catch (error) {
console.log('~>', red('Your config file is not formatted properly. Please fix it.'))
process.exit()
}
// override with user config
// TODO: check the sanity of the config?
for (const key in config) {
if (userConfig[key]) {
config[key] = Object.assign({}, config[key], userConfig[key])
}
}
}
return config
}