diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f6b36f0..38cbb664 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). +#### [v1.4.5](https://github.com/CookPete/auto-changelog/compare/v1.4.4...v1.4.5) +> 27 February 2018 +- Correctly prefix package version [`#33`](https://github.com/CookPete/auto-changelog/issues/33) + #### [v1.4.4](https://github.com/CookPete/auto-changelog/compare/v1.4.3...v1.4.4) > 22 February 2018 - Do not show date for unreleased section [`#31`](https://github.com/CookPete/auto-changelog/issues/31) diff --git a/package.json b/package.json index b0a62b13..0a4b1c92 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "auto-changelog", - "version": "1.4.4", + "version": "1.4.5", "description": "Command line tool for generating a changelog from git tags and commit history", "bin": { "auto-changelog": "./lib/index.js" diff --git a/src/run.js b/src/run.js index 096ac1d9..a31d34de 100644 --- a/src/run.js +++ b/src/run.js @@ -52,7 +52,7 @@ function getOptions (argv, pkg) { } } -function getLatestVersion (options, pkg) { +function getLatestVersion (options, pkg, commits) { if (options.latestVersion) { if (!semver.valid(options.latestVersion)) { throw new Error('--latest-version must be a valid semver version') @@ -60,7 +60,8 @@ function getLatestVersion (options, pkg) { return options.latestVersion } if (options.package) { - return `v${pkg.version}` + const prefix = commits.some(c => /^v/.test(c.tag)) ? 'v' : '' + return `${prefix}${pkg.version}` } return null } @@ -70,7 +71,7 @@ export default async function run (argv) { const options = getOptions(argv, pkg) const remote = await fetchRemote(options.remote) const commits = await fetchCommits(remote, options) - const latestVersion = getLatestVersion(options, pkg) + const latestVersion = getLatestVersion(options, pkg, commits) const releases = parseReleases(commits, remote, latestVersion, options) const log = await compileTemplate(options.template, { releases }) await writeFile(options.output, log) diff --git a/test/run.js b/test/run.js index eec10318..a44f7b81 100644 --- a/test/run.js +++ b/test/run.js @@ -99,6 +99,25 @@ describe('run', () => { return run(['', '', '--package']) }) + it('uses version from package.json with no prefix', async () => { + mock('pathExists', () => true) + mock('readJson', () => ({ + version: '2.0.0' + })) + mock('fetchCommits', () => commits.map(commit => { + return { + ...commit, + tag: commit.tag ? commit.tag.replace('v', '') : null + } + })) + mock('writeFile', (output, log) => { + expect(log).to.include('2.0.0') + expect(log).to.not.include('v2.0.0') + }) + + return run(['', '', '--package']) + }) + it('command line options override options from package.json', async () => { mock('pathExists', () => true) mock('readJson', () => ({