class Utopia::Command::Site::Update
Update
a local site.
Public Instance Methods
call()
click to toggle source
# File lib/utopia/command/site.rb, line 154 def call destination_root = parent.root branch_name = "utopia-upgrade-#{Utopia::VERSION}" $stderr.puts "Upgrading #{destination_root}..." Dir.chdir(destination_root) do system('git', 'checkout', '-b', branch_name) or fail "could not change branch" end DIRECTORIES.each do |directory| FileUtils.mkdir_p(File.join(destination_root, directory)) end OLD_PATHS.each do |path| path = File.join(destination_root, path) $stderr.puts "\tRemoving #{path}..." FileUtils.rm_rf(path) end CONFIGURATION_FILES.each do |configuration_file| source_path = File.join(Site::ROOT, configuration_file) destination_path = File.join(destination_root, configuration_file) $stderr.puts "Updating #{destination_path}..." FileUtils.copy_entry(source_path, destination_path) buffer = File.read(destination_path).gsub('$UTOPIA_VERSION', Utopia::VERSION) File.open(destination_path, "w") { |file| file.write(buffer) } end Environment.defaults(destination_root) begin Dir.chdir(destination_root) do # Stage any files that have been changed or removed: system("git", "add", "-u") or fail "could not add files" # Stage any new files that we have explicitly added: system("git", "add", *Site::CONFIGURATION_FILES) or fail "could not add files" move_static! update_gemfile! # Commit all changes: system("git", "commit", "-m", "Upgrade to utopia #{Utopia::VERSION}.") or fail "could not commit changes" # Checkout master.. system("git", "checkout", "master") or fail "could not checkout master" # and merge: system("git", "merge", "--squash", "--no-commit", branch_name) or fail "could not merge changes" end rescue RuntimeError $stderr.puts "** Detected error with upgrade, reverting changes. Some new files may still exist in tree. **" system("git", "checkout", "master") ensure system("git", "branch", "-D", branch_name) end end
move_static!()
click to toggle source
Move legacy `pages/_static` to `public/_static`.
# File lib/utopia/command/site.rb, line 126 def move_static! # If public/_static doens't exist, we are done. return unless File.exist? 'pages/_static' if File.exist? 'public/_static' if File.lstat("public/_static").symlink? FileUtils.rm_f "public/_static" else warn "Can't move pages/_static to public/_static, destination already exists." return end end # One more sanity check: if File.directory? 'pages/_static' system("git", "mv", "pages/_static", "public/") end end
update_gemfile!()
click to toggle source
Move `Gemfile` to `gems.rb`.
# File lib/utopia/command/site.rb, line 146 def update_gemfile! # If `Gemfile` doens't exist, we are done: return unless File.exist?('Gemfile') system("git", "mv", "Gemfile", "gems.rb") system("git", "mv", "Gemfile.lock", "gems.locked") end