Skip to content

Commit

Permalink
Merge branch 'release/0.1.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelkaron committed Aug 28, 2013
2 parents 738b6be + 71cc7cf commit b3d2310
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 16 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ In lieu of a formal styleguide, take care to maintain the existing coding style.

## Release History

0.1.6 - Further cleanup. Added support for `strip`
0.1.5 - Externalize common code to separat modules
0.1.4 - Added support for cli arguments
0.1.3 - Added support for event
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "grunt-semver",
"description": "Semantic versioning for grunt",
"version": "0.1.5",
"version": "0.1.6",
"homepage": "https://github.com/mikaelkaron/grunt-semver",
"author": {
"name": "Mikael Karon",
Expand All @@ -23,8 +23,9 @@
"main": "Gruntfile.js",
"dependencies": {
"semver": "~2.1",
"grunt-util-options": "~0.0.1",
"grunt-util-process": "~0.0.1"
"grunt-util-options": "~0.0.2",
"grunt-util-process": "~0.0.1",
"grunt-util-args": "~0.0.3"
},
"devDependencies": {
"grunt-contrib-jshint": "~0.6.0",
Expand Down
73 changes: 60 additions & 13 deletions tasks/semver.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ module.exports = function(grunt) {
var _ = grunt.util._;
var _process = require("grunt-util-process")(grunt);
var _options = require("grunt-util-options")(grunt);
var _args = require("grunt-util-args")(grunt);
var SPACE = "space";
var PHASE = "phase";
var PART = "part";
var BUILD = "build";
var VERSION = "version";
var SEMVER = "semver";
var SEMVER_VALIDATE = SEMVER + ".validate";
var SEMVER_SET = SEMVER + ".set";
var SEMVER_BUMP = SEMVER + ".bump";
var SEMVER_STRIP = SEMVER + ".strip";

// Default options
var OPTIONS = {};
Expand All @@ -47,6 +48,20 @@ module.exports = function(grunt) {
return result;
}

/**
* Strips part of a semver
* @param {SemVer} version
* @param {String} part
* @returns {SemVer} version (now without part)
*/
function strip(version, part) {
if (version && part) {
version[part] = [];
}

return version;
}

// Add SEMVER delimiters
grunt.template.addDelimiters(SEMVER, "{%", "%}");

Expand All @@ -55,12 +70,11 @@ module.exports = function(grunt) {
var me = this;

// Get options and process
var options = _process.call(_options.call(me, me.options(OPTIONS), PHASE, PART, BUILD), {
var options = _process.call(_options.call(me, _.defaults(_args.call(me, null, PART, BUILD), me.options(OPTIONS)), PART, BUILD), {
"delimiters" : SEMVER
}, PHASE, PART, BUILD);
}, PART, BUILD);

// Update parameters
phase = options[PHASE];
part = options[PART];
build = options[BUILD];

Expand All @@ -79,11 +93,11 @@ module.exports = function(grunt) {
}(format(semver(build ? semver.clean(part) + "+" + build : part)))));
}
catch (e) {
grunt.fail.warn(e);
grunt.warn(e);
}
}
else {
this.files.forEach(function (file) {
me.files.forEach(function (file) {
file.src.forEach(function (src) {
try {
var json = grunt.file.readJSON(src);
Expand All @@ -97,15 +111,15 @@ module.exports = function(grunt) {
grunt.event.emit(SEMVER_VALIDATE, version, src);
}
catch (e) {
grunt.fail.warn(e);
grunt.warn(e);
}
});
});
}
break;

case "set" :
this.files.forEach(function (file) {
me.files.forEach(function (file) {
var dest = file.dest;

file.src.forEach(function (src) {
Expand All @@ -127,7 +141,7 @@ module.exports = function(grunt) {
grunt.event.emit(SEMVER_SET, version, src, dest);
}
catch (e) {
grunt.fail.warn(e);
grunt.warn(e);
}
});
});
Expand All @@ -139,7 +153,7 @@ module.exports = function(grunt) {
case "minor" :
case "patch" :
case "prerelease" :
this.files.forEach(function (file) {
me.files.forEach(function (file) {
var dest = file.dest;

file.src.forEach(function (src) {
Expand All @@ -157,19 +171,52 @@ module.exports = function(grunt) {
grunt.event.emit(SEMVER_BUMP, version, src, dest);
}
catch (e) {
grunt.fail.warn(e);
grunt.warn(e);
}
});
});
break;

default :
grunt.warn("Unknown part '" + part + "'");
}
break;

case "strip" :
switch (part) {
case "prerelease" :
case "build" :
me.files.forEach(function (file) {
var dest = file.dest;

file.src.forEach(function (src) {
try {
var json = grunt.file.readJSON(src);

grunt.log.verbose.writeln(src + " version : " + json[VERSION].cyan);

grunt.log.write(src + " : ");
var version = json[VERSION] = format(strip(semver(json[VERSION]), part));
grunt.log.writeln(version.green);

grunt.file.write(dest, JSON.stringify(json, null, options[SPACE]));

grunt.event.emit(SEMVER_STRIP, version, src, dest);
}
catch (e) {
grunt.warn(e);
}
});
});
break;

default :
grunt.fail.warn("Unknown part '" + part + "'");
grunt.warn("Unknown part '" + part + "'");
}
break;

default :
grunt.fail.warn("Unknown phase '" + phase + "'");
grunt.warn("Unknown phase '" + phase + "'");
}
});
};

0 comments on commit b3d2310

Please sign in to comment.