File: Rakefile

package info (click to toggle)
ruby-sinatra-contrib 1.4.7-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 572 kB
  • ctags: 392
  • sloc: ruby: 4,722; makefile: 2
file content (65 lines) | stat: -rw-r--r-- 2,066 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
require 'open-uri'
require 'yaml'
require 'sinatra/contrib/version'

desc "run specs"
task(:spec) { ruby '-S rspec spec -cw' }
task(:test => :spec)
task(:default => :spec)

namespace :doc do
  task :readmes do
    Dir.glob 'lib/sinatra/*.rb' do |file|
      excluded_files = %w[lib/sinatra/contrib.rb lib/sinatra/capture.rb lib/sinatra/engine_tracking.rb]
      next if excluded_files.include?(file)
      doc  = File.read(file)[/^module Sinatra(\n)+(  #[^\n]*\n)*/m].scan(/^ *#(?!#) ?(.*)\n/).join("\n")
      file = "doc/#{file[4..-4].tr("/_", "-")}.rdoc"
      Dir.mkdir "doc" unless File.directory? "doc"
      puts "writing #{file}"
      File.open(file, "w") { |f| f << doc }
    end
  end

  task :all => [:readmes]
end

desc "generate documentation"
task :doc => 'doc:all'

desc "generate gemspec"
task 'sinatra-contrib.gemspec' do
  content = File.read 'sinatra-contrib.gemspec'

  fields = {
    :authors => `git shortlog -sn`.scan(/[^\d\s].*/),
    :email   => `git shortlog -sne`.scan(/[^<]+@[^>]+/),
    :files   => `git ls-files`.split("\n").reject { |f| f =~ /^(\.|Gemfile)/ }
  }

  fields.each do |field, values|
    updated = "  s.#{field} = ["
    updated << values.map { |v| "\n    %p" % v }.join(',')
    updated << "\n  ]"
    content.sub!(/  s\.#{field} = \[\n(    .*\n)*  \]/, updated)
  end

  File.open('sinatra-contrib.gemspec', 'w') { |f| f << content }
end

task :gemspec => 'sinatra-contrib.gemspec'

task :release => :gemspec do
  sh <<-SH
    rm -Rf sinatra-contrib*.gem &&
    gem build sinatra-contrib.gemspec &&
    gem install sinatra-contrib*.gem --local &&
    gem push sinatra-contrib*.gem  &&
    git commit --allow-empty -a -m '#{Sinatra::Contrib::VERSION} release'  &&
    git tag -s v#{Sinatra::Contrib::VERSION} -m '#{Sinatra::Contrib::VERSION} release'  &&
    git tag -s #{Sinatra::Contrib::VERSION} -m '#{Sinatra::Contrib::VERSION} release'  &&
    git push && (git push origin master || true) &&
    git push --tags && (git push origin --tags || true)
  SH
end