Skip to content

feat: Expose release count option #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,27 @@ If you've already run `commit-and-tag-version` when creating your release, you m
the version, by using `commit-and-tag-version --skip.bump`. By default, tagging with an already existing tag make `git` fails.
You can add the `--tag-force` flag to make use of `-f` option when calling `git tag`, then the existing version tag will be replaced.

### Generate changelogs for old releases

Normally only the changelog for the last release will be generated and prepended to the `changelog.md`. If you want to generate changelogs for previous releases you can do so by setting the `releaseCount` option like described [here](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-core#releasecount).

When setting releaseCount=0 the whole changelog gets regenerated and replaced.

You can set the option either in the`.versionrc` file or inside `package.json` like below

```json
//.versionrc
{
"releaseCount": 0
}

//package.json

"commit-and-tag-version": {
"releaseCount": 0
}
```

### CLI Help

```sh
Expand Down
5 changes: 5 additions & 0 deletions command.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ const yargs = require('yargs')
type: 'string',
default: defaults.tagPrefix
})
.option('release-count', {
describe: 'How many releases of changelog you want to generate. It counts from the upcoming release. Useful when you forgot to generate any previous changelog. Set to 0 to regenerate all.',
type: 'number',
default: defaults.releaseCount
})
.option('tag-force', {
describe: 'Allow tag replacement',
type: 'boolean',
Expand Down
1 change: 1 addition & 0 deletions defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const defaults = {
commitAll: false,
silent: false,
tagPrefix: 'v',
releaseCount: 1,
scripts: {},
skip: {},
dryRun: false,
Expand Down
5 changes: 3 additions & 2 deletions lib/lifecycles/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function outputChangelog (args, newVersion) {
createIfMissing(args)
const header = args.header

let oldContent = args.dryRun ? '' : fs.readFileSync(args.infile, 'utf-8')
let oldContent = args.dryRun || args.releaseCount === 0 ? '' : fs.readFileSync(args.infile, 'utf-8')
const oldContentStart = oldContent.search(START_OF_LAST_RELEASE_PATTERN)
// find the position of the last release and remove header:
if (oldContentStart !== -1) {
Expand All @@ -34,7 +34,8 @@ function outputChangelog (args, newVersion) {
const changelogStream = conventionalChangelog({
debug: args.verbose && console.info.bind(console, 'conventional-changelog'),
preset: presetLoader(args),
tagPrefix: args.tagPrefix
tagPrefix: args.tagPrefix,
releaseCount: args.releaseCount
}, context, { merges: null, path: args.path }, args.parserOpts, args.writerOpts)
.on('error', function (err) {
return reject(err)
Expand Down