Skip to content

Commit

Permalink
feat(presets): add support for '.versionrc' customized presets
Browse files Browse the repository at this point in the history
  • Loading branch information
Loïs Bégué committed Apr 28, 2020
1 parent 6ecf98d commit 437a144
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
21 changes: 11 additions & 10 deletions .versionrc
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"types": [
{"type":"feat","section":"Features"},
{"type":"fix","section":"Bug Fixes"},
{"type":"docs","section":"Documentation", "hidden": false},
{"type":"chore","section":"Modification of the app structure/core", "hidden": false},
{"type":"test","section":"Tests", "hidden": true},
{"type":"build","section":"Build System", "hidden": false},
{"type": "style", "hidden": true},
{"type": "refactor", "hidden": true},
{"type": "perf", "hidden": true},
{"type":"ci","hidden":true}
{"type": "feat", "section":"Features"},
{"type": "fix", "section":"Bug Fixes"},
{"type": "chore", "section":"Chore"},
{"type": "docs", "section":"Documentation"},

{"type": "test", "section":"Tests", "hidden": true},
{"type": "build", "section":"Build System", "hidden": true},
{"type": "style", "section":"Styling", "hidden": true},
{"type": "refactor", "section":"Refactoring", "hidden": true},
{"type": "perf", "section":"Performance", "hidden": true},
{"type": "ci", "section":"CI/CD", "hidden":true}
]
}
17 changes: 14 additions & 3 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,26 @@ module.exports = function(grunt) {
},
version: {
options: {
preset: 'angular',
header: '# grunt-standard-version changelog\n\nAll notable changes to this project will be documented in this file. See [grunt-standard-version](https://github.com/khatastroffik/grunt-standard-version).\n\n'
dryRun: true,
header: '# grunt-standard-version changelog\n\nAll notable changes to this project will be documented in this file. See [grunt-standard-version](https://github.com/khatastroffik/grunt-standard-version).\n\n',
}
},
test: {
options: {
dryRun: true,
header: "# TEST HEADER\nThis is a test changelog\n\n",
types: [
{"type": "feat", "section": "TEST Features"},
{"type": "fix", "section": "TEST Bug Fixes"},
{"type": "chore", "section": "TEST Chore"},
{"type": "docs", "section": "TEST Documentation"},
{"type": "style", "section": "TEST Style"},
{"type": "refactor", "section": "TEST Refactoring"},
{"type": "perf", "section": "TEST Performance"},
{"type": "test", "section": "TEST Tests"}
]
}
}

},
nodeunit: {
tests: ['test/*_test.js']
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,18 @@ Overview:

Further details: see [standard-version default configuration](https://github.com/conventional-changelog/standard-version/blob/master/defaults.js) and [standard-version commands](https://github.com/conventional-changelog/standard-version/blob/master/command.js) among others.

### Example
### Usage of the `.versionrc` (and alternatives) configuration

The [conventional-change-spec](https://github.com/conventional-changelog/conventional-changelog-config-spec/blob/master/versions/2.1.0/README.md) v2.1.0 (adopted by standard-version) defines configuration options applicable to the presets i.e. each preset may define it's own "taste" according to the spec.

To apply a **custom spec** i.e. to define a *custom rule set*, you may create a `.versionrc` file in the same directory as the `Gruntfile.js`.
See *standard-version* [Configuration](https://github.com/conventional-changelog/standard-version#configuration) documentation.

**grunt-standard-version** will *merge the 'versionrc' custom rule set* with the task configuration in the `Gruntfile.js`. Rules defined in the gruntfile take absolute precedence over the versionrc configuration. This matches with the CLI behavior.

Note: the option `header` defined in the **conventional-change-spec** (see above) is *not respected by standard-version 7.1.0*. Instead, `header` is defined as a *root option* by standard-version. This may change in the future (fix?). See the configuration example below.

### Gruntfile Configuration Example

This is an example of the **standardVersion** task configuration using a target named "version".

Expand Down
5 changes: 4 additions & 1 deletion tasks/standardVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

'use strict';
var standard_version = require('standard-version');
const { getConfiguration } = require('standard-version/lib/configuration');

/*
===================================================================
Expand Down Expand Up @@ -42,10 +43,12 @@ var DEFAULT_OPTIONS = {
};

module.exports = function (grunt) {

grunt.registerMultiTask('standardVersion', 'bump your package version, update CHANGELOG and stage both', function () {

var done = this.async();
var opt = this.options(DEFAULT_OPTIONS);
var localVersionReleaseConfig = getConfiguration();
var opt = this.options( {...DEFAULT_OPTIONS, ...localVersionReleaseConfig} );

function handleError(err) {
if (opt.continueIfError) {
Expand Down

0 comments on commit 437a144

Please sign in to comment.