diff --git a/grunt/tasks/release.js b/grunt/tasks/release.js index 07d9b546..017837ea 100644 --- a/grunt/tasks/release.js +++ b/grunt/tasks/release.js @@ -1,3 +1,79 @@ -module.exports = function () { - +/** + * Register release-related tasks. + */ + +module.exports = function (grunt) { + + /** + * Update manifest file versions. + */ + + grunt.registerTask('version', function (version) { + var manifests = ['package', 'bower', 'component'] + manifests.forEach(function (file) { + file = file + '.json' + var json = grunt.file.read(file) + json = json.replace( + /"version"\s*:\s*"(.+?)"/, + '"version": "' + version + '"' + ) + grunt.file.write(file, json) + console.log('updated ' + blue(file)) + }) + }) + + /** + * Commit & push to branches & tags + npm publish + */ + + grunt.registerTask('git', function (version) { + var ShellTask = require('shell-task') + new ShellTask('git add -A') + .then('git commit -m "[release] ' + version + '"') + .then('git tag ' + version) + .then('git push') + .then('git push origin refs/tags/' + version) + .then('npm publish') + .run(this.async()) + }) + + /** + * Main release routine. + */ + + grunt.registerTask('release', function (version) { + + var semver = require('semver') + var readline = require('readline') + var done = this.async() + var current = grunt.config.get('version') + var next = semver.inc(current, version || 'patch') || version + + if (!semver.valid(next)) { + return grunt.fail.warn('Invalid version.') + } + if (semver.lt(next, current)) { + return grunt.fail.warn('Version is older than current.') + } + + readline.createInterface({ + input: process.stdin, + output: process.stdout + }).question('Releasing version ' + next + '. Continue? (Y/n)', function (answer) { + if (!answer || answer.toLowerCase() === 'y') { + console.log(blue('Releasing: ' + next)) + grunt.config.set('version', next) + grunt.task.run([ + 'default', + 'version:' + next + // 'git:' + next + ]) + } + done() + }) + }) + + function blue (str) { + return '\x1b[1m\x1b[34m' + str + '\x1b[39m\x1b[22m' + } } \ No newline at end of file diff --git a/package.json b/package.json index 9644bcef..71c41489 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,8 @@ "karma-jasmine": "^0.2.2", "karma-phantomjs-launcher": "^0.1.4", "karma-sauce-launcher": "^0.2.10", + "semver": "^4.0.3", + "shell-task": "^1.0.0", "uglify-js": "^2.4.15", "webpack": "^1.4.4" }