Created
May 20, 2013 12:58
-
-
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.
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
#!/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