Skip to content

Commit

Permalink
feat(bump all files): add support for prerelase
Browse files Browse the repository at this point in the history
Upgrade semve to allow for prerelease versions
Change RexExp for versions and prerelease versions
Add prereleaseName to options, defaulted to null
- pre release types:
named:   1.0.0-rc.0
unnamed: 1.0.0-0
Fix issue where bump:git on multiple files failed

Closes: 42, 94, 102, 110
  • Loading branch information
schechter committed Feb 14, 2015
1 parent f96609e commit 03523f3
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 16 deletions.
76 changes: 69 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ grunt.initConfig({
push: true,
pushTo: 'upstream',
gitDescribeOptions: '--tags --always --abbrev=1 --dirty=-d',
globalReplace: false
globalReplace: false,
prereleaseName: null
}
},
})
Expand Down Expand Up @@ -124,6 +125,19 @@ Default value: `false`

Replace all occurrences of the version in the file. When set to `false`, only the first occurrence will be replaced.

#### options.prereleaseName
Type: `String`
Default value: `rc`

When bumping to a prerelease version this will be the identifier of the prerelease e.g. `dev`, `alpha`, `beta`, `rc` etc.
1.0.0-`prereleaseName`.0
When left as the default `null` version bump:prereleae will behave as follows:
* 1.0.0 to 1.0.1-0
* 1.0.1-0 to 1.0.1-2
* from a previous bump:git
* 1.0.0-7-g10b5 to 1.0.0-8


### Usage Examples

Let's say current version is `0.0.1`.
Expand Down Expand Up @@ -153,12 +167,6 @@ $ grunt bump:major
>> Tagged as "v1.0.0"
>> Pushed to origin

$ grunt bump:prerelease
>> Version bumped to 1.0.0-1
>> Committed as "Release v1.0.0-1"
>> Tagged as "v1.0.0-1"
>> Pushed to origin

$ grunt bump:patch
>> Version bumped to 1.0.1
>> Committed as "Release v1.0.1"
Expand All @@ -170,6 +178,60 @@ $ grunt bump:git
>> Committed as "Release v1.0.1-ge96c"
>> Tagged as "v1.0.1-ge96c"
>> Pushed to origin

$ grunt bump:prepatch
>> Version bumped to 1.0.2-rc.0
>> Committed as "Release v1.0.2-rc.0"
>> Tagged as "v1.0.2-rc.0"
>> Pushed to origin

$ grunt bump:prerelease
>> Version bumped to 1.0.2-rc.0
>> Committed as "Release v1.0.2-rc.0"
>> Tagged as "v1.0.2.rc.0"
>> Pushed to origin

$ grunt bump:prerelease
>> Version bumped to 1.0.2-rc.1
>> Committed as "Release v1.0.2-rc.1"
>> Tagged as "v1.0.2.rc.1"
>> Pushed to origin

$ grunt bump:patch # (major, minor or patch) will do this
>> Version bumped to 1.0.2
>> Committed as "Release v1.0.2"
>> Tagged as "v1.0.2"
>> Pushed to origin

$ grunt bump:preminor
>> Version bumped to 1.1.0-rc.0
>> Committed as "Release v1.1.0-rc.0"
>> Tagged as "v1.1.0-rc.0"
>> Pushed to origin

$ grunt bump
>> Version bumped to 1.1.0
>> Committed as "Release v1.1.0"
>> Tagged as "v1.1.0"
>> Pushed to origin

$ grunt bump:premajor
>> Version bumped to 2.0.0-rc.0
>> Committed as "Release v2.0.0-rc.0"
>> Tagged as "v2.0.0-rc.0"
>> Pushed to origin

$ grunt bump
>> Version bumped to 2.0.0
>> Committed as "Release v2.0.0"
>> Tagged as "v2.0.0"
>> Pushed to origin

$ grunt bump:prerelease # from a released version `prerelease` defaults to prepatch
>> Version bumped to 2.0.1-rc.0
>> Committed as "Release v2.0.1-rc.0"
>> Tagged as "v2.0.1-rc.0"
>> Pushed to origin
````

If you want to jump to an exact version, you can use the ```setversion``` tag in the command line.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
},
"license": "MIT",
"dependencies": {
"semver": "~2.3.0"
"semver": "~4.2.2"
},
"peerDependencies": {
"grunt": ">=0.4.0"
Expand Down
18 changes: 10 additions & 8 deletions tasks/bump.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
* grunt bump:patch
* grunt bump:minor
* grunt bump:major
* grunt bump:prepatch
* grunt bump:preminor
* grunt bump:premajor
* grunt bump:prerelease
*
* @author Vojta Jina <[email protected]>
* @author Mathias Paumgarten <[email protected]>
Expand Down Expand Up @@ -34,7 +38,8 @@ module.exports = function(grunt) {
push: true,
pushTo: 'upstream',
gitDescribeOptions: '--tags --always --abbrev=1 --dirty=-d',
globalReplace: false
globalReplace: false,
prereleaseName: null
});

var dryRun = grunt.option('dry-run');
Expand Down Expand Up @@ -77,14 +82,12 @@ module.exports = function(grunt) {

var globalVersion; // when bumping multiple files
var gitVersion; // when bumping using `git describe`
var VERSION_REGEXP = /([\'|\"]?version[\'|\"]?[ ]*:[ ]*[\'|\"]?)([\d||A-a|.|-]*)([\'|\"]?)/i;

var VERSION_REGEXP = new RegExp('([\\\'|\\\"]?version[\\\'|\\\"]?[ ]*:[ ]*[\\\'|\\\"]?)(\\\d+\\\.\\\d+\\\.\\\d+(-'+opts.prereleaseName+'\\\.\\\d+)?(-\\\d+)?)[\\\d||A-a|.|-]*([\\\'|\\\"]?)', 'i');

if (opts.globalReplace) {
VERSION_REGEXP = new RegExp(VERSION_REGEXP.source, 'gi');
}


// GET VERSION FROM GIT
runIf(opts.bumpVersion && versionType === 'git', function() {
exec('git describe ' + opts.gitDescribeOptions, function(err, stdout) {
Expand All @@ -96,14 +99,13 @@ module.exports = function(grunt) {
});
});


// BUMP ALL FILES
runIf(opts.bumpVersion, function() {
grunt.file.expand(opts.files).forEach(function(file, idx) {
var version = null;
var content = grunt.file.read(file).replace(VERSION_REGEXP, function(match, prefix, parsedVersion, suffix) {
gitVersion = gitVersion && parsedVersion + '-' + gitVersion;
version = exactVersionToSet || gitVersion || semver.inc(parsedVersion, versionType || 'patch');
var bumpFrom;
var content = grunt.file.read(file).replace(VERSION_REGEXP, function(match, prefix, parsedVersion, namedPre, noNamePre, suffix) {
version = exactVersionToSet || gitVersion || semver.inc(parsedVersion, versionType || 'patch', opts.prereleaseName);
return prefix + version + suffix;
});

Expand Down

0 comments on commit 03523f3

Please sign in to comment.