require File.expand_path(File.join(File.dirname(__FILE__), "..", "rake_helpers"))

NAME = "merb"
AUTHOR = "Merb Team"
EMAIL = "team@merbivore.com"
HOMEPAGE = "http://merbivore.com/"
SUMMARY = "(merb-core + merb-more + DM) == Merb stack"

# For RubyForge release task
RUBY_FORGE_PROJECT  = "merb"
PROJECT_URL         = HOMEPAGE
PROJECT_SUMMARY     = SUMMARY
PROJECT_DESCRIPTION = SUMMARY

GEM_AUTHOR = AUTHOR
GEM_EMAIL  = EMAIL

GEM_NAME    = NAME
PKG_BUILD   = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
GEM_VERSION = Merb::VERSION  + PKG_BUILD
DM_VERSION  = Merb::DM_VERSION

RELEASE_NAME    = "REL #{GEM_VERSION}"

gems = [
  ["merb-core",             "= #{GEM_VERSION}"],
  ["merb-action-args",      "= #{GEM_VERSION}"],
  ["merb-assets",           "= #{GEM_VERSION}"],
  ["merb-auth",             "= #{GEM_VERSION}"],
  ["merb-cache",            "= #{GEM_VERSION}"],
  ["merb-exceptions",       "= #{GEM_VERSION}"],
  ["merb-gen",              "= #{GEM_VERSION}"],
  ["merb-haml",             "= #{GEM_VERSION}"],
  ["merb-helpers",          "= #{GEM_VERSION}"],
  ["merb-mailer",           "= #{GEM_VERSION}"],
  ["merb-param-protection", "= #{GEM_VERSION}"],
  ["merb-slices",           "= #{GEM_VERSION}"],
  ["merb_datamapper",       "= #{GEM_VERSION}"],
  ["do_sqlite3",            "~> #{DM_VERSION}"],
  ["dm-timestamps",         "~> #{DM_VERSION}"],
  ["dm-types",              "~> #{DM_VERSION}"],
  ["dm-aggregates",         "~> #{DM_VERSION}"],
  ["dm-validations",        "~> #{DM_VERSION}"],
  ["dm-sweatshop",          "~> #{DM_VERSION}"],
  ["dm-serializer",         "~> #{DM_VERSION}"]
]

merb_spec = Gem::Specification.new do |s|
  s.rubyforge_project = 'merb'
  s.name         = NAME
  s.version      = GEM_VERSION
  s.platform     = Gem::Platform::RUBY
  s.author       = AUTHOR
  s.email        = EMAIL
  s.homepage     = HOMEPAGE
  s.summary      = SUMMARY
  s.description  = SUMMARY
  s.files        = %w(LICENSE README Rakefile) + Dir.glob("{lib}/**/*")
  s.required_rubygems_version = ">= 1.3.0"
  gems.each do |gem, version|
    s.add_dependency gem, version
  end
end

Rake::GemPackageTask.new(merb_spec) do |package|
  package.gem_spec = merb_spec
end

require "extlib/tasks/release"

task :package => ["lib/merb.rb"]
desc "Create merb.rb"
task "lib/merb.rb" do
  mkdir_p "lib"
  File.open("lib/merb.rb","w+") do |file|
    file.puts "### AUTOMATICALLY GENERATED. DO NOT EDIT!"
    gems.each do |pair|
      g, _ = pair
      file.puts "require '#{g}'"
    end
  end
end

desc "Bundle up all the merb-more gems"
task :bundle => [:package] do
  mkdir_p "bundle"
  cp "pkg/merb-#{GEM_VERSION}.gem", "bundle"
  cp "pkg/merb-more-#{GEM_VERSION}.gem", "bundle"
  gems.each do |gem|
    sh %{cp #{gem}/pkg/#{gem}-#{Merb::MORE_VERSION}.gem bundle/}
  end
end

desc "Install the gem"
task :install do
  Merb::RakeHelper.install(GEM_NAME, :version => GEM_VERSION)
end

desc "Uninstall the gem"
task :uninstall do
  Merb::RakeHelper.uninstall(GEM_NAME, :version => GEM_VERSION)
end

desc "create a gemspec file"
task :make_spec do
  File.open("#{NAME}.gemspec", "w") do |file|
    file.puts spec.to_ruby
  end
end
