forked from refinery/refinerycms
/
refinery-update-core
60 lines (51 loc) · 2.82 KB
/
refinery-update-core
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
#!/usr/bin/env ruby
require 'fileutils'
REFINERY_ROOT = File.expand_path(File.dirname(__FILE__) << "/..")
RAILS_ROOT = ARGV.first unless defined? RAILS_ROOT
unless RAILS_ROOT.nil? or RAILS_ROOT.length == 0
# ensure asset directories exist.
dirs = [%w(public stylesheets), %w(public javascripts), %w(db migrate), %w(lib tasks)]
FileUtils::makedirs dirs.map {|dir| File.join(RAILS_ROOT, dir) }
# copy in the new assets.
assets = [%w(public stylesheets refinery), %w(public javascripts refinery)]
assets.each do |asset|
FileUtils::rm_rf File.join(RAILS_ROOT, asset), :secure => true # ensure the destination is clear.
FileUtils::cp_r File.join(REFINERY_ROOT, asset), File.join(RAILS_ROOT, asset) # copy the new assets into the project.
end
# copy in any new migrations.
FileUtils::cp Dir[File.join(REFINERY_ROOT, %w(db migrate *.rb))], File.join(RAILS_ROOT, %w(db migrate))
# copy any rake tasks from plugins to the main lib directory so they can be run.
FileUtils::cp Dir[File.join(REFINERY_ROOT, %w(** tasks *.rake))], File.join(RAILS_ROOT, %w(lib tasks))
# read in the config files
app_config = File.open(File.join(RAILS_ROOT, %w(config environment.rb)), "r").read
environment_updated = false
# backup app's environment.rb
unless (app_refinery_gems_section = app_config.scan(/(#===REFINERY REQUIRED GEMS===)([^#]*)(#===REFINERY END OF REQUIRED GEMS===)/).join("")).length == 0
# read in the config file in the gem
refinery_config = File.open(File.join(REFINERY_ROOT, %w(config environment.rb)), "r").read
FileUtils.cp File.join(RAILS_ROOT, %w(config environment.rb)), File.join(RAILS_ROOT, %w(config environment.autobackupbyrefinery.rb))
# write the new content into the file.
File.open(File.join(RAILS_ROOT, %w(config environment.rb)), "w").puts(app_config.gsub!(
app_refinery_gems_section,
refinery_config.scan(/(#===REFINERY REQUIRED GEMS===)([^#]*)(#===REFINERY END OF REQUIRED GEMS===)/).join("")
))
environment_updated = true
end
unless ARGV.include?("--from-refinery-installer")
puts "---------"
puts "Copied new Refinery core assets."
if environment_updated
puts "I've made a backup of your current config/environment.rb file as it has been updated with the latest Refinery RubyGem requirements."
puts "The backup is located at config/environment.autobackupbyrefinery.rb incase you need it."
end
puts ""
puts "=== ACTION REQUIRED ==="
puts "Please run rake db:migrate to ensure your database is at the correct version."
puts "Please also run rake gems:install to ensure you have the currently specified gems." if environment_updated
puts ""
end
else
unless ARGV.include?("--from-refinery-installer")
puts "Please specify the path of the refinery project that you want to update, i.e. refinery-update-core /path/to/project"
end
end