Created
November 7, 2018 13:09
-
-
Save lucasrenan/945460fc5ff0554ff27e4a12f010dd26 to your computer and use it in GitHub Desktop.
Modified version of "Rake task to find unused images on a Rails project"
This file contains hidden or 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
# Modified version of: https://gist.github.com/rafaelp/4467738 | |
# Uses ACK 2 library and parallalel gem | |
task :find_unused_images do | |
images = Dir.glob(Rails.root.join('app/assets/images/**/*')) | |
puts "Images found: #{images.count}" | |
images_to_delete = [] | |
Parallel.each(images, in_threads: 4) do |image| | |
unless File.directory?(image) | |
puts "Checking #{image}..." | |
# print "." | |
result = `ack -g -i '(app|public)' | ack -x -w '#{File.basename(image)}'` | |
if result.empty? | |
images_to_delete << image | |
else | |
end | |
end | |
end | |
puts "\n\nDelete unused files:" | |
images_to_delete.sort.each do |unused_file| | |
puts "rm #{unused_file}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment