Skip to content

Commit

Permalink
feat(app): Add all pre release types support (preminor, premajor etc)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tallyb committed Feb 5, 2019
1 parent 222d006 commit 50eafea
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <version number>`. 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.
Expand Down
19 changes: 6 additions & 13 deletions lib/versionHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
5 changes: 5 additions & 0 deletions test/mocha/versionHelper.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()', () => {
Expand Down

0 comments on commit 50eafea

Please sign in to comment.