-
-
Save justvitalius/25318a1d71bcc657ee21 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
Rake task for finding unused images in rails app. | |
It requires 'ack' http://betterthangrep.com/ | |
MacOS: brew install ack | |
Linux: apt-get install ack-grep | |
Before lunch a task put .ackrc to home directory like ~/.ackrc |
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
--type-add=css=.sass,.less,.scss | |
--type-add=ruby=.rake,.rsel,.builder,.thor | |
--type-add=html=..html,.html.erb,.haml,.html.haml,.slim,.html.slim | |
--type-add=js=.js.erb,.coffee | |
--type-set=cucumber=.feature | |
--ignore-dir=vendor | |
--ignore-dir=log | |
--ignore-dir=tmp | |
--ignore-dir=doc | |
--ignore-dir=coverage | |
--ignore-dir=public/assets | |
--ignore-dir=spec/cassettes | |
--ignore-dir=features/cassettes | |
--smart-case | |
--sort-files | |
--color | |
--follow | |
--group |
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
# It requires ACK - http://betterthangrep.com/ | |
task :find_unused_images do | |
images = Dir.glob('app/assets/images/**/*') | |
images_to_delete = [] | |
images.each do |image| | |
unless File.directory?(image) | |
# print "\nChecking #{image}..." | |
print "." | |
result = `ack -1 --ruby --html --css --js #{File.basename(image)}` | |
if result.empty? | |
images_to_delete << image | |
else | |
end | |
end | |
end | |
puts "\n\nDelete #{images_to_delete.count} unused files running the command below:" | |
puts "rm #{images_to_delete.join(" ")}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment