diff --git a/Gruntfile.js b/Gruntfile.js index 2d06758..1580372 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,6 +1,6 @@ module.exports = function(grunt) { grunt.initConfig({ - + clean: { test: 'test/fixtures/_component.json' }, @@ -37,13 +37,23 @@ module.exports = function(grunt) { grunt.loadNpmTasks('grunt-contrib-clean'); grunt.loadNpmTasks('grunt-contrib-nodeunit'); - grunt.registerTask('test', [ - 'clean', - 'setup', - 'release', - 'nodeunit', - 'clean' - ]); + grunt.registerTask('test', function() { + grunt.task.run([ + 'clean', + 'setup', + 'release', + 'nodeunit', + 'clean' + ]); + + grunt.task.run([ + 'clean', + 'setup', + 'bump-only', + 'nodeunit', + 'clean' + ]); + }); grunt.registerMultiTask('setup', 'Setup test fixtures', function(){ this.files.forEach(function(f){ diff --git a/tasks/grunt-release.js b/tasks/grunt-release.js index 1233953..b3bbf69 100644 --- a/tasks/grunt-release.js +++ b/tasks/grunt-release.js @@ -10,8 +10,16 @@ var shell = require('shelljs'); var semver = require('semver'); module.exports = function(grunt){ + grunt.registerTask('bump-only', 'bump version only', function(type){ + + var file = grunt.config.get('release.options.file') || grunt.config('pkgFile') || 'package.json'; + grunt.log.writeln(file); + + grunt.log.writeln('Only bumping the version.'); + bump(setup(file, true, type)); + }); grunt.registerTask('release', 'bump version, git tag, git push, npm publish', function(type){ - + //defaults var options = this.options({ bump: true, @@ -24,7 +32,7 @@ module.exports = function(grunt){ npm : true }); - var config = setup(options.file, type); + var config = setup(options.file, options.bump, type); var templateOptions = { data: { version: config.newVersion @@ -45,15 +53,6 @@ module.exports = function(grunt){ if (options.npm) publish(config); if (options.github) githubRelease(config); - function setup(file, type){ - var pkg = grunt.file.readJSON(file); - var newVersion = pkg.version; - if (options.bump) { - newVersion = semver.inc(pkg.version, type || 'patch'); - } - return {file: file, pkg: pkg, newVersion: newVersion}; - } - function add(config){ run('git add ' + config.file); } @@ -78,7 +77,7 @@ module.exports = function(grunt){ var cmd = 'npm publish'; var msg = 'published '+ config.newVersion +' to npm'; var npmtag = getNpmTag(); - if (npmtag){ + if (npmtag){ cmd += ' --tag ' + npmtag; msg += ' with a tag of "' + npmtag + '"'; } @@ -104,12 +103,6 @@ module.exports = function(grunt){ if (msg) grunt.log.ok(msg); } - function bump(config){ - config.pkg.version = config.newVersion; - grunt.file.write(config.file, JSON.stringify(config.pkg, null, ' ') + '\n'); - grunt.log.ok('Version bumped to ' + config.newVersion); - } - function githubRelease(){ var request = require('superagent'); var done = task.async(); @@ -127,7 +120,7 @@ module.exports = function(grunt){ .end(function(res){ if (res.statusCode === 201){ success(); - } + } else { grunt.fail.warn('Error creating github release. Response: ' + res.text); } @@ -138,6 +131,21 @@ module.exports = function(grunt){ done(); } } - }); + + function setup(file, bump, type){ + var pkg = grunt.file.readJSON(file); + var newVersion = pkg.version; + if (bump) { + newVersion = semver.inc(pkg.version, type || 'patch'); + } + return {file: file, pkg: pkg, newVersion: newVersion}; + } + + function bump(config){ + config.pkg.version = config.newVersion; + grunt.file.write(config.file, JSON.stringify(config.pkg, null, ' ') + '\n'); + grunt.log.ok('Version bumped to ' + config.newVersion); + } + };