Class: Utopia::Command::Site::Update
- Inherits:
-
Samovar::Command
- Object
- Samovar::Command
- Utopia::Command::Site::Update
- Defined in:
- lib/utopia/command/site.rb
Overview
Update a local site.
Instance Method Summary collapse
- #invoke(parent) ⇒ Object
-
#move_static! ⇒ Object
Move legacy
pages/_statictopublic/_static.
Instance Method Details
#invoke(parent) ⇒ Object
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 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/utopia/command/site.rb', line 121 def invoke(parent) 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 Setup::Site::DIRECTORIES.each do |directory| FileUtils.mkdir_p(File.join(destination_root, directory)) end Setup::Site::OLD_PATHS.each do |path| path = File.join(destination_root, path) $stderr.puts "\tRemoving #{path}..." FileUtils.rm_rf(path) end Setup::Site::CONFIGURATION_FILES.each do |configuration_file| source_path = File.join(Setup::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 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", *Setup::Site::CONFIGURATION_FILES) or fail "could not add files" move_static! # 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! ⇒ Object
Move legacy pages/_static to public/_static.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/utopia/command/site.rb', line 102 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 |