Skip to content

Commit

Permalink
Merge branch 'release/0.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelkaron committed Aug 16, 2013
2 parents 4131503 + 90afec4 commit 6c7ad99
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ A string value that is used to format the output JSON
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).

## Release History
0.1.1 - Added support for templated arguments
0.1.0 - First somewhat stable release
0.0.3 - Nothing to important
0.0.2 - Added support for `build`
Expand Down
2 changes: 1 addition & 1 deletion 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.0",
"version": "0.1.1",
"homepage": "https://github.com/mikaelkaron/grunt-semver",
"author": {
"name": "Mikael Karon",
Expand Down
35 changes: 31 additions & 4 deletions tasks/semver.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,23 @@ module.exports = function(grunt) {
"use strict";

var semver = require("semver");

var SEMVER = "semver";
var SPACE = "space";
var VERSION = "version";
var OPTIONS = {};

// Default options
var OPTIONS = {};
OPTIONS[SPACE] = "\t";

// grunt.template.process options
var PROCESS_OPTIONS = {
"delimiters" : SEMVER
};

/**
* Formats a semver
* @returns {String} Formatted semver
*/
function format() {
/*jshint validthis:true */
var me = this;
Expand All @@ -33,12 +43,29 @@ module.exports = function(grunt) {
return result;
}

grunt.task.registerMultiTask("semver", "Semantic versioner for grunt", function (phase, part, build) {
// Add SEMVER delimiters
grunt.template.addDelimiters(SEMVER, "{%", "%}");

// Register SEMVER task
grunt.task.registerMultiTask(SEMVER, "Semantic versioner for grunt", function (phase, part, build) {
// Get options (with defaults)
var options = this.options(OPTIONS);

// Log flags (if verbose)
grunt.log.verbose.writeflags(options);

// Process arguments
if (grunt.util.kindOf(phase) === "string") {
phase = grunt.template.process(phase, PROCESS_OPTIONS);
}
if (grunt.util.kindOf(part) === "string") {
part = grunt.template.process(part, PROCESS_OPTIONS);
}
if (grunt.util.kindOf(build) === "string") {
build = grunt.template.process(build, PROCESS_OPTIONS);
}

// Pick phase
switch (phase) {
case "validate" :
if (part) {
Expand All @@ -55,7 +82,7 @@ module.exports = function(grunt) {
var src = file.src;
var json = grunt.file.readJSON(src);

grunt.log.writeln(src + " : " + format.call(semver(build ?semver.clean(json[VERSION]) + "+" + build : json[VERSION])).green);
grunt.log.writeln(src + " : " + format.call(semver(build ? semver.clean(json[VERSION]) + "+" + build : json[VERSION])).green);
}
catch (e) {
grunt.fail.warn(e);
Expand Down

0 comments on commit 6c7ad99

Please sign in to comment.