Skip to content

Instantly share code, notes, and snippets.

@gogiel
Created December 10, 2014 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gogiel/a1fa827f5241bc543e4d to your computer and use it in GitHub Desktop.
Save gogiel/a1fa827f5241bc543e4d to your computer and use it in GitHub Desktop.
Find unused assets
# Requires `brew install ag`
dirname = ARGV[0]
records = Dir.glob(File.join(dirname, "**/*"))
possible_extensions = %w(jpeg jpg svg gif png css scss js coffee htc ejs jst).map{|ext| ".#{ext}"}
names = records.reject{|path| File.directory?(path) }.map do |path|
name = File.basename path
while true
ext = File.extname(name)
if possible_extensions.include? ext
name = File.basename name, ext
else
break
end
end
[name, path]
end
names.each do |data|
name, path = data
`ag '#{name}' --ignore '*.svg' > /dev/null`
if $? != 0
puts path
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment