Skip to content

Commit

Permalink
Fixes REGEX issue and uses prereleaseName from options for reges and …
Browse files Browse the repository at this point in the history
…call to semver
  • Loading branch information
schechter committed Feb 12, 2015
1 parent 22d07be commit 15ec1c8
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions tasks/bump.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = function(grunt) {
pushTo: 'upstream',
gitDescribeOptions: '--tags --always --abbrev=1 --dirty=-d',
globalReplace: false,
prereleaseName: 'rc';
prereleaseName: 'rc'
});

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

var globalVersion; // when bumping multiple files
var gitVersion; // when bumping using `git describe`
// FIX ME get opts.prereleaseName in regex
var VERSION_REGEXP = '/[\'|\"]?version[\'|\"]?[ ]*:[ ]*([\'|\"])?(\d+\.\d+(\.\d)?(-'+opts.prereleaseName+'.\d+)?)[\'|\"]?/i';
var VERSION_REGEXP = new RegExp('([\\\'|\\\"]?version[\\\'|\\\"]?[ ]*:[ ]*[\\\'|\\\"]?)(\\\d+\\\.\\\d+\\\.\\\d+(-'+opts.prereleaseName+'\\\.\\\d+)?)[\\\w-]*?([\\\'|\\\"]?)', '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 @@ -105,10 +104,9 @@ module.exports = function(grunt) {
grunt.file.expand(opts.files).forEach(function(file, idx) {
var version = null;
var bumpFrom;
var content = grunt.file.read(file).replace(VERSION_REGEXP, function(quote, parsedVersion) {
var content = grunt.file.read(file).replace(VERSION_REGEXP, function(match, prefix, parsedVersion, git, suffix) {
version = exactVersionToSet || gitVersion || semver.inc(parsedVersion, versionType, opts.prereleaseName);
}
return quote + version + quote;
return prefix + version + suffix;
});

if (!version) {
Expand Down

0 comments on commit 15ec1c8

Please sign in to comment.