public
Created — forked from soffes/clean_assets.rb

Rake task to clean unused images in your iOS project

  • Download Gist
clean_assets.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
desc 'Remove unused images'
task :clean_assets do
require 'set'
 
all = Set.new
used = Set.new
unused = Set.new
 
# White list
used.merge %w{Icon Icon-29 Icon-50 Icon-58 Icon-72 Icon-114}
 
regex = /\[UIImage imageNamed:@"([a-zA-Z0-9\-_]+).png"\]/
Dir.glob('Classes/*.m').each do |path|
used.merge File.open(path).read.scan(regex).flatten
end
 
Dir.glob('Resources/Images/*.png').each do |path|
next if path.include? '@2x.png'
all << path.gsub('Resources/Images/', '').gsub('.png', '') # My regex skills need work
end
 
unused = all - used
unused.each do |key|
`rm -f Resources/Images/#{key}.png Resources/Images/#{key}@2x.png`
end
 
puts "#{all.length} total found"
puts "#{used.length} used found"
puts "#{unused.length} deleted"
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.