Please build this for me, yesterday!

#!/usr/bin/env perl

=head1 NAME

App-sourcery

=head1 USAGE

# loads all @assets within $path and reports any not referenced in at-least one of the @sources
./sourcery --path=/var/www --asset=*.css --asset=*.js --asset=*.png --source=*.html

=head1 DESCRIPTION

Often times I'll find myself mucking around with an old webapp codebase that has had assets (css, js, images, etc) added to it over and over throughout its life, and being the neat-freak that I am I like to keep my codebase clean.

This (potentially) is a program that finds all files that match the specified asset and source patterns, puts them in their respective buckets, and then report the assets that are no longer being referenced anywhere.

=cut

# your contribution here please, thanks.

1 Comment

Is this harder than finding all of your desired asset files on disk:


find /var/www -name '*.css' -o -name '*.png' -print | perl -pe 's,/var/www,,' > /tmp/my-assets

And then grepping across your codebase for each of those files, recording which ones have no matches?


cat /tmp/my-assets | (while read asset; do
grep -r -q $asset *;
[[ $? -eq 0 ]] || echo $asset;
done) > /tmp/missing-assets

This won't work if you're trying to solve a slightly different problem ("how do I find which .css classes or javascript functions aren't used by any pages?").

Leave a comment

About Al Newkirk

user-pic ... proud Perl hacker, ask me anything!