Skip to content

Commit

Permalink
Correctly prefix package version
Browse files Browse the repository at this point in the history
Fixes #33
  • Loading branch information
cookpete committed Feb 27, 2018
1 parent 7fe4dba commit 91dfb42
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,16 @@ 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')
}
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
}
Expand All @@ -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)
Expand Down
19 changes: 19 additions & 0 deletions test/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => ({
Expand Down

0 comments on commit 91dfb42

Please sign in to comment.