Skip to content

Commit

Permalink
Feat add parser opts conventional-changelog#821
Browse files Browse the repository at this point in the history
  • Loading branch information
Taras Kuprunets committed Sep 29, 2021
1 parent ca5ab8f commit 6808b23
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,26 @@ If you do not want to have any tag prefix you can use the `-t` flag and provide

> Note: simply -t or --tag-prefix without any value will fallback to the default 'v'
### Parser Options

If you need to include custom parser options to read your commits, you can use the `--parser-opts` to indicate the path to a .js file that exports the options.

```sh
standard-version --parser-options ./parser-opts.js
```

This can be useful in cases like Azure DevOps that uses custom merge pull request titles. The `parser-opts.js` could look like this:

```js
/** @type {import("conventional-commits-parser").Options} */
module.exports = {
mergePattern: /^Merged PR (\d+): (\w*)(?:\(([\w\$\.\-\* ]*)\))?\: (.*)$/,
mergeCorrespondence: ['id', 'type', 'scope', 'subject']
}
```

For more informantion on what parser options are available, reference to [documentation](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-commits-parser).

### CLI Help

```sh
Expand Down
4 changes: 4 additions & 0 deletions command.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ const yargs = require('yargs')
default: defaults.preset,
describe: 'Commit message guideline preset'
})
.option('parser-opts', {
type: 'string',
describe: 'Path to file with Conventional Commits Parser Options'
})
.option('lerna-package', {
type: 'string',
describe: 'Name of the package from which the tags will be extracted'
Expand Down
9 changes: 9 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ module.exports = async function standardVersion (argv) {
throw Error(`custom changelog header must not match ${changelog.START_OF_LAST_RELEASE_PATTERN}`)
}

if (typeof argv.parserOpts === 'string') {
const parserOptsPath = path.resolve(argv.parserOpts)
try {
argv.parserOpts = require(parserOptsPath)
} catch(err) {
argv.parserOpts = null
}
}

const args = Object.assign({}, defaults, argv)
let pkg
for (const packageFile of args.packageFiles) {
Expand Down
2 changes: 1 addition & 1 deletion lib/lifecycles/bump.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function bumpVersion (releaseAs, currentVersion, args) {
path: args.path,
tagPrefix: args.tagPrefix,
lernaPackage: args.lernaPackage
}, function (err, release) {
}, args.parserOpts, function (err, release) {
if (err) return reject(err)
else return resolve(release)
})
Expand Down
2 changes: 1 addition & 1 deletion lib/lifecycles/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function outputChangelog (args, newVersion) {
debug: args.verbose && console.info.bind(console, 'conventional-changelog'),
preset: presetLoader(args),
tagPrefix: args.tagPrefix
}, context, { merges: null, path: args.path })
}, context, { merges: null, path: args.path }, args.parserOpts)
.on('error', function (err) {
return reject(err)
})
Expand Down

0 comments on commit 6808b23

Please sign in to comment.