Skip to content

Instantly share code, notes, and snippets.

@dmiedema
Created March 6, 2014 17:44
Show Gist options
  • Save dmiedema/9395345 to your computer and use it in GitHub Desktop.
Save dmiedema/9395345 to your computer and use it in GitHub Desktop.
Check for which cocoapods are used or not used in your project. Super rough and not 100% accurate right now
#!/usr/bin/env ruby
#
#
#
$pods = Array.new
File.open("Podfile", "r") do |infile|
while (line = infile.gets)
pod = line.split(',')[0]
if !pod["pod"].nil? && pod[0] != '#'
$pods << pod.split(' ')[1][1...-1]
end
end # while line
end # end file reading
# puts pods
projectName = ''
Dir.glob('*.xcworkspace').each do |file|
projectName = file.split('.')[0]
end
puts projectName
usedPods = Array.new
def check_import(import)
values = import.split('/')
values.each { |value|
if $pods.include? value
return value
end
}
return nil
end
Dir.glob("#{projectName}/**/*.{h,m,pch}") do |file|
File.open(file, "r") do |infile|
while (line = infile.gets)
if !line['#import'].nil?
import = line.split(' ')[1][1...-3]
podname = check_import import
if !(podname).nil?
usedPods << podname
end
end
end
end # reading files
end # directory search
puts "### Used Pods ###"
puts usedPods
puts "### Unused Pods ###"
puts $pods - usedPods
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment