Skip to content

Commit 3bbba02

Browse files
authored
feat: allows seperate prefixTag version sequences (#573)
1 parent f5bff12 commit 3bbba02

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ module.exports = async function standardVersion (argv) {
5656
if (pkg) {
5757
version = pkg.version
5858
} else if (args.gitTagFallback) {
59-
version = await latestSemverTag()
59+
version = await latestSemverTag(args.tagPrefix)
6060
} else {
6161
throw new Error('no package file found')
6262
}

lib/latest-semver-tag.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
const gitSemverTags = require('git-semver-tags')
22
const semver = require('semver')
33

4-
module.exports = function () {
4+
module.exports = function (tagPrefix = undefined) {
55
return new Promise((resolve, reject) => {
6-
gitSemverTags(function (err, tags) {
6+
gitSemverTags({ tagPrefix }, function (err, tags) {
77
if (err) return reject(err)
88
else if (!tags.length) return resolve('1.0.0')
9+
// Respect tagPrefix
10+
tags = tags.map(tag => tag.replace(new RegExp('^' + tagPrefix), ''))
911
// ensure that the largest semver tag is at the head.
1012
tags = tags.map(tag => { return semver.clean(tag) })
1113
tags.sort(semver.rcompare)

test/git.spec.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function mock ({ bump, changelog, tags }) {
6666
}
6767
}))
6868

69-
mockery.registerMock('git-semver-tags', function (cb) {
69+
mockery.registerMock('git-semver-tags', function (_, cb) {
7070
if (tags instanceof Error) cb(tags)
7171
else cb(null, tags || [])
7272
})
@@ -103,6 +103,29 @@ describe('git', function () {
103103
}
104104
})
105105

106+
describe('tagPrefix', () => {
107+
// TODO: Use unmocked git-semver-tags and stage a git environment
108+
it('will add prefix onto tag based on version from package', async function () {
109+
writePackageJson('1.2.0')
110+
mock({ bump: 'minor', tags: ['p-v1.2.0'] })
111+
await exec('--tag-prefix p-v')
112+
shell.exec('git tag').stdout.should.match(/p-v1\.3\.0/)
113+
})
114+
115+
it('will add prefix onto tag via when gitTagFallback is true and no package [cli]', async function () {
116+
shell.rm('package.json')
117+
mock({ bump: 'minor', tags: ['android/production/v1.2.0', 'android/production/v1.0.0'] })
118+
await exec('--tag-prefix android/production/v')
119+
shell.exec('git tag').stdout.should.match(/android\/production\/v1\.3\.0/)
120+
})
121+
122+
it('will add prefix onto tag via when gitTagFallback is true and no package [options]', async function () {
123+
mock({ bump: 'minor', tags: ['android/production/v1.2.0', 'android/production/v1.0.0'] })
124+
await exec({ tagPrefix: 'android/production/v', packageFiles: [] })
125+
shell.exec('git tag').stdout.should.match(/android\/production\/v1\.3\.0/)
126+
})
127+
})
128+
106129
it('formats the commit and tag messages appropriately', async function () {
107130
mock({ bump: 'minor', tags: ['v1.0.0'] })
108131
await exec({})

0 commit comments

Comments
 (0)