From 13eb9cd47d780f90938c1c447a31149d2f02baea Mon Sep 17 00:00:00 2001 From: Steve Mao Date: Sun, 28 May 2017 08:18:43 +1000 Subject: [PATCH] feat: allow a version # to be provided for release-as, rather than just major, minor, patch. --- README.md | 2 ++ command.js | 1 - index.js | 2 +- test.js | 28 ++++++++++++++++++++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7d28fe3d8..396ff4573 100644 --- a/README.md +++ b/README.md @@ -129,6 +129,8 @@ you would like your next release to be a `minor`. Simply do: ```bash # npm run script npm run release -- --release-as minor +# Or +npm run release -- --release-as 1.1.0 ``` you will get version `1.1.0` rather than the auto generated version `1.0.1`. diff --git a/command.js b/command.js index 60bdfd0fa..cbbf45d4e 100755 --- a/command.js +++ b/command.js @@ -7,7 +7,6 @@ module.exports = require('yargs') describe: 'Specify the release type manually (like npm version )', requiresArg: true, string: true, - choices: ['major', 'minor', 'patch'], global: true }) .option('prerelease', { diff --git a/index.js b/index.js index c7aa5ca09..e6a7870a0 100755 --- a/index.js +++ b/index.js @@ -27,7 +27,7 @@ module.exports = function standardVersion (argv, done) { if (!args.firstRelease) { var releaseType = getReleaseType(args.prerelease, release.releaseType, pkg.version) - newVersion = semver.inc(pkg.version, releaseType, args.prerelease) + newVersion = semver.valid(releaseType) || semver.inc(pkg.version, releaseType, args.prerelease) updateConfigs(args, newVersion) } else { checkpoint(args, 'skip version bump on first release', [], chalk.red(figures.cross)) diff --git a/test.js b/test.js index af217bc9f..995868bca 100644 --- a/test.js +++ b/test.js @@ -290,6 +290,34 @@ describe('cli', function () { }) }) + describe('release-as-exact', function () { + it('releases as v100.0.0', function () { + var originVer = '1.0.0' + writePackageJson(originVer) + fs.writeFileSync('CHANGELOG.md', 'legacy header format\n', 'utf-8') + + commit('fix: first commit') + + return execCliAsync('--release-as v100.0.0') + .then(function () { + getPackageVersion().should.equal('100.0.0') + }) + }) + + it('releases as 200.0.0-amazing', function () { + var originVer = '1.0.0' + writePackageJson(originVer) + fs.writeFileSync('CHANGELOG.md', 'legacy header format\n', 'utf-8') + + commit('fix: first commit') + + return execCliAsync('--release-as 200.0.0-amazing') + .then(function () { + getPackageVersion().should.equal('200.0.0-amazing') + }) + }) + }) + it('creates a prerelease with a new minor version after two prerelease patches', function () { writePackageJson('1.0.0') fs.writeFileSync('CHANGELOG.md', 'legacy header format\n', 'utf-8')