Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 171 lines (148 sloc) 5.169 kb
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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
# Simple release is: rake version:bump:patch publish

require 'pathname'
require 'rake/clean'
require 'rake/rdoctask'
require 'rake/gempackagetask'
require 'fileutils'
require 'sdoc'
require File.dirname(__FILE__) + '/versioner'

include FileUtils

ROOT = Pathname(__FILE__).dirname.expand_path
GEM_NAME = 'padrino-framework'
GEM_VERSION = ROOT.join('VERSION').read.chomp
VERSIONER = Versioner.new(GEM_VERSION, Dir[File.dirname(__FILE__) + '/**/VERSION'])

padrino_gems = [
  "padrino-core",
  "padrino-gen",
  "padrino-helpers",
  "padrino-mailer",
  "padrino-admin",
  "padrino"
]

GEM_PATHS = padrino_gems.freeze

def rake_command(command)
  sh "#{Gem.ruby} -S rake #{command}", :verbose => true
end

%w(install gemspec build).each do |task_name|
  desc "Run #{task_name} for all projects"
  task task_name do
    GEM_PATHS.each do |dir|
      Dir.chdir(dir) { rake_command(task_name) }
    end
  end
end

desc "Clean pkg and other stuff"
task :clean do
  GEM_PATHS.each do |dir|
    Dir.chdir(dir) do
      %w(doc tmp pkg coverage).each { |dir| FileUtils.rm_rf dir }
    end
  end
end

desc "Clean pkg and other stuff"
task :uninstall do
  sh "gem search --no-version padrino | grep padrino | xargs sudo gem uninstall -a"
end

desc "Displays the current version"
task :version do
  puts "Current version: #{VERSIONER.current_version}"
end

desc "Commits all staged files"
task :commit, [:message] do |t, args|
  system("git commit -a -m \"#{args.message}\"")
end

desc "Generate documentation for the Rails framework"
Rake::RDocTask.new do |rdoc|
  rdoc.rdoc_dir = 'doc'
  rdoc.options << '--fmt' << 'shtml' # explictly set shtml generator
  rdoc.title = "Padrino Framework Documentation"
  rdoc.main = 'padrino-core/README.rdoc'
  rdoc.rdoc_files.include('padrino-core/lib/{*.rb,padrino-core}/*.rb')
  rdoc.rdoc_files.exclude('padrino-core/lib/padrino-core/cli.rb')
  rdoc.rdoc_files.exclude('padrino-core/lib/padrino-core/support_lite.rb')
  rdoc.rdoc_files.exclude('padrino-core/lib/padrino-core/server.rb')
  rdoc.rdoc_files.include('padrino-core/README.rdoc')
  rdoc.rdoc_files.include('padrino-admin/lib/**/*.rb')
  rdoc.rdoc_files.exclude('padrino-admin/lib/padrino-admin/generators')
  rdoc.rdoc_files.include('padrino-admin/README.rdoc')
  rdoc.rdoc_files.include('padrino-helpers/lib/**/*.rb')
  rdoc.rdoc_files.include('padrino-helpers/README.rdoc')
  rdoc.rdoc_files.include('padrino-mailer/lib/**/*.rb')
  rdoc.rdoc_files.include('padrino-mailer/README.rdoc')
end

namespace :version do
  namespace :bump do
    desc "Bump the gemspec by a major version."
    task :major => :versionomy do
      version = VERSIONER.bump!(:major)
      puts "Bumping the major version to #{version.to_s}"
      Rake::Task['gemspec'].invoke
      Rake::Task['commit'].invoke("Bumped version to #{version.to_s}")
    end

    desc "Bump the gemspec by a minor version."
    task :minor => :versionomy do
      version = VERSIONER.bump!(:minor)
      puts "Bumping the minor version to #{version.to_s}"
      Rake::Task['gemspec'].invoke
      Rake::Task['commit'].invoke("Bumped version to #{version.to_s}")
    end

    desc "Bump the gemspec by a patch version."
    task :tiny => :versionomy do |t|
      version = VERSIONER.bump!(:tiny)
      puts "Bumping the patch version to #{version.to_s}"
      Rake::Task['gemspec'].invoke
      Rake::Task['commit'].invoke("Bumped version to #{version.to_s}")
    end

    task :versionomy do
      require 'versionomy' unless defined?(Versionomy) # gem install versionomy
    end
  end
end

desc "Create main README.rdoc"
task :readme do
  copyright = "== Copyright\n\nCopyright (c) 2010 Padrino. See LICENSE for details."
  readme = %w(core gen helpers admin mailer cache).collect do |gem|
    File.read("padrino-#{gem}/README.rdoc").gsub(copyright,"").strip
  end
  readme << copyright
  File.open("README.rdoc", "w"){ |f| f.puts readme.join("\n\n") }
  puts "Created correctly README.rdoc"
end

desc "Publish doc on padrino.github.com"
task :publish_doc do
  puts "Publishing doc on padrino.github.com ..."
  rake_command("readme")
  sh 'git clone git@github.com:padrino/padrino.github.com.git'
  rake_command("rdoc")
  FileUtils.cp_r("doc/.", "padrino.github.com/api")
  Dir.chdir('padrino.github.com') do
    sh 'git add *'
    sh 'git commit -m "Updated docs."'
    sh 'git push origin master'
  end
  FileUtils.rm_rf "padrino.github.com"
  FileUtils.rm_rf "doc"
end

desc "Release all padrino gems"
task :publish do
  puts "Pushing to Gemcutter..."
  GEM_PATHS.each do |dir|
    Dir.chdir(dir) { rake_command("gemcutter:release") }
  end
  puts "Pushing to RubyForge..."
  GEM_PATHS.each do |dir|
    Dir.chdir(dir) { rake_command("rubyforge:release") }
  end
  rake_command("clean")
end

desc "Run tests for all padrino stack gems"
task :default => :test

desc "Run tests for all padrino stack gems"
task :test do
  # Omit the padrino metagem since no tests there
  GEM_PATHS[0..-2].each do |gem|
    Dir.chdir(File.join(ROOT, gem)) { rake_command "test" }
  end
end

desc "Execute a fresh install removing all padrino version and then reinstall all gems"
task :fresh => [:uninstall, :install, :clean]
Something went wrong with that request. Please try again.