public
Description: Radiant is a no-fluff, open source content management system designed for small teams.
Homepage: http://radiantcms.org/
Clone URL: git://github.com/radiant/radiant.git
radiant / lib / tasks / framework.rake
100644 136 lines (118 sloc) 5.899 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
# Only define freeze and unfreeze tasks in instance mode
unless File.directory? "#{RAILS_ROOT}/app"
  namespace :radiant do
    namespace :freeze do
      desc "Lock this application to the current gems (by unpacking them into vendor/radiant)"
      task :gems do
        require 'rubygems'
        require 'rubygems/gem_runner'
        Gem.manage_gems
 
        radiant = (version = ENV['VERSION']) ?
          Gem.cache.search('radiant', "= #{version}").first :
          Gem.cache.search('radiant').sort_by { |g| g.version }.last
 
        version ||= radiant.version
 
        unless radiant
          puts "No radiant gem #{version} is installed. Do 'gem list radiant' to see what you have available."
          exit
        end
 
        puts "Freezing to the gems for Radiant #{radiant.version}"
        rm_rf "vendor/radiant"
 
        chdir("vendor") do
          Gem::GemRunner.new.run(["unpack", "radiant", "--version", "=#{version}"])
          FileUtils.mv(Dir.glob("radiant*").first, "radiant")
        end
      end
 
      desc "Lock to latest Edge Radiant or a specific revision with REVISION=X (ex: REVISION=245484e), a tag with TAG=Y (ex: TAG=0.6.6), or a branch with BRANCH=Z (ex: BRANCH=mental)"
      task :edge do
        $verbose = false
        unless system "git --version"
          $stderr.puts "ERROR: Must have git available in the PATH to lock this application to Edge Radiant"
          exit 1
        end
 
        radiant_git = "git://github.com/radiant/radiant.git"
 
        if File.exist?("vendor/radiant/.git/HEAD")
          system "cd vendor/radiant; git checkout master; git pull origin master"
        else
          system "git clone #{radiant_git} vendor/radiant"
        end
 
        case
        when ENV['TAG']
          system "cd vendor/radiant; git checkout -b v#{ENV['TAG']} #{ENV['TAG']}"
        when ENV['BRANCH']
          system "cd vendor/radiant; git checkout --track -b #{ENV['BRANCH']} origin/#{ENV['BRANCH']}"
        when ENV['REVISION']
          system "cd vendor/radiant; git checkout -b REV_#{ENV['REVISION']} #{ENV['REVISION']}"
        end
      end
    end
 
    desc "Unlock this application from freeze of gems or edge and return to a fluid use of system gems"
    task :unfreeze do
      rm_rf "vendor/radiant"
    end
 
    desc "Update both configs, scripts and public/javascripts from Radiant"
    task :update => [ "update:scripts", "update:javascripts", "update:configs", "update:images", "update:stylesheets" ]
 
    namespace :update do
      desc "Add new scripts to the instance script/ directory"
      task :scripts do
        local_base = "script"
        edge_base = "#{File.dirname(__FILE__)}/../../script"
 
        local = Dir["#{local_base}/**/*"].reject { |path| File.directory?(path) }
        edge = Dir["#{edge_base}/**/*"].reject { |path| File.directory?(path) }
        edge = edge.reject { |f| f =~ /(generate|plugin|destroy)$/ }
 
        edge.each do |script|
          base_name = script[(edge_base.length+1)..-1]
          next if local.detect { |path| base_name == path[(local_base.length+1)..-1] }
          if !File.directory?("#{local_base}/#{File.dirname(base_name)}")
            mkdir_p "#{local_base}/#{File.dirname(base_name)}"
          end
          install script, "#{local_base}/#{base_name}", :mode => 0755
        end
        install "#{File.dirname(__FILE__)}/../generators/instance/templates/instance_generate", "#{local_base}/generate", :mode => 0755
      end
 
      desc "Update your javascripts from your current radiant install"
      task :javascripts do
        FileUtils.mkdir_p("#{RAILS_ROOT}/public/javascripts/admin/")
        copy_javascripts = proc do |project_dir, scripts|
          scripts.reject!{|s| File.basename(s) == 'application.js'} if File.exists?(project_dir + 'application.js')
          FileUtils.cp(scripts, project_dir)
        end
        copy_javascripts[RAILS_ROOT + '/public/javascripts/', Dir["#{File.dirname(__FILE__)}/../../public/javascripts/*.js"]]
        copy_javascripts[RAILS_ROOT + '/public/javascripts/admin/', Dir["#{File.dirname(__FILE__)}/../../public/javascripts/admin/*.js"]]
      end
 
      desc "Update config/boot.rb from your current radiant install"
      task :configs do
        require 'erb'
        FileUtils.cp("#{File.dirname(__FILE__)}/../generators/instance/templates/instance_boot.rb", RAILS_ROOT + '/config/boot.rb')
        instance_env = "#{RAILS_ROOT}/config/environment.rb"
        tmp_env = "#{RAILS_ROOT}/config/environment.tmp"
        gen_env = "#{File.dirname(__FILE__)}/../generators/instance/templates/instance_environment.rb"
        backup_env = "#{RAILS_ROOT}/config/environment.bak"
        File.open(tmp_env, 'w') do |f|
          app_name = File.basename(File.expand_path(RAILS_ROOT))
          f.write ERB.new(File.read(gen_env)).result(binding)
        end
        unless FileUtils.compare_file(instance_env, tmp_env)
          FileUtils.cp(instance_env, backup_env)
          FileUtils.cp(tmp_env, instance_env)
          puts "** WARNING **
config/environment.rb was changed in Radiant 0.6.5. Your original has been
backed up to config/environment.bak and replaced with the packaged version.
Please copy your customizations to the new file."
        end
        FileUtils.rm(tmp_env)
      end
 
      desc "Update admin images from your current radiant install"
      task :images do
        project_dir = RAILS_ROOT + '/public/images/admin/'
        images = Dir["#{File.dirname(__FILE__)}/../../public/images/admin/*"]
        FileUtils.cp(images, project_dir)
      end
 
      desc "Update admin stylesheets from your current radiant install"
      task :stylesheets do
        project_dir = RAILS_ROOT + '/public/stylesheets/admin/'
        stylesheets = Dir["#{File.dirname(__FILE__)}/../../public/stylesheets/admin/*.css"]
        FileUtils.cp(stylesheets, project_dir)
      end
    end
  end
end