require 'rake'
require 'spec/rake/spectask'


def include_autumn
  require "pathname"
  begin
    # Dev-time paths, for checking gems and trees in-place (like skel)
    if Pathname.new(__FILE__).dirname.join("lib","autumn.rb").file?
      $LOAD_PATH.unshift Pathname.new(__FILE__).dirname.expand_path.join("lib")
    elsif Pathname.new(__FILE__).dirname.join("..").expand_path.join("autumn.rb").file?
      $LOAD_PATH.unshift Pathname.new(__FILE__).dirname.join("..").expand_path
    end
    require "autumn"
    require "autumn/genesis"
  rescue LoadError
    require "rubygems"
    require "autumn"
    require "autumn/genesis"
  end
end

task :default do
  puts 'Type "rake --tasks" to see a list of tasks you can perform.'
end

# Load the Autumn environment.
task :environment do
  include_autumn
  AL_ROOT = File.dirname(__FILE__)
  @genesis = Autumn::Genesis.new
  @genesis.load_global_settings
  @genesis.load_season_settings
end

task :boot do
  include_autumn
  AL_ROOT = File.dirname(__FILE__)
  @genesis = Autumn::Genesis.new
  @genesis.boot! false
end

# Load tasks from main tasks
Dir["tasks/**/*.rake"].each do |task|
  load task
end

# Load any custom Rake tasks in the bot's tasks directory.
Dir["leaves/*"].each do |leaf|
  leaf_name = File.basename(leaf, ".rb").downcase
  namespace leaf_name.to_sym do # Tasks are placed in a namespace named after the leaf
    FileList["leaves/#{leaf_name}/tasks/**/*.rake"].sort.each do |task|
      load task
    end
  end
end
