From f86210aeea59de361fd93b680fcb05d0bf9e05f8 Mon Sep 17 00:00:00 2001 From: Mateus Mamede Lage Date: Wed, 1 Sep 2021 11:59:10 -0400 Subject: [PATCH 1/4] feat: add parser options --- command.js | 4 ++++ index.js | 9 +++++++++ lib/lifecycles/bump.js | 2 +- lib/lifecycles/changelog.js | 2 +- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/command.js b/command.js index d65d5ea06..5d44798e3 100755 --- a/command.js +++ b/command.js @@ -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' diff --git a/index.js b/index.js index 3a35555fc..91ff4c61f 100755 --- a/index.js +++ b/index.js @@ -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) { diff --git a/lib/lifecycles/bump.js b/lib/lifecycles/bump.js index 370fbff03..f13641e5a 100644 --- a/lib/lifecycles/bump.js +++ b/lib/lifecycles/bump.js @@ -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) }) diff --git a/lib/lifecycles/changelog.js b/lib/lifecycles/changelog.js index b52f529c0..b521b499f 100644 --- a/lib/lifecycles/changelog.js +++ b/lib/lifecycles/changelog.js @@ -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) }) From e6284963331c34bc9197e21d46509c53a99118b1 Mon Sep 17 00:00:00 2001 From: Mateus Mamede Lage Date: Wed, 1 Sep 2021 11:59:20 -0400 Subject: [PATCH 2/4] docs: parser options --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index f924f6073..6628fd3f0 100644 --- a/README.md +++ b/README.md @@ -313,6 +313,25 @@ 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 +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 From 3e4e34ab2cbf68564e77fbc95b5ad45f2ed4b071 Mon Sep 17 00:00:00 2001 From: Mateus Mamede Lage Date: Wed, 1 Sep 2021 12:23:58 -0400 Subject: [PATCH 3/4] docs: adds type to export --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 6628fd3f0..3af84ae61 100644 --- a/README.md +++ b/README.md @@ -324,6 +324,7 @@ 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'] From a28b2ca6b6fed49934ce0d9171fa54ec370819eb Mon Sep 17 00:00:00 2001 From: mmamedel Date: Fri, 12 Nov 2021 22:46:14 -0500 Subject: [PATCH 4/4] Update README.md Co-authored-by: Naimah Nash --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3af84ae61..12d57bfcc 100644 --- a/README.md +++ b/README.md @@ -318,7 +318,7 @@ If you do not want to have any tag prefix you can use the `-t` flag and provide 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 +standard-version --parser-opts ./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: