标签:span 项目 car 打开 java name efi 命令 -o
#!/bin/sh programFilePath=$(cd "$(dirname "$0")"; pwd) unusedCount=0 maybeUnusedCount=0 if [[ -z $programFilePath ]]; then read -p "请输入工程的路径" programFilePath fi check_files=`find $programFilePath -name ‘*.xib‘ -o -name ‘*.storyboard‘ -o -name ‘*.[mh]‘ -o -name ‘*.pch‘ -o -name ‘*.java‘ -o -name ‘*.xml‘ -o -name ‘*.js‘ -o -name ‘*.html‘` for file in `echo $check_files | sed ‘s/\n/ /g‘` do #iOS图片引用规则 :获取@符号的语句 grep -i "@\"" -A 0 "$file" | grep -v -e "--" >> maybeImageSentence.txt done imageTextPath="$programFilePath/maybeImageSentence.txt" maybeUnusedImageFilePath="$programFilePath/maybeUnusedImage.txt" if [ -f "$maybeUnusedImageFilePath" ]; then rm -f "$maybeUnusedImageFilePath" fi unusedImageFilePath="$programFilePath/unusedImage.txt" if [ -f "$unusedImageFilePath" ]; then rm -f "$unusedImageFilePath" fi for png in `find $programFilePath -name ‘*.png‘` do # 图片名称 match_name=`basename $png` suffix1="@2x.png" suffix2=".9.png" suffix3=".png" suffix4="@3x.png" if [[ ${match_name/${suffix1}//} != $match_name ]]; then match_name=${match_name%$suffix1} elif [[ ${match_name/${suffix4}//} != $match_name ]]; then match_name=${match_name%$suffix4} elif [[ ${match_name/${suffix2}//} != $match_name ]]; then match_name=${match_name%$suffix2} else match_name=${match_name%$suffix3} fi dir_name=`dirname $png` if [[ $dir_name =~ .bundle$ ]] || [[ $dir_name =~ .appiconset$ ]] || [[ $dir_name =~ .launchimage$ ]]; then continue fi # 在imageset里面找 result=$(echo $dir_name | grep "imageset") if [[ "$result" == "" ]]; then continue fi referenced=false if grep -q "$match_name" "$imageTextPath"; then referenced=true fi contaT=$(echo $match_name | grep "[0-9]") if [[ "$contaT" != "" ]]; then maybeUnusedCount=`expr $maybeUnusedCount + 1` echo "$png" >> maybeUnusedImage.txt continue fi if ! $referenced ; then unusedCount=`expr $unusedCount + 1` echo "$png" >> unusedImage.txt # 打开下面的语句直接删除图片目录 例如icon_arrow_bluesmall.imageset # rm -rf $dir_name fi done rm maybeImageSentence.txt echo "Total $unusedCount unusedImage files ->imagePath store unusedImage.txt" echo "Total $maybeUnusedCount maybeUnusedImage files ->imagePath store maybeUnusedImage.txt"
使用方法:首先把上面的代码复制到一个文件中命名为 unused-image.sh,把这个文件放在目标工程下面执行 sh unused-image.sh 命令即可。会生成两个文件 unusedImage.txt和 maybeUnusedImage.txt。
方案2的缺点就是无法判断图片名称带有数字的无法确定是否是无用资源如图片名称为bg_card_lower_1_2@2x.png,此类命名的图片输出到maybeUnusedImage.txt这个文件中,需要手动的排查删除。
原创文章,欢迎转载,转载请标注,谢谢大家!!!!!!!
原创文章,欢迎转载,转载请标注,谢谢大家!!!!!!!
原创文章,欢迎转载,转载请标注,谢谢大家!!!!!!!
================================================================
若有疑问请加本人QQ:610774281 微信:stephenli225。 一起探讨一起进步。。。。
标签:span 项目 car 打开 java name efi 命令 -o
原文地址:http://www.cnblogs.com/lidaojian/p/7533441.html