Skip to content

Commit

Permalink
Merge branch 'release/0.1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelkaron committed Aug 16, 2013
2 parents 6c7ad99 + 2304047 commit 5ad95c0
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 38 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.2 - Added verbose logging
0.1.1 - Added support for templated arguments
0.1.0 - First somewhat stable release
0.0.3 - Nothing to important
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.1",
"version": "0.1.2",
"homepage": "https://github.com/mikaelkaron/grunt-semver",
"author": {
"name": "Mikael Karon",
Expand Down
98 changes: 61 additions & 37 deletions tasks/semver.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,17 @@ module.exports = function(grunt) {
var OPTIONS = {};
OPTIONS[SPACE] = "\t";

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

/**
* Formats a semver
* Formats a semver version
* @param {SemVer} version
* @returns {String} Formatted semver
*/
function format() {
/*jshint validthis:true */
var me = this;
var build = me.build;

function format(version) {
// Call super
var result = me.format();
var result = version.format();

// Get build
var build = version.build;

// Add build if it exists
if (build && build.length) {
Expand All @@ -43,6 +38,19 @@ module.exports = function(grunt) {
return result;
}

/**
* Processes parameter
* @param {*} param Paramter
* @returns {*} Processed parameter
*/
function process(param) {
return grunt.util.kindOf(param) === "string"
? grunt.template.process(param, {
"delimiters" : SEMVER
})
: param;
}

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

Expand All @@ -51,26 +59,26 @@ module.exports = function(grunt) {
// Get options (with defaults)
var options = this.options(OPTIONS);

// Process arguments
phase = process(phase);
part = process(part);
build = process(build);

// 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" :
grunt.log.verbose.writeflags({
"phase": phase,
"version": part,
"build": build
});

if (part) {
try {
grunt.log.writeln(format.call(semver(build ? semver.clean(part) + "+" + build : part)).green);
grunt.log.writeln(format(semver(build ? semver.clean(part) + "+" + build : part)).green);
}
catch (e) {
grunt.fail.warn(e);
Expand All @@ -82,7 +90,9 @@ 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.verbose.writeln(src + " version : " + json[VERSION].cyan);

grunt.log.writeln(src + " : " + format(semver(build ? semver.clean(json[VERSION]) + "+" + build : json[VERSION])).green);
}
catch (e) {
grunt.fail.warn(e);
Expand All @@ -92,19 +102,28 @@ module.exports = function(grunt) {
break;

case "set" :
grunt.log.verbose.writeflags({
"phase": phase,
"version": part,
"build": build
});

this.files.forEach(function (file) {
try {
var src = file.src;
var dest = file.dest || src;

grunt.log.write(src + " : ");

var json = grunt.file.readJSON(src);
var version = json[VERSION] = format.call(semver(build ? semver.clean(part || json[VERSION]) + "+" + build : part || json[VERSION]).inc(part));

grunt.log.verbose.write(src + " version : " + json[VERSION].cyan);
if (part) {
grunt.log.verbose.write(" (but will use " + part.cyan + " instead)");
}
grunt.log.verbose.writeln();

grunt.log.write(src + " : ");
var version = json[VERSION] = format(semver(build ? semver.clean(part || json[VERSION]) + "+" + build : part || json[VERSION]));
grunt.log.writeln(version.green);

grunt.file.write(dest, JSON.stringify(json, null, options[SPACE]));
grunt.file.write(file.dest, JSON.stringify(json, null, options[SPACE]));
}
catch (e) {
grunt.fail.warn(e);
Expand All @@ -113,6 +132,12 @@ module.exports = function(grunt) {
break;

case "bump" :
grunt.log.verbose.writeflags({
"phase": phase,
"part": part,
"build": build
});

switch (part) {
case "major" :
case "minor" :
Expand All @@ -121,16 +146,15 @@ module.exports = function(grunt) {
this.files.forEach(function (file) {
try {
var src = file.src;
var dest = file.dest || src;

grunt.log.write(src + " : ");

var json = grunt.file.readJSON(src);
var version = json[VERSION] = format.call(semver(build ? semver.clean(json[VERSION]) + "+" + build : semver.clean(json[VERSION])).inc(part));

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

grunt.log.write(src + " : ");
var version = json[VERSION] = format(semver(build ? semver.clean(json[VERSION]) + "+" + build : semver.clean(json[VERSION])).inc(part));
grunt.log.writeln(version.green);

grunt.file.write(dest, JSON.stringify(json, null, options[SPACE]));
grunt.file.write(file.dest, JSON.stringify(json, null, options[SPACE]));
}
catch (e) {
grunt.fail.warn(e);
Expand Down

0 comments on commit 5ad95c0

Please sign in to comment.