Skip to content

Commit d862d4a

Browse files
authored
Merge pull request #53 from lucahuettner/feat/expose-release-count-opt
feat: Expose release count option
2 parents 7fbc106 + 6dfde4e commit d862d4a

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,27 @@ If you've already run `commit-and-tag-version` when creating your release, you m
343343
the version, by using `commit-and-tag-version --skip.bump`. By default, tagging with an already existing tag make `git` fails.
344344
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.
345345

346+
### Generate changelogs for old releases
347+
348+
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).
349+
350+
When setting releaseCount=0 the whole changelog gets regenerated and replaced.
351+
352+
You can set the option either in the`.versionrc` file or inside `package.json` like below
353+
354+
```json
355+
//.versionrc
356+
{
357+
"releaseCount": 0
358+
}
359+
360+
//package.json
361+
362+
"commit-and-tag-version": {
363+
"releaseCount": 0
364+
}
365+
```
366+
346367
### CLI Help
347368

348369
```sh

command.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ const yargs = require('yargs')
7373
type: 'string',
7474
default: defaults.tagPrefix
7575
})
76+
.option('release-count', {
77+
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.',
78+
type: 'number',
79+
default: defaults.releaseCount
80+
})
7681
.option('tag-force', {
7782
describe: 'Allow tag replacement',
7883
type: 'boolean',

defaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const defaults = {
88
commitAll: false,
99
silent: false,
1010
tagPrefix: 'v',
11+
releaseCount: 1,
1112
scripts: {},
1213
skip: {},
1314
dryRun: false,

lib/lifecycles/changelog.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function outputChangelog (args, newVersion) {
2323
createIfMissing(args)
2424
const header = args.header
2525

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

0 commit comments

Comments
 (0)