Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions tasks/grunt-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var Q = require('q');

module.exports = function(grunt){
grunt.registerTask('release', 'bump version, git tag, git push, npm publish', function(type){

//defaults
var options = this.options({
bump: true,
Expand All @@ -32,6 +32,7 @@ module.exports = function(grunt){
version: config.newVersion
}
};
var tagType = grunt.template.process(grunt.config.getRaw('release.options.tagType') || 'annotated', templateOptions);
var tagName = grunt.template.process(grunt.config.getRaw('release.options.tagName') || '<%= version %>', templateOptions);
var commitMessage = grunt.template.process(grunt.config.getRaw('release.options.commitMessage') || 'release <%= version %>', templateOptions);
var tagMessage = grunt.template.process(grunt.config.getRaw('release.options.tagMessage') || 'version <%= version %>', templateOptions);
Expand Down Expand Up @@ -73,6 +74,17 @@ module.exports = function(grunt){
return tag;
}

function getTagTypeArg(){
switch(tagType) {
case 'annotated':
return '--annotate ';
case 'lightweight':
return '';
default:
throw grunt.util.error('Unrecognized tagType: "' + tagType + '".');
}
}

function ifEnabled(option, fn){
if (options[option]) return fn;
}
Expand All @@ -88,7 +100,7 @@ module.exports = function(grunt){
else {
var success = shell.exec(cmd, {silent:true}).code === 0;

if (success){
if (success){
grunt.log.ok(msg || cmd);
deferred.resolve();
}
Expand All @@ -109,7 +121,7 @@ module.exports = function(grunt){
}

function tag(){
return run('git tag ' + tagName + ' -m "'+ tagMessage +'"', 'created new git tag: ' + tagName);
return run('git tag ' + getTagTypeArg() + tagName + ' -m "'+ tagMessage +'"', 'created new ' + tagType + ' git tag: ' + tagName);
}

function push(){
Expand All @@ -124,7 +136,7 @@ module.exports = function(grunt){
var cmd = 'npm publish';
var msg = 'published version '+ config.newVersion +' to npm';
var npmtag = getNpmTag();
if (npmtag){
if (npmtag){
cmd += ' --tag ' + npmtag;
msg += ' with a tag of "' + npmtag + '"';
}
Expand All @@ -143,7 +155,7 @@ module.exports = function(grunt){

function githubRelease(){
var deferred = Q.defer();
if (nowrite){
if (nowrite){
success();
return;
}
Expand All @@ -157,7 +169,7 @@ module.exports = function(grunt){
.end(function(res){
if (res.statusCode === 201){
success();
}
}
else {
deferred.reject('Error creating github release. Response: ' + res.text);
}
Expand Down