From 492657f7418084ad8d531f5d7df3cdf7d25d5e6f Mon Sep 17 00:00:00 2001 From: Diego Netto Date: Thu, 5 Feb 2015 11:23:06 -0800 Subject: [PATCH] chore(build): Use best practices to release new versions --- Gruntfile.js | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 8 ++++++- 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 Gruntfile.js diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..5d4453f --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,59 @@ +'use strict'; +var semver = require('semver'); + +module.exports = function (grunt) { + require('load-grunt-tasks')(grunt); + + grunt.initConfig({ + pkg: grunt.file.readJSON('package.json'), + changelog: { + options: { + dest: 'CHANGELOG.md', + versionFile: 'package.json' + } + }, + release: { + options: { + commitMessage: '<%= version %>', + tagName: 'v<%= version %>', + bump: false, // we have our own bump + file: 'package.json' + } + }, + stage: { + options: { + files: ['CHANGELOG.md'] + } + } + }); + + grunt.registerTask('bump', 'bump manifest version', function (type) { + var options = this.options({ + file: grunt.config('pkgFile') || 'package.json' + }); + + function setup(file, type) { + var pkg = grunt.file.readJSON(file); + var newVersion = pkg.version = semver.inc(pkg.version, type || 'patch'); + return { + file: file, + pkg: pkg, + newVersion: newVersion + }; + } + + var config = setup(options.file, type); + grunt.file.write(config.file, JSON.stringify(config.pkg, null, ' ') + '\n'); + grunt.log.ok('Version bumped to ' + config.newVersion); + }); + + grunt.registerTask('stage', 'git add files before running the release task', function () { + var files = this.options().files; + grunt.util.spawn({ + cmd: process.platform === 'win32' ? 'git.cmd' : 'git', + args: ['add'].concat(files) + }, grunt.task.current.async()); + }); + + grunt.registerTask('default', ['bump', 'changelog', 'stage', 'release']); +}; diff --git a/package.json b/package.json index 7194d25..4c4bfda 100644 --- a/package.json +++ b/package.json @@ -38,8 +38,14 @@ "yosay": "^1.0.2" }, "devDependencies": { + "grunt": "^0.4.5", + "grunt-conventional-changelog": "^1.1.0", + "grunt-release": "^0.11.0", + "load-grunt-tasks": "^3.1.0", + "marked": "^0.3.3", "mocha": "^2.1.0", - "mockery": "^1.4.0" + "mockery": "^1.4.0", + "semver": "^4.2.0" }, "peerDependencies": { "yo": ">=1.0.0"