Skip to content

Commit

Permalink
feat: support custom regexp
Browse files Browse the repository at this point in the history
Closes #126
  • Loading branch information
Anonym-tsk authored and eddiemonge committed Feb 18, 2015
1 parent 696464b commit 2fe1e89
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ grunt.initConfig({
pushTo: 'upstream',
gitDescribeOptions: '--tags --always --abbrev=1 --dirty=-d',
globalReplace: false,
prereleaseName: null
prereleaseName: null,
regExp: null
}
},
})
Expand Down Expand Up @@ -137,6 +138,11 @@ When left as the default `null` version bump:prereleae will behave as follows:
* from a previous bump:git
* 1.0.0-7-g10b5 to 1.0.0-8

#### options.regExp
Type: `RegExp`
Default value: `null`

Regex to find and replace version string in files described in `options.files`. If no value is specified, it will use the plugin's default.

### Usage Examples

Expand Down
12 changes: 8 additions & 4 deletions tasks/bump.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ module.exports = function(grunt) {
pushTo: 'upstream',
gitDescribeOptions: '--tags --always --abbrev=1 --dirty=-d',
globalReplace: false,
prereleaseName: null
prereleaseName: null,
regExp: null
});

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

var globalVersion; // when bumping multiple files
var gitVersion; // when bumping using `git describe`
var VERSION_REGEXP = new RegExp('([\\\'|\\\"]?version[\\\'|\\\"]?[ ]*:[ ]*[\\\'|\\\"]?)(\\\d+\\\.\\\d+\\\.\\\d+(-'+opts.prereleaseName+'\\\.\\\d+)?(-\\\d+)?)[\\\d||A-a|.|-]*([\\\'|\\\"]?)', 'i');
var VERSION_REGEXP = opts.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');
Expand All @@ -103,9 +108,8 @@ module.exports = function(grunt) {
runIf(opts.bumpVersion, function() {
grunt.file.expand(opts.files).forEach(function(file, idx) {
var version = null;
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);
version = exactVersionToSet || gitVersion || semver.inc(parsedVersion, versionType || 'patch', opts.prereleaseName);
return prefix + version + suffix;
});

Expand Down

0 comments on commit 2fe1e89

Please sign in to comment.