Skip to content
This repository has been archived by the owner on May 20, 2024. It is now read-only.

Commit

Permalink
[modules] improve changelog-version
Browse files Browse the repository at this point in the history
  • Loading branch information
ArmorDarks committed Mar 30, 2018
1 parent 76948a2 commit 4273f87
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions modules/changelog-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,23 @@ const updateChangelogVersion = ({
changelogFilename = 'CHANGELOG.md',
repositoryURL = pkg.repository.url,
date = moment().format('YYYY-MM-DD'),
headPattern = /^## \[?(HEAD|Unreleased)\]?$/m,
headPattern = /^## \[?(HEAD|Unreleased)\]?.+$/m,
versionPattern = /^## \[?(\d+\.\d+\.\d+)/m
} = {}) => {
if (!version) {
logError('[changelog-version] please, specify `package.json` `version` property')
process.exit(1)
}

if (!repositoryURL || !repositoryURL.includes('github.com') || !repositoryURL.endsWith('.git')) {
if (!repositoryURL || !repositoryURL.includes('github.com')) {
logError('[changelog-version] please, specify `package.json` `repository.url` property with a valid Github URL')
process.exit(1)
}

if (repositoryURL.endsWith('.git')) {
repositoryURL = repositoryURL.slice(0, -4)
}

readFile(changelogFilename, { encoding: 'utf-8' }, (error, changelog) => {
if (error) return console.log(`[changelog-version] seems to be no ${changelogFilename}, skipping changelog version update`)

Expand All @@ -60,8 +64,8 @@ const updateChangelogVersion = ({
const releaseHeader = `## [${version}](${repositoryURL}/compare/v${previousVersion}...v${version}) - ${date}`
const newHEADHeader = `## [HEAD](${repositoryURL}/compare/v${version}...HEAD)`
const updatedChangelog = changelog
.replace(headPattern, `${newHEADHeader}\n\n## HEAD`)
.replace(headPattern, releaseHeader)
.replace(headPattern, `${newHEADHeader}\n\n## __RELEASE_HEADER__`)
.replace(/^## __RELEASE_HEADER__$/m, releaseHeader)

writeFileSync(changelogFilename, updatedChangelog)

Expand Down

0 comments on commit 4273f87

Please sign in to comment.