You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #!/usr/bin/env ruby
  2. require 'json'
  3. def puts_c(color, str)
  4. puts "\x1b[#{color}m#{str}\x1b[0m"
  5. end
  6. # for tracking if bump was needed
  7. $bumped = false
  8. def did_bump
  9. if !$bumped
  10. puts "bump detected!"
  11. if `which uglifyjs`.empty?
  12. puts_c 31, "you need uglifyjs installed"
  13. puts "run `sudo npm install -g uglify-js`"
  14. exit 1
  15. end
  16. end
  17. $bumped = true
  18. end
  19. # get package.json version
  20. pckg_path = 'package.json'
  21. package = JSON.parse File.read pckg_path
  22. v = package['version']
  23. # check/bump version in `mustache.js` file
  24. mjs_path = 'mustache.js'
  25. mjs = File.read mjs_path
  26. mjs_re = /mustache.version = "([\d\.]*)"/
  27. if match = mjs.match(mjs_re)
  28. mjs_v = match.captures[0]
  29. if v != mjs_v then
  30. did_bump
  31. puts "> bumping version in file 'mustache.js': #{mjs_v} -> #{v}..."
  32. mjs.gsub! mjs_re, "mustache.version = \"#{v}\""
  33. File.open(mjs_path, 'w') {|f| f.write(mjs) }
  34. end
  35. else
  36. puts_c 31, "ERROR: Can't find 'mustache.version = \"x.x.x\"' in mustache.js"
  37. exit 1
  38. end
  39. # check/bump version in `mustache.js.nuspec` file
  40. nspc_path = 'mustache.js.nuspec'
  41. nspc = File.read nspc_path
  42. nspc_re = /<version>([\d\.]*)<\/version>/
  43. if match = nspc.match(nspc_re)
  44. nspc_v = match.captures[0]
  45. if v != nspc_v then
  46. did_bump
  47. puts "> bumping version in file 'mustache.js.nuspec': #{nspc_v} -> #{v}..."
  48. nspc.gsub! nspc_re, "<version>#{v}</version>"
  49. File.open(nspc_path, 'w') {|f| f.write(nspc) }
  50. end
  51. else
  52. puts_c 31, "ERROR: Can't find '<version>x.x.x</version>' in mustache.js.nuspec"
  53. exit 1
  54. end
  55. # check/bump version in `bower.json` file
  56. bwr_path = 'bower.json'
  57. bwr = File.read bwr_path
  58. bwr_re = /"version": "([\d\.]*)"/
  59. if match = bwr.match(bwr_re)
  60. bwr_v = match.captures[0]
  61. if v != bwr_v
  62. did_bump
  63. puts "> bumping version in file 'bower.json': #{bwr_v} -> #{v}..."
  64. bwr.gsub! bwr_re, "\"version\": \"#{v}\""
  65. File.open(bwr_path, 'w') {|f| f.write(bwr) }
  66. end
  67. else
  68. puts_c 31, "ERROR: Can't find '\"version\": \"x.x.x\"' in 'bower.json'"
  69. exit 1
  70. end
  71. # if bumped, do extra stuff and notify the user
  72. if $bumped
  73. # minify `mustache.js` using the Rakefile task
  74. puts "> minifying `mustache.js`..."
  75. `rake minify`
  76. # stage files for commit
  77. `git add #{pckg_path}`
  78. `git add #{mjs_path}`
  79. `git add #{nspc_path}`
  80. `git add #{bwr_path}`
  81. `git add mustache.min.js`
  82. `git commit -m "bump to version #{v}"`
  83. # notify codemonkey
  84. puts "staged bumped files and created commit"
  85. puts_c 32, "successfully bumped version to #{v}!"
  86. puts_c 33, "don't forget to `npm publish` and `spm publish`!"
  87. exit 1
  88. end
  89. exit 0