Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelkaron committed Aug 9, 2013
0 parents commit 34e3f83
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
14 changes: 14 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"curly": true,
"eqeqeq": true,
"immed": true,
"latedef": true,
"newcap": true,
"noarg": true,
"sub": true,
"undef": true,
"boss": true,
"eqnull": true,
"node": true,
"laxbreak": true
}
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.idea
node_modules
npm-debug.log
tmp
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
language: node_js
before_script:
- npm install -g grunt-cli buster@~0.6
28 changes: 28 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* grunt-semver
* https://github.com/mikaelkaron/grunt-semver
*
* Copyright (c) 2013 Mikael Karon
* Licensed under the MIT license.
*/

'use strict';

module.exports = function(grunt) {

grunt.initConfig({
"jshint": {
"all": [
"Gruntfile.js",
"tasks/*.js"
],
"options": {
"jshintrc": ".jshintrc"
}
}
});

grunt.loadTasks("tasks");
grunt.loadNpmTasks("grunt-contrib-jshint");
grunt.registerTask("default", [ "jshint" ]);
};
34 changes: 34 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "grunt-semver",
"description": "Semantic versioning for grunt",
"version": "0.0.1-SNAPSHOT",
"homepage": "https://github.com/mikaelkaron/grunt-semver",
"author": {
"name": "Mikael Karon",
"email": "[email protected]"
},
"repository": {
"type": "git",
"url": "https://github.com/mikaelkaron/grunt-semver"
},
"bugs": {
"url": "https://github.com/mikaelkaron/grunt-semver/issues"
},
"licenses": [
{
"type": "MIT",
"url": "http://mikael.mit-license.org"
}
],
"main": "Gruntfile.js",
"dependencies": {
"semver": "~2.1"
},
"devDependencies": {
"grunt-contrib-jshint": "~0.6.0",
"grunt": "~0.4.1"
},
"keywords": [
"gruntplugin"
]
}
122 changes: 122 additions & 0 deletions tasks/semver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
* grunt-semver
* https://github.com/mikaelkaron/grunt-semver
*
* Copyright (c) 2013 Mikael Karon
* Licensed under the MIT license.
*/

module.exports = function(grunt) {
"use strict";

var semver = require("semver");
var SPACE = "space";
var VERSION = "version";
var OPTIONS = {};

OPTIONS[SPACE] = "\t";

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

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

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

return result;
}

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

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

switch (phase) {
case "valid" :
if (part) {
try {
grunt.log.ok(format.call(semver(part)));
}
catch (e) {
grunt.log.error(e);
}
}
else {
this.files.forEach(function (file) {
var src = file.src;
var json = grunt.file.readJSON(src);

try {
grunt.log.ok(src + " : " + format.call(semver(json[VERSION])));
}
catch (e) {
grunt.log.error(e);
}
});
}
break;

case "set" :
this.files.forEach(function (file) {
var src = file.src;
var dest = file.dest || src;
var json = grunt.file.readJSON(src);
var version;

try {
version = json[VERSION] = format.call(semver(part));

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

grunt.file.write(dest, JSON.stringify(json, null, options[SPACE]));
}
catch (e) {
grunt.log.error(e);
}
});
break;

case "bump" :
this.files.forEach(function (file) {
var src = file.src;
var dest = file.dest || src;
var json = grunt.file.readJSON(src);
var version;

switch (part) {
case "major" :
case "minor" :
case "patch" :
case "prerelease" :
try {
version = json[VERSION] = format.call(semver(json[VERSION]).inc(part));

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

grunt.file.write(dest, JSON.stringify(json, null, options[SPACE]));
}
catch (e) {
grunt.log.error(e);
}

break;

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

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

0 comments on commit 34e3f83

Please sign in to comment.