Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 153 lines (131 sloc) 4.909 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
require 'rake'
require 'rubygems/package_task'
require 'thor/group'

spec = eval(File.read('spree.gemspec'))
Gem::PackageTask.new(spec) do |pkg|
  pkg.gem_spec = spec
end

task :default => [:spec, :cucumber ]

desc "clean the whole repository by removing all the generated files"
task :clean do
  cmd = "rm -rf sandbox"; puts cmd; system cmd
  %w(api auth core dash promo).each do |gem_name|
    cmd = "rm #{gem_name}/Gemfile*"; puts cmd; system cmd
    cmd = "cd #{gem_name}/spec && rm -rf test_app"; puts cmd; system cmd
  end
end

desc "run all tests for ci"
task :ci do
  cmd = "bundle update"; puts cmd; system cmd;

  %w(sqlite3 mysql).each do |database_name|
    %w(api auth core promo).each do |gem_name|
      puts "########################### #{gem_name}|#{database_name} (features) ###########################"
      cmd = "rm #{gem_name}/Gemfile*"; puts cmd; system cmd
      sh "cd #{gem_name} && #{$0} test_app DB_NAME='#{database_name}'"
      sh "cd #{gem_name} && bundle exec cucumber -p ci"
    end

    %w(api auth core dash promo).each do |gem_name|
      puts "########################### #{gem_name}|#{database_name} (spec) ###########################"
      cmd = "rm #{gem_name}/Gemfile*"; puts cmd; system cmd
      sh "cd #{gem_name} && #{$0} test_app DB_NAME='#{database_name}'"
      sh "cd #{gem_name} && #{$0} spec"
    end
  end
end

desc "run spec test for all gems"
task :spec do
  %w(api auth core dash promo).each do |gem_name|
    puts "########################### #{gem_name} #########################"
    cmd = "rm #{gem_name}/Gemfile*"; puts cmd; system cmd
    cmd = "cd #{gem_name} && bundle exec #{$0} test_app"; puts cmd; system cmd
    cmd = "cd #{gem_name} && bundle exec #{$0} spec"; puts cmd; system cmd
  end
end

desc "run cucumber test for all gems"
task :cucumber do
  %w(api auth core promo).each do |gem_name|
    puts "########################### #{gem_name} #########################"
    cmd = "rm #{gem_name}/Gemfile*"; puts cmd; system cmd
    cmd = "cd #{gem_name} && bundle exec rake test_app"; puts cmd; system cmd
    cmd = "cd #{gem_name} && bundle exec cucumber -p ci"; puts cmd; system cmd
  end
end

namespace :gem do
  desc "run rake gem for all gems"
  task :build do
    %w(core auth api dash promo sample).each do |gem_name|
      puts "########################### #{gem_name} #########################"
      cmd = "rm -rf #{gem_name}/pkg"; puts cmd; system cmd
      cmd = "cd #{gem_name} && bundle exec rake gem"; puts cmd; system cmd
    end
    cmd = "rm -rf pkg"; puts cmd; system cmd
    cmd = "bundle exec rake gem"; puts cmd; system cmd
  end
end

namespace :gem do
  desc "run gem install for all gems"
  task :install do
    version = File.read(File.expand_path("../SPREE_VERSION", __FILE__)).strip

    %w(core auth api dash promo sample).each do |gem_name|
      puts "########################### #{gem_name} #########################"
      cmd = "rm #{gem_name}/pkg"; puts cmd; system cmd
      cmd = "cd #{gem_name} && bundle exec rake gem"; puts cmd; system cmd
      cmd = "cd #{gem_name}/pkg && gem install spree_#{gem_name}-#{version}.gem"; puts cmd; system cmd
    end
    cmd = "rm -rf pkg"; puts cmd; system cmd
    cmd = "bundle exec rake gem"; puts cmd; system cmd
    cmd = "gem install pkg/spree-#{version}.gem"; puts cmd; system cmd
  end
end

namespace :gem do
  desc "Release all gems to gemcutter. Package spree components, then push spree"
  task :release do
    version = File.read(File.expand_path("../SPREE_VERSION", __FILE__)).strip

    %w(core auth api dash promo sample).each do |gem_name|
      puts "########################### #{gem_name} #########################"
      cmd = "cd #{gem_name}/pkg && gem push spree_#{gem_name}-#{version}.gem"; puts cmd; system cmd
    end
    cmd = "gem push pkg/spree-#{version}.gem"; puts cmd; system cmd
  end
end

desc "Creates a sandbox application for testing your Spree code"
task :sandbox do

  class SandboxGenerator < Thor::Group
    include Thor::Actions

    def generate_app
      remove_directory_if_exists("sandbox")
      run "bundle exec rails new sandbox -GJT"
    end

    def append_gemfile
      inside "sandbox" do
        append_file "Gemfile" do
<<-gems
gem 'spree', :path => '../' \n
if RUBY_VERSION < "1.9"
gem "ruby-debug"
else
gem "ruby-debug19"
end

gems
        end
      end
    end

    def install_generators
      inside "sandbox" do
        run 'rails g spree:site -f'
        run 'bundle exec rake spree:install'
        run 'bundle exec rake spree_sample:install'
      end
    end

    def run_bootstrap
      inside "sandbox" do
        run 'bundle exec rake db:bootstrap AUTO_ACCEPT=true'
      end
    end

    private
    def remove_directory_if_exists(path)
      run "rm -r #{path}" if File.directory?(path)
    end
  end

  SandboxGenerator.start
end
Something went wrong with that request. Please try again.