Created
July 12, 2012 13:22
-
-
Save DTrierweiler/3098077 to your computer and use it in GitHub Desktop.
Enhancement of asset-precompile speedup
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
namespace :assets do | |
task :precompile, :roles => :web, :except => { :no_release => true } do | |
run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} asset_paths} | |
num_paths = capture("cat #{latest_release}/tmp/asset_paths").to_i | |
run %Q{rm #{latest_release}/tmp/asset_paths} | |
if num_paths == 0 # 0 means, there are no gems with asset paths | |
from = source.next_revision(current_revision) | |
if capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ app/assets/ | wc -l").to_i > 0 | |
run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile} | |
else | |
logger.info "Skipping asset pre-compilation because there were no asset changes" | |
end | |
else | |
run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile} | |
end | |
end | |
end | |
desc "Checks if there are any Gems with Assets, which need to be compiled" | |
task :asset_paths => :environment do | |
file = File.new("tmp/asset_paths", "w") | |
asset_paths = Rails.application.assets.paths | |
file.puts(asset_paths.reject!{|x| x.start_with?(Rails.root) || x.include?('jquery-rails')}.size) | |
file.close | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment