Skip to content

Commit

Permalink
Merge branch 'release/0.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelkaron committed Aug 12, 2013
2 parents 253bdc4 + 91d5b9d commit e9a6143
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 14 deletions.
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
[![Build Status](https://travis-ci.org/mikaelkaron/grunt-semver.png)](https://travis-ci.org/mikaelkaron/grunt-semver)
[![NPM version](https://badge.fury.io/js/grunt-semver.png)](http://badge.fury.io/js/grunt-semver)

# grunt-semver

> Semantic versioner for grunt
## Getting Started
This plugin requires Grunt `~0.4.0`

If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

```shell
npm install grunt-semver --save-dev
```

One the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

```js
grunt.loadNpmTasks('grunt-semver');
```

## The "grunt-semver" task

### Overview
In your project's Gruntfile, add a section named `semver` to the data object passed into `grunt.initConfig()`.

```js
grunt.initConfig({
"semver": {
"options": {
// Task-specific options go here.
},
"your_target": {
// Target-specific file lists and/or options go here.
},
},
})
```

### Options

#### options.space
Type: `String`
Default value: `\t`

A string value that is used to format the output JSON

## Contributing
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.0.2 - Added support for `build`
0.0.1 - First release
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.0.1",
"version": "0.0.2",
"homepage": "https://github.com/mikaelkaron/grunt-semver",
"author": {
"name": "Mikael Karon",
Expand Down
29 changes: 16 additions & 13 deletions tasks/semver.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = function(grunt) {
"use strict";

var semver = require("semver");

var SPACE = "space";
var VERSION = "version";
var OPTIONS = {};
Expand All @@ -18,22 +19,24 @@ module.exports = function(grunt) {

function format() {
/*jshint validthis:true */
var prerelease = this.prerelease;
var build = this.build;
var result = this.major + '.' + this.minor + '.' + this.patch;
var me = this;

var prerelease = me.prerelease;
var build = me.build;
var result = [ me.major, me.minor, me.patch ].join(".");

if (prerelease && prerelease.length) {
result += '-' + prerelease.join('.');
result += '-' + prerelease.join(".");
}

if (build && build.length) {
result += "+" + build;
result += "+" + build.join(".");
}

return result;
}

grunt.task.registerMultiTask("semver", "Semantic versioner for grunt", function (phase, part) {
grunt.task.registerMultiTask("semver", "Semantic versioner for grunt", function (phase, part, build) {
var options = this.options(OPTIONS);

// Log flags (if verbose)
Expand All @@ -43,10 +46,10 @@ module.exports = function(grunt) {
case "valid" :
if (part) {
try {
grunt.log.ok(format.call(semver(part)));
grunt.log.ok(format.call(build ? semver(semver(part) + "+" + build) : semver(part)));
}
catch (e) {
grunt.log.error(e);
grunt.fail.warn(e);
}
}
else {
Expand All @@ -55,10 +58,10 @@ module.exports = function(grunt) {
var json = grunt.file.readJSON(src);

try {
grunt.log.ok(src + " : " + format.call(semver(json[VERSION])));
grunt.log.ok(src + " : " + format.call(build ? semver(semver(json[VERSION]) + "+" + build) : semver(json[VERSION])));
}
catch (e) {
grunt.log.error(e);
grunt.fail.warn(e);
}
});
}
Expand All @@ -72,14 +75,14 @@ module.exports = function(grunt) {
var version;

try {
version = json[VERSION] = format.call(semver(part));
version = json[VERSION] = format.call(build ? semver(semver(part) + "+" + build) : semver(part));

grunt.log.ok(src + " : " + version);

grunt.file.write(dest, JSON.stringify(json, null, options[SPACE]));
}
catch (e) {
grunt.log.error(e);
grunt.fail.warn(e);
}
});
break;
Expand All @@ -97,7 +100,7 @@ module.exports = function(grunt) {
case "patch" :
case "prerelease" :
try {
version = json[VERSION] = format.call(semver(json[VERSION]).inc(part));
version = json[VERSION] = format.call((build ? semver(semver(json[VERSION]) + "+" + build) : semver(json[VERSION])).inc(part));

grunt.log.ok(src + " : " + version);

Expand Down

0 comments on commit e9a6143

Please sign in to comment.