forked from conventional-changelog/standard-version
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(configuration): .versionrc.js files are now supported (conventi…
…onal-changelog#378) * feat(configuration): .versionrc.js files are now supported - Updates the configuration retrieval to support Javascript (`.js`) configurations. - Javascript configurations MUST export a configuration object _or_ a function (returning a configuration object) as the default export. closes conventional-changelog#371 * docs: Updates README to include details for the new '.versionrc.js' support * fix: updates error message to be a bit more descriptive and helpful.
- Loading branch information
1 parent
36f85c6
commit ddc5c00
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