Last active
June 15, 2016 13:08
-
-
Save k06a/b7bec2244b4155e0ed71de24a4f83439 to your computer and use it in GitHub Desktop.
Xcode xcasset usage detector
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
set -eu -o pipefail | |
function show_code { | |
while read ERROR_LOCATION; do | |
echo "$ERROR_LOCATION:: error: Missing imageset with name $1" | |
done < <(find "$PROJECT_NAME" -name '*.m' -print0 | xargs -0 grep -n -o -e "\[UIImage imageNamed:@\"$1\"\]" | cut -d ':' -f 1,2) | |
} | |
function show_img { | |
echo -n $(find "$PROJECT_NAME" -name "$1.imageset") | |
echo ":: error: No more refs to imageset $1" | |
} | |
function show_nonconst { | |
echo -n "$1" | |
echo " error: Non-const usage of UIImage's imageNamed" | |
} | |
USED_NAMES=$(find "$PROJECT_NAME" -name '*.m' -print0 | xargs -0 grep -h -o -e '\[UIImage imageNamed:@"[^"]*"\]' | /usr/bin/sed 's/\[UIImage imageNamed:@"\(.*\)"\]/\1/g' | sort -u) | |
PRESENTED_IMAGES=$(find "$PROJECT_NAME" -name *.imageset | grep -v Pods | /usr/bin/sed -e 's/.*\///' -e 's/\.imageset$//' | sort -u) | |
EXIT_CODE=0 | |
echo "Non-const usages of UIImage's imageNamed:" | |
while read name; do | |
show_nonconst $name | |
EXIT_CODE=1 | |
done < <(find SurfMate -name '*.m' -print0 | xargs -0 grep -n -o -e '\[UIImage imageNamed:[^@]' | /usr/bin/sed 's/\[UIImage imageNamed:[^@]//g') | |
echo "Missing imageset with name:" | |
while read name; do | |
show_code $name | |
EXIT_CODE=1 | |
done < <(comm -23 <(printf '%s' "$USED_NAMES") <(printf '%s' "$PRESENTED_IMAGES")) | |
echo | |
echo "No more refs to imageset:" | |
while read name; do | |
show_img $name | |
EXIT_CODE=1 | |
done < <(comm -13 <(printf '%s' "$USED_NAMES") <(printf '%s' "$PRESENTED_IMAGES")) | |
echo | |
exit $EXIT_CODE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment