Skip to content

Commit

Permalink
feat: allows seperate prefixTag version sequences (conventional-chang…
Browse files Browse the repository at this point in the history
  • Loading branch information
jahead authored Apr 6, 2021
1 parent f5bff12 commit 3bbba02
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ module.exports = async function standardVersion (argv) {
if (pkg) {
version = pkg.version
} else if (args.gitTagFallback) {
version = await latestSemverTag()
version = await latestSemverTag(args.tagPrefix)
} else {
throw new Error('no package file found')
}
Expand Down
6 changes: 4 additions & 2 deletions lib/latest-semver-tag.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
const gitSemverTags = require('git-semver-tags')
const semver = require('semver')

module.exports = function () {
module.exports = function (tagPrefix = undefined) {
return new Promise((resolve, reject) => {
gitSemverTags(function (err, tags) {
gitSemverTags({ tagPrefix }, function (err, tags) {
if (err) return reject(err)
else if (!tags.length) return resolve('1.0.0')
// Respect tagPrefix
tags = tags.map(tag => tag.replace(new RegExp('^' + tagPrefix), ''))
// ensure that the largest semver tag is at the head.
tags = tags.map(tag => { return semver.clean(tag) })
tags.sort(semver.rcompare)
Expand Down
25 changes: 24 additions & 1 deletion test/git.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function mock ({ bump, changelog, tags }) {
}
}))

mockery.registerMock('git-semver-tags', function (cb) {
mockery.registerMock('git-semver-tags', function (_, cb) {
if (tags instanceof Error) cb(tags)
else cb(null, tags || [])
})
Expand Down Expand Up @@ -103,6 +103,29 @@ describe('git', function () {
}
})

describe('tagPrefix', () => {
// TODO: Use unmocked git-semver-tags and stage a git environment
it('will add prefix onto tag based on version from package', async function () {
writePackageJson('1.2.0')
mock({ bump: 'minor', tags: ['p-v1.2.0'] })
await exec('--tag-prefix p-v')
shell.exec('git tag').stdout.should.match(/p-v1\.3\.0/)
})

it('will add prefix onto tag via when gitTagFallback is true and no package [cli]', async function () {
shell.rm('package.json')
mock({ bump: 'minor', tags: ['android/production/v1.2.0', 'android/production/v1.0.0'] })
await exec('--tag-prefix android/production/v')
shell.exec('git tag').stdout.should.match(/android\/production\/v1\.3\.0/)
})

it('will add prefix onto tag via when gitTagFallback is true and no package [options]', async function () {
mock({ bump: 'minor', tags: ['android/production/v1.2.0', 'android/production/v1.0.0'] })
await exec({ tagPrefix: 'android/production/v', packageFiles: [] })
shell.exec('git tag').stdout.should.match(/android\/production\/v1\.3\.0/)
})
})

it('formats the commit and tag messages appropriately', async function () {
mock({ bump: 'minor', tags: ['v1.0.0'] })
await exec({})
Expand Down

0 comments on commit 3bbba02

Please sign in to comment.