Skip to content

Commit

Permalink
Adding custom tasks to run before or after bump and release
Browse files Browse the repository at this point in the history
You can now use `beforeBump`, `afterBump`, `beforeRelease` and
`afterRelease` as arrays in config to run grunt tasks accordingly.

Closes #98.
Reference #6.
  • Loading branch information
Mark Kennedy authored and drublic committed Feb 5, 2015
1 parent 92c3bbd commit d07530c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ The following are all the release steps, you can disable any you need to:
tagName: 'some-tag-<%= version %>', //default: '<%= version %>'
commitMessage: 'check out my release <%= version %>', //default: 'release <%= version %>'
tagMessage: 'tagging version <%= version %>', //default: 'Version <%= version %>',
beforeBump: [], // optional grunt tasks to run before file versions are bumped
afterBump: [], // optional grunt tasks to run after file versions are bumped
beforeRelease: [], // optional grunt tasks to run after release version is bumped up but before release is packaged
afterRelease: [], // optional grunt tasks to run after release is packaged
github: {
repo: 'geddski/grunt-release', //put your user/repo here
usernameVar: 'GITHUB_USERNAME', //ENVIRONMENT VARIABLE that contains Github username
Expand Down
29 changes: 28 additions & 1 deletion tasks/grunt-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ module.exports = function(grunt){
push: true,
pushTags: true,
npm: true,
remote: 'origin'
remote: 'origin',
beforeReleaseTasks: [],
afterReleaseTasks: [],
beforeBumpTasks: [],
afterBumpTasks: []
}, (grunt.config.data[this.name] || {}).options);
var config = setup(options.file, type);

Expand Down Expand Up @@ -238,8 +242,30 @@ module.exports = function(grunt){
return deferred.promise;
}

function runTasks(taskName) {
var map = {
beforeBump: 'beforeBumpTasks',
afterBump: 'afterBumpTasks',
beforeRelease: 'beforeReleaseTasks',
afterRelease: 'afterReleaseTasks'
};
return function () {
var method = map[taskName],
tasks = options[method];
if (tasks.length) {
grunt.log.ok('running ' + method + ' ');
if (!nowrite) {
grunt.task.run(tasks);
}
}
}
}

new Q()
.then(ifEnabled('beforeBumpTasks', runTasks('beforeBump')))
.then(ifEnabled('bump', bump))
.then(ifEnabled('afterBumpTasks', runTasks('afterBump')))
.then(ifEnabled('beforeReleaseTasks', runTasks('beforeRelease')))
.then(ifEnabled('changelog', changelog))
.then(ifEnabled('add', add))
.then(ifEnabled('commit', commit))
Expand All @@ -248,6 +274,7 @@ module.exports = function(grunt){
.then(ifEnabled('pushTags', pushTags))
.then(ifEnabled('npm', publish))
.then(ifEnabled('github', githubRelease))
.then(ifEnabled('afterReleaseTasks', runTasks('afterRelease')))
.catch(function(msg){
grunt.fail.warn(msg || 'release failed');
})
Expand Down

0 comments on commit d07530c

Please sign in to comment.