-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.js
53 lines (44 loc) · 1.12 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
const path = require('path')
const fs = require('fs')
const DEFAULT_CONFIG = require('./default-config')
function deepMerge (dst, src) {
for (const [k, v] of Object.entries(src)) {
if (dst[k]) {
if (Array.isArray(dst[k])) {
dst[k] = [
...dst[k],
...(Array.isArray(v) ? v : [v]),
]
} else if (typeof dst[k] === 'object') {
deepMerge(dst[k], v)
} else {
dst[k] = v
}
} else {
dst[k] = v
}
}
return dst
}
function getConfig (root) {
let config = {}
let pkg = {}
if (fs.existsSync(path.join(root, 'package.json'))) {
pkg = require(path.join(root, 'package.json'))
}
if (fs.existsSync(path.join(root, 'git-publisher.js'))) {
config = require(path.join(root, 'git-publisher.js'))
} else if (fs.existsSync(path.join(root, 'git-publisher.yaml'))) {
config = require('js-yaml').safeLoad(fs.readFileSync(path.resolve(root, 'git-publisher.yaml'), 'utf8'))
} else {
config = pkg.gitPublisher || {}
}
return {
...deepMerge(DEFAULT_CONFIG, config),
pkg,
}
}
module.exports = {
getConfig,
deepMerge,
}