-
-
Save Narnach/4277584 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc "precompile assets (only if needed)" | |
task :precompile_assets do | |
puts "Diffing assets to check if we need to precompile" | |
precompile = true | |
# Only do this if we have a previous release | |
# Do a normal precompile on a force precompile | |
if previous_release && latest_release && !ENV['FORCE_PRECOMPILE'] | |
puts "Comparing asset sources of #{previous_release} and #{latest_release}." | |
# Gather all the names of the source files from your local machine. | |
# NOTE: it would be better to diff the filename lists of the previous and lastest release, but this will function. | |
files = ['Gemfile.lock', 'config/routes.rb'] | |
['app/assets', 'lib/assets', 'vendor/assets'].map{|d| Dir["#{d}/**/*.*"].each{ |f| files << f }} | |
begin | |
diff_commands = [] | |
files.each do |file| | |
diff_commands << "diff -w -q '#{previous_release}/#{file}' '#{latest_release}/#{file}'" | |
end | |
# Diff & copy, raises CommandError if any of the diffs fail | |
run diff_commands.join(' && ') | |
run "cp -R -p #{previous_release}/public/assets/ #{latest_release}/public/assets/" | |
precompile = false | |
rescue Capistrano::CommandError | |
puts "Diff detected, so we need to recompile our assets" | |
precompile = true | |
end | |
end | |
run "cd #{latest_release} && bundle exec rake i18n:js:export assets:precompile RAILS_ENV=production" if precompile | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment