release.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. var semver = require('semver'),
  2. readline = require('readline'),
  3. ShellTask = require('shell-task')
  4. module.exports = function (grunt) {
  5. grunt.registerTask('version', function (version) {
  6. ;['package', 'bower', 'component'].forEach(function (file) {
  7. file = file + '.json'
  8. var json = grunt.file.read(file)
  9. json = json.replace(/"version"\s*:\s*"(.+?)"/, '"version": "' + version + '"')
  10. grunt.file.write(file, json)
  11. console.log('updated ' + blue(file))
  12. })
  13. })
  14. grunt.registerTask('git', function (version) {
  15. new ShellTask('git add -A')
  16. .then('git commit -m Release-v' + version)
  17. .then('git tag v' + version)
  18. .then('git push')
  19. .then('git push origin v' + version)
  20. .run(this.async(), function (err) {
  21. grunt.fail.fatal(err)
  22. })
  23. })
  24. grunt.registerTask('release', function (version) {
  25. var done = this.async(),
  26. current = grunt.config('version'),
  27. next = semver.inc(current, version || 'patch') || version
  28. if (!semver.valid(next)) {
  29. return grunt.fail.warn('Invalid version.')
  30. }
  31. if (semver.lt(next, current)) {
  32. return grunt.fail.warn('Version is older than current.')
  33. }
  34. readline.createInterface({
  35. input: process.stdin,
  36. output: process.stdout
  37. }).question('Releasing version v' + next + '. Continue? (Y/n)', function (answer) {
  38. if (!answer || answer.toLowerCase() === 'y') {
  39. console.log(blue('Releasing: v' + next))
  40. grunt.task.run([
  41. 'jshint',
  42. 'build:' + next,
  43. 'test',
  44. 'version:' + next,
  45. 'git:' + next
  46. ])
  47. }
  48. done()
  49. })
  50. })
  51. }
  52. function blue (str) {
  53. return '\x1b[1m\x1b[34m' + str + '\x1b[39m\x1b[22m'
  54. }