forked from conventional-changelog/standard-version
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configuration.js
39 lines (35 loc) · 989 Bytes
/
configuration.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
const path = require('path')
const findUp = require('find-up')
const { readFileSync } = require('fs')
const CONFIGURATION_FILES = [
'.versionrc',
'.versionrc.json',
'.versionrc.js'
]
module.exports.getConfiguration = function () {
let config = {}
const configPath = findUp.sync(CONFIGURATION_FILES)
if (!configPath) {
return config
}
if (path.extname(configPath) === '.js') {
const jsConfiguration = require(configPath)
if (typeof jsConfiguration === 'function') {
config = jsConfiguration()
} else {
config = jsConfiguration
}
} else {
config = JSON.parse(readFileSync(configPath))
}
/**
* @todo we could eventually have deeper validation of the configuration (using `ajv`) and
* provide a more helpful error.
*/
if (typeof config !== 'object') {
throw Error(
`[standard-version] Invalid configuration in ${configPath} provided. Expected an object but found ${typeof config}.`
)
}
return config
}