Skip to content

Instantly share code, notes, and snippets.

@aenain
Created May 20, 2013 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aenain/5612073 to your computer and use it in GitHub Desktop.
Save aenain/5612073 to your computer and use it in GitHub Desktop.
Put this file in Rails.root/script directory and make precompiling assets easy as possible again! Why? Removing appropriate files after precompiling assets seems inefficient.
#!/bin/bash
bundle exec rake assets:precompile
repository_root=$(git rev-parse --show-toplevel)
assets_directory="$repository_root/public/assets"
# 1. reads diff from the manifest.yml
# 2. takes only those lines which represent replaced assets
# 3. remove duplicates like: application.js => application/index.js
# 4. extracts filename from sth like: application.js: application-21sda697d128sad12312dsa.js
files_to_remove=$(git diff "$assets_directory/manifest.yml" | egrep '^[-]\w+' | grep -v '/index.*:' | sed -E 's/^[^:]+:[[:space:]]//')
for file in $files_to_remove
do
# wildcard is to match compressed files as well
git rm "$assets_directory/$file*"
done
git add $assets_directory
git commit -m 'rake assets:precompile' --no-edit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment