From fa466c22fcb51328be21af45f31403be3d278767 Mon Sep 17 00:00:00 2001 From: Jonathan Kim Date: Wed, 4 Dec 2013 14:44:55 -0500 Subject: [PATCH 1/5] Move setup and bump outside of the task registration. --- tasks/grunt-release.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/tasks/grunt-release.js b/tasks/grunt-release.js index 1233953..ab69862 100644 --- a/tasks/grunt-release.js +++ b/tasks/grunt-release.js @@ -45,15 +45,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); } @@ -104,12 +95,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(); @@ -139,5 +124,20 @@ module.exports = function(grunt){ } } + 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 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); + } + }); }; From 5f7e0bb2eecf864dbe903d46f89d049d218838c9 Mon Sep 17 00:00:00 2001 From: Jonathan Kim Date: Wed, 4 Dec 2013 14:45:11 -0500 Subject: [PATCH 2/5] New bump-only task. --- tasks/grunt-release.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tasks/grunt-release.js b/tasks/grunt-release.js index ab69862..28833bd 100644 --- a/tasks/grunt-release.js +++ b/tasks/grunt-release.js @@ -10,6 +10,16 @@ var shell = require('shelljs'); var semver = require('semver'); module.exports = function(grunt){ + grunt.registerTask('bump-only', 'bump version only', function(type){ + + //defaults + var options = this.options({ + file: grunt.config('pkgFile') || 'package.json' + }); + + grunt.log('Only bumping the version.'); + bump(setup(options.file, type)); + }); grunt.registerTask('release', 'bump version, git tag, git push, npm publish', function(type){ //defaults From 2d1e01a8658f0ef355b524770a577c51e06d8870 Mon Sep 17 00:00:00 2001 From: Jonathan Kim Date: Wed, 4 Dec 2013 14:46:39 -0500 Subject: [PATCH 3/5] Whitespace. --- tasks/grunt-release.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tasks/grunt-release.js b/tasks/grunt-release.js index 28833bd..2abc403 100644 --- a/tasks/grunt-release.js +++ b/tasks/grunt-release.js @@ -21,7 +21,7 @@ module.exports = function(grunt){ bump(setup(options.file, type)); }); grunt.registerTask('release', 'bump version, git tag, git push, npm publish', function(type){ - + //defaults var options = this.options({ bump: true, @@ -79,7 +79,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 + '"'; } @@ -122,7 +122,7 @@ module.exports = function(grunt){ .end(function(res){ if (res.statusCode === 201){ success(); - } + } else { grunt.fail.warn('Error creating github release. Response: ' + res.text); } From ce91f5999918fe3efae15302afc0c17ce09a124e Mon Sep 17 00:00:00 2001 From: Jonathan Kim Date: Wed, 4 Dec 2013 15:02:40 -0500 Subject: [PATCH 4/5] Fixes. --- tasks/grunt-release.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/tasks/grunt-release.js b/tasks/grunt-release.js index 2abc403..b3bbf69 100644 --- a/tasks/grunt-release.js +++ b/tasks/grunt-release.js @@ -12,13 +12,11 @@ var semver = require('semver'); module.exports = function(grunt){ grunt.registerTask('bump-only', 'bump version only', function(type){ - //defaults - var options = this.options({ - file: grunt.config('pkgFile') || 'package.json' - }); + var file = grunt.config.get('release.options.file') || grunt.config('pkgFile') || 'package.json'; + grunt.log.writeln(file); - grunt.log('Only bumping the version.'); - bump(setup(options.file, type)); + 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){ @@ -34,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 @@ -133,11 +131,12 @@ module.exports = function(grunt){ done(); } } + }); - function setup(file, type){ + function setup(file, bump, type){ var pkg = grunt.file.readJSON(file); var newVersion = pkg.version; - if (options.bump) { + if (bump) { newVersion = semver.inc(pkg.version, type || 'patch'); } return {file: file, pkg: pkg, newVersion: newVersion}; @@ -149,5 +148,4 @@ module.exports = function(grunt){ grunt.log.ok('Version bumped to ' + config.newVersion); } - }); }; From 68bebc246355f4b8f19dddded462bf1f97a75233 Mon Sep 17 00:00:00 2001 From: Jonathan Kim Date: Wed, 4 Dec 2013 15:02:51 -0500 Subject: [PATCH 5/5] Update gruntfile to test both functions. --- Gruntfile.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) 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){