Skip to content

Instantly share code, notes, and snippets.

@omgitsads
Forked from ilyakatz/before_compile_assets.rb
Created December 3, 2012 13:17
Show Gist options
  • Save omgitsads/4194994 to your computer and use it in GitHub Desktop.
Save omgitsads/4194994 to your computer and use it in GitHub Desktop.
Selective compilation
last_revision = run "cat #{current_path}/REVISION"
assets_modified = run "git diff --name-only #{last_revision} | grep '/assets/' | wc -l"
if assets_modified.output.to_i > 0
info "#{assets_modified} asset files changed detected. Compiling assets"
cd #{release_path} && PATH=#{release_path}/ey_bundler_binstubs:$PATH #{config.framework_envs} rake assets:precompile RAILS_GROUPS=assets"
else
info "No asset changes detected. Copying assets from previous"
current = shared_path + '/assets'
last_asset_path = shared_path + '/last_assets'
run <<-COMMAND
if [ -d #{current_path} ]; then
rm -rf #{last_asset_path} && mkdir #{last_asset_path} && mv #{current} #{last_asset_path} && mkdir -p #{current};
else
mkdir -p #{current} #{last_asset_path};
fi;
ln -nfs #{current} #{last_asset_path} #{current_path + '/public'}
COMMAND
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment