-
-
Save eran3d/ad481b801476de73f68e63cf599c3ead to your computer and use it in GitHub Desktop.
Check if UIImage exists in assets
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
#!/bin/bash | |
function show_code { | |
ERROR_LOCATION=$(grep -Ron "\[UIImage imageNamed:\s*@\"$1\"\s*\]" $PROJECT_NAME) | |
if [[ -z $ERROR_LOCATION ]]; then | |
ERROR_LOCATION=$(grep -Ron "UIImage(named\:\s*\"$1\"\s*)" $PROJECT_NAME) | |
fi | |
ERROR_LOCATION=$(echo $ERROR_LOCATION | cut -d ':' -f 1,2) | |
echo "$ERROR_LOCATION: error: Missing imageset with name $1" | |
} | |
function show_img { | |
local IMG_LOC=$(find "$PROJECT_NAME" -name "$1.imageset" | sed 's/.xcassets\//.xcassets:.\//') | |
echo "$IMG_LOC/:: error: No more refs to imageset $1" | |
} | |
USED_NAMES=() | |
#find obj-c [UIImage imageNamed:@""] | |
USED_NAMES+=($(grep -Ron '\[UIImage imageNamed:\s*@"[^"]*"\s*\]' $PROJECT_NAME | cut -d '"' -f 2 | sort -u)) | |
#find swift UIImage(named "") | |
USED_NAMES+=($(grep -Ron 'UIImage(named\:\s*"[^"]\{1,\}"\s*)' $PROJECT_NAME | cut -d '"' -f 2 | sort -u)) | |
#find images names in assets | |
PRESENTED_IMAGES=$(find "$PROJECT_NAME" -name *.imageset | grep -v Pods | /usr/bin/sed -e 's/.*\///' -e 's/\.imageset$//' | sort -u) | |
EXIT_CODE=0 | |
echo "Missing imageset with name:" | |
for name in $(comm -23 <(printf '%s' "$USED_NAMES") <(printf '%s' "$PRESENTED_IMAGES")); do | |
show_code $name | |
EXIT_CODE=1 | |
done | |
echo "No more refs to imageset:" | |
for name in $(comm -13 <(printf '%s' "$USED_NAMES") <(printf '%s' "$PRESENTED_IMAGES")); do | |
show_img $name | |
EXIT_CODE=1 | |
done | |
echo | |
exit $EXIT_CODE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment