Thorfile 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. module GemHelpers
  2. def generate_gemspec
  3. $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), "lib")))
  4. require "rack/test"
  5. Gem::Specification.new do |s|
  6. s.name = "rack-test"
  7. s.version = Rack::Test::VERSION
  8. s.author = "Bryan Helmkamp"
  9. s.email = "bryan@brynary.com"
  10. s.homepage = "http://github.com/brynary/rack-test"
  11. s.summary = "Simple testing API built on Rack"
  12. s.description = <<-EOS.strip
  13. Rack::Test is a small, simple testing API for Rack apps. It can be used on its
  14. own or as a reusable starting point for Web frameworks and testing libraries
  15. to build on. Most of its initial functionality is an extraction of Merb 1.0's
  16. request helpers feature.
  17. EOS
  18. s.rubyforge_project = "rack-test"
  19. require "git"
  20. repo = Git.open(".")
  21. s.files = normalize_files(repo.ls_files.keys - repo.lib.ignored_files)
  22. s.test_files = normalize_files(Dir['spec/**/*.rb'] - repo.lib.ignored_files)
  23. s.has_rdoc = true
  24. s.extra_rdoc_files = %w[README.rdoc MIT-LICENSE.txt]
  25. s.add_dependency "rack", ">= 1.0"
  26. end
  27. end
  28. def normalize_files(array)
  29. # only keep files, no directories, and sort
  30. array.select do |path|
  31. File.file?(path)
  32. end.sort
  33. end
  34. # Adds extra space when outputting an array. This helps create better version
  35. # control diffs, because otherwise it is all on the same line.
  36. def prettyify_array(gemspec_ruby, array_name)
  37. gemspec_ruby.gsub(/s\.#{array_name.to_s} = \[.+?\]/) do |match|
  38. leadin, files = match[0..-2].split("[")
  39. leadin + "[\n #{files.split(",").join(",\n ")}\n ]"
  40. end
  41. end
  42. def read_gemspec
  43. @read_gemspec ||= eval(File.read("rack-test.gemspec"))
  44. end
  45. def sh(command)
  46. puts command
  47. system command
  48. end
  49. end
  50. class Default < Thor
  51. include GemHelpers
  52. desc "gemspec", "Regenerate rack-test.gemspec"
  53. def gemspec
  54. File.open("rack-test.gemspec", "w") do |file|
  55. gemspec_ruby = generate_gemspec.to_ruby
  56. gemspec_ruby = prettyify_array(gemspec_ruby, :files)
  57. gemspec_ruby = prettyify_array(gemspec_ruby, :test_files)
  58. gemspec_ruby = prettyify_array(gemspec_ruby, :extra_rdoc_files)
  59. file.write gemspec_ruby
  60. end
  61. puts "Wrote gemspec to rack-test.gemspec"
  62. read_gemspec.validate
  63. end
  64. desc "build", "Build a rack-test gem"
  65. def build
  66. sh "gem build rack-test.gemspec"
  67. FileUtils.mkdir_p "pkg"
  68. FileUtils.mv read_gemspec.file_name, "pkg"
  69. end
  70. desc "install", "Install the latest built gem"
  71. def install
  72. sh "gem install --local pkg/#{read_gemspec.file_name}"
  73. end
  74. desc "release", "Release the current branch to GitHub and Gemcutter"
  75. def release
  76. gemspec
  77. build
  78. Release.new.tag
  79. Release.new.gem
  80. end
  81. end
  82. class Release < Thor
  83. include GemHelpers
  84. desc "tag", "Tag the gem on the origin server"
  85. def tag
  86. release_tag = "v#{read_gemspec.version}"
  87. sh "git tag -a #{release_tag} -m 'Tagging #{release_tag}'"
  88. sh "git push origin #{release_tag}"
  89. end
  90. desc "gem", "Push the gem to Gemcutter"
  91. def gem
  92. sh "gem push pkg/#{read_gemspec.file_name}"
  93. end
  94. end