From 50eafea8578f9fb3f71eccb94849d209ee0c6837 Mon Sep 17 00:00:00 2001 From: tallyb Date: Tue, 5 Feb 2019 11:49:35 +0200 Subject: [PATCH] feat(app): Add all pre release types support (preminor, premajor etc) --- README.md | 2 +- lib/versionHelper.js | 19 ++++++------------- test/mocha/versionHelper.spec.js | 5 +++++ 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index becf634..846f2dd 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ In your `package.json` ``` Running release will do the following: -- Bumps version. By default, this will publish a patch version, if you want to control the semver option you can pass an optional 'prerelease', 'patch', 'minor' or 'major' to the `--type` argument. The prerelease versions will be in the format of `2.3.2-4`. +- Bumps version. By default, this will publish a patch version, if you want to control the semver option you can pass an optional type `--type` argument. The prerelease versions will be in the format of `2.3.2-4`. valid types are: 'major', 'minor', 'patch', 'premajor', 'preminor', 'prepatch', 'prerelease' - Updates version in files: by default it will only update the root level `package.json`. Optionnaly use `--file` to specify file paths or files patterns (globs) that can have their version updated as well. Files can be `package.json` files or `config.xml` files - Commit the changed files with a standard commit message. Default message is `chore(app): Version `. Use `--production` to suffix the commit message with the work `production` (can be later used in CI) - Generates changlog based on Angular standard commit messages. diff --git a/lib/versionHelper.js b/lib/versionHelper.js index 4af996b..be6a5c9 100644 --- a/lib/versionHelper.js +++ b/lib/versionHelper.js @@ -31,22 +31,15 @@ var filterFiles = function(files, extension) { * @returns {String} bumped version */ var bump = function(currentVersion, bumpType) { - if (!currentVersion) { + + const BUMPTYPES = ['major', 'minor', 'patch', 'premajor', 'preminor', 'prepatch', 'prerelease']; + if (!currentVersion || !semver.valid(currentVersion)) { return '0.0.1'; } - let nextVersion; - switch (bumpType) { - case 'prerelease': - case 'patch': - case 'minor': - case 'major': - nextVersion = semver.inc(currentVersion, bumpType); - break; - default: - nextVersion = semver.inc(currentVersion, 'patch'); - break; - + if (!bumpType || !BUMPTYPES.includes(bumpType)) { + bumpType = 'patch'; } + let nextVersion = semver.inc(currentVersion, bumpType); return nextVersion; }; diff --git a/test/mocha/versionHelper.spec.js b/test/mocha/versionHelper.spec.js index e8d3512..41626bd 100644 --- a/test/mocha/versionHelper.spec.js +++ b/test/mocha/versionHelper.spec.js @@ -50,6 +50,11 @@ describe('versionHelper', () => { it('should return 0.0.1 when initial version is empty', () => { expect(versionHelper.bump()).to.equal('0.0.1'); }); + + it('should return 0.0.1 when initial version is invalid', () => { + expect(versionHelper.bump('something')).to.equal('0.0.1'); + }); + }); describe('bumpFiles()', () => {