Created
November 6, 2013 01:10
-
-
Save iHiD/7329237 to your computer and use it in GitHub Desktop.
Remove unused images from a Rails app
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
class Pruner | |
def initialize(root) | |
@skip = [ | |
'.', '..', # System files | |
'.DS_Store', # Mac files | |
'determiners' # Directories that are programatic | |
] | |
@root = root | |
end | |
def prune(directory = "") | |
p "Pruning #{directory}" | |
full_directory = "#{@root}#{directory}" | |
Dir.new(full_directory).each do |filename| | |
next if @skip.include?(filename) | |
filepath = "#{@root}#{directory}#{filename}" | |
if File.directory?(filepath) | |
prune("#{directory}#{filename}/") | |
next | |
end | |
#p "File: #{filename}" | |
cmd = "git grep '#{directory}#{filename}' | wc -l" | |
#p cmd | |
count = `#{cmd}`.strip.to_i | |
if count == 0 | |
p "- #{directory}#{filename}" | |
File.delete(filepath) | |
else | |
p "+ #{directory}#{filename}" | |
end | |
end | |
end | |
end | |
root = "/Users/iHiD/Projects/meducation/website/app/assets/images/" | |
Pruner.new(root).prune |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment