Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
94 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters