Skip to content

Commit

Permalink
fix: prevent duplicate headers from being added (conventional-changel…
Browse files Browse the repository at this point in the history
  • Loading branch information
jthomerson committed Feb 25, 2019
1 parent 3423bfb commit 44f6381
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/lifecycles/changelog.js
Expand Up @@ -5,6 +5,7 @@ const conventionalChangelog = require('conventional-changelog')
const fs = require('fs')
const runLifecycleScript = require('../run-lifecycle-script')
const writeFile = require('../write-file')
const START_OF_LAST_RELEASE_PATTERN = /(^##? (?!Change Log$)|<a name=)/m

module.exports = function (args, newVersion) {
if (args.skip.changelog) return Promise.resolve()
Expand All @@ -22,9 +23,10 @@ function outputChangelog (args, newVersion) {
createIfMissing(args)
var header = '# Change Log\n\nAll notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.\n'
var oldContent = args.dryRun ? '' : fs.readFileSync(args.infile, 'utf-8')
var oldContentStart = oldContent.search(START_OF_LAST_RELEASE_PATTERN)
// find the position of the last release and remove header:
if (oldContent.indexOf('<a name=') !== -1) {
oldContent = oldContent.substring(oldContent.indexOf('<a name='))
if (oldContentStart !== -1) {
oldContent = oldContent.substring(oldContentStart)
}
var content = ''
var context
Expand Down

0 comments on commit 44f6381

Please sign in to comment.