Skip to content

Commit 6808b23

Browse files
author
Taras Kuprunets
committed
Feat add parser opts conventional-changelog#821
1 parent ca5ab8f commit 6808b23

File tree

5 files changed

+35
-2
lines changed

5 files changed

+35
-2
lines changed

README.md

+20
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,26 @@ If you do not want to have any tag prefix you can use the `-t` flag and provide
313313

314314
> Note: simply -t or --tag-prefix without any value will fallback to the default 'v'
315315
316+
### Parser Options
317+
318+
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.
319+
320+
```sh
321+
standard-version --parser-options ./parser-opts.js
322+
```
323+
324+
This can be useful in cases like Azure DevOps that uses custom merge pull request titles. The `parser-opts.js` could look like this:
325+
326+
```js
327+
/** @type {import("conventional-commits-parser").Options} */
328+
module.exports = {
329+
mergePattern: /^Merged PR (\d+): (\w*)(?:\(([\w\$\.\-\* ]*)\))?\: (.*)$/,
330+
mergeCorrespondence: ['id', 'type', 'scope', 'subject']
331+
}
332+
```
333+
334+
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).
335+
316336
### CLI Help
317337

318338
```sh

command.js

+4
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ const yargs = require('yargs')
9999
default: defaults.preset,
100100
describe: 'Commit message guideline preset'
101101
})
102+
.option('parser-opts', {
103+
type: 'string',
104+
describe: 'Path to file with Conventional Commits Parser Options'
105+
})
102106
.option('lerna-package', {
103107
type: 'string',
104108
describe: 'Name of the package from which the tags will be extracted'

index.js

+9
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ module.exports = async function standardVersion (argv) {
3737
throw Error(`custom changelog header must not match ${changelog.START_OF_LAST_RELEASE_PATTERN}`)
3838
}
3939

40+
if (typeof argv.parserOpts === 'string') {
41+
const parserOptsPath = path.resolve(argv.parserOpts)
42+
try {
43+
argv.parserOpts = require(parserOptsPath)
44+
} catch(err) {
45+
argv.parserOpts = null
46+
}
47+
}
48+
4049
const args = Object.assign({}, defaults, argv)
4150
let pkg
4251
for (const packageFile of args.packageFiles) {

lib/lifecycles/bump.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ function bumpVersion (releaseAs, currentVersion, args) {
122122
path: args.path,
123123
tagPrefix: args.tagPrefix,
124124
lernaPackage: args.lernaPackage
125-
}, function (err, release) {
125+
}, args.parserOpts, function (err, release) {
126126
if (err) return reject(err)
127127
else return resolve(release)
128128
})

lib/lifecycles/changelog.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function outputChangelog (args, newVersion) {
3636
debug: args.verbose && console.info.bind(console, 'conventional-changelog'),
3737
preset: presetLoader(args),
3838
tagPrefix: args.tagPrefix
39-
}, context, { merges: null, path: args.path })
39+
}, context, { merges: null, path: args.path }, args.parserOpts)
4040
.on('error', function (err) {
4141
return reject(err)
4242
})

0 commit comments

Comments
 (0)