Rakefile 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. require 'rake/testtask'
  2. task :default => :test
  3. # SPECS =====================================================================
  4. desc 'Generate test coverage report'
  5. task :rcov do
  6. sh "rcov -Ilib:test test/*_test.rb"
  7. end
  8. desc 'Run tests (default)'
  9. Rake::TestTask.new(:test) do |t|
  10. t.test_files = FileList['test/*_test.rb']
  11. t.ruby_opts = ['-Itest']
  12. t.ruby_opts << '-rubygems' if defined? Gem
  13. end
  14. # PACKAGING =================================================================
  15. begin
  16. require 'rubygems'
  17. rescue LoadError
  18. end
  19. if defined?(Gem)
  20. SPEC = eval(File.read('tilt.gemspec'))
  21. def package(ext='')
  22. "pkg/tilt-#{SPEC.version}" + ext
  23. end
  24. desc 'Build packages'
  25. task :package => %w[.gem .tar.gz].map {|e| package(e)}
  26. desc 'Build and install as local gem'
  27. task :install => package('.gem') do
  28. sh "gem install #{package('.gem')}"
  29. end
  30. directory 'pkg/'
  31. file package('.gem') => %w[pkg/ tilt.gemspec] + SPEC.files do |f|
  32. sh "gem build tilt.gemspec"
  33. mv File.basename(f.name), f.name
  34. end
  35. file package('.tar.gz') => %w[pkg/] + SPEC.files do |f|
  36. sh "git archive --format=tar HEAD | gzip > #{f.name}"
  37. end
  38. desc 'Upload gem and tar.gz distributables to rubyforge'
  39. task :release => [package('.gem'), package('.tar.gz')] do |t|
  40. sh <<-SH
  41. rubyforge add_release sinatra tilt #{SPEC.version} #{package('.gem')} &&
  42. rubyforge add_file sinatra tilt #{SPEC.version} #{package('.tar.gz')}
  43. SH
  44. end
  45. end
  46. # GEMSPEC ===================================================================
  47. file 'tilt.gemspec' => FileList['{lib,test}/**','Rakefile'] do |f|
  48. # read version from tilt.rb
  49. version = File.read('lib/tilt.rb')[/VERSION = '(.*)'/] && $1
  50. # read spec file and split out manifest section
  51. spec = File.
  52. read(f.name).
  53. sub(/s\.version\s*=\s*'.*'/, "s.version = '#{version}'")
  54. parts = spec.split(" # = MANIFEST =\n")
  55. # determine file list from git ls-files
  56. files = `git ls-files`.
  57. split("\n").sort.reject{ |file| file =~ /^\./ }.
  58. map{ |file| " #{file}" }.join("\n")
  59. # piece file back together and write...
  60. parts[1] = " s.files = %w[\n#{files}\n ]\n"
  61. spec = parts.join(" # = MANIFEST =\n")
  62. spec.sub!(/s.date = '.*'/, "s.date = '#{Time.now.strftime("%Y-%m-%d")}'")
  63. File.open(f.name, 'w') { |io| io.write(spec) }
  64. puts "updated #{f.name}"
  65. end