Last active
January 3, 2018 03:12
-
-
Save Desgard/a7b8f696dcc2f838777e564d68724f94 to your computer and use it in GitHub Desktop.
Check the iPad xib and Storyboard fit
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
| #!/usr/bin/env bash | |
| # 用于检测项目目录下的 xib 和 storyboard 对于 iPad 的兼容性问题 | |
| # 命名规范是 iPad 适配的 xib 或 storyboard 文件如果 iPhone 以 home.storyboard 为 file name | |
| # 则 iPad 为 homePad.storyboard 为 file name | |
| # 运行脚本后可以检测对应 homePad.storyboard 的合法性 | |
| CHECK_TARGET_FOLDER="./YOUR PROJECT FOLDER" | |
| xmllintPath=`which xmllint` | |
| if [[ $xmllintPath == "" ]]; then | |
| echo "ERR: xmllint not install" | |
| exit | |
| fi | |
| for file in `find $CHECK_TARGET_FOLDER -name "*Pad.xib"`; do | |
| if [[ ${file:0-7:3} == "Pad" ]]; then | |
| iphoneFile=${file%Pad*}".xib" | |
| if [[ -e $iphoneFile ]]; then | |
| padConnects=`grep -e 'outlet property="[a-zA-Z]*"' -o --no-filename --text $file | grep -e '"[a-zA-Z]*"' -o` | |
| iphoneConnects=`grep -e 'outlet property="[a-zA-Z]*"' -o --no-filename --text $iphoneFile | grep -e '"[a-zA-Z]*"' -o` | |
| for connect in $iphoneConnects; do | |
| match=`echo $padConnects | grep -e $connect -o` | |
| if [[ $match == "" ]]; then | |
| echo $file | |
| echo $iphoneFile | |
| echo " "$connect | |
| echo "" | |
| fi | |
| done | |
| fi | |
| fi | |
| done | |
| # storyboard check | |
| for file in `find $CHECK_TARGET_FOLDER -name "*Pad.storyboard"`; do | |
| echo "Process file: $file" | |
| iphoneFile=${file%Pad*}".storyboard" | |
| if [[ ! -e $iphoneFile ]]; then | |
| echo "Warning: not exist iphone file" | |
| continue | |
| fi | |
| # 获取viewController | |
| viewControlls=`echo "cat //*/@storyboardIdentifier" | \ | |
| xmllint --shell "$file" | \ | |
| awk -F\" 'NR % 2 == 0 { print $2 }'` | |
| for vc in $viewControlls; do | |
| padConnects=`echo "cat //*/viewController[@storyboardIdentifier=\"$vc\"]/*/outlet" | \ | |
| xmllint --shell "$file" | \ | |
| awk -F\" 'NR % 2 == 0 { print $2 }'` | |
| iphoneConnects=`echo "cat //*/viewController[@storyboardIdentifier=\"$vc\"]/*/outlet" | \ | |
| xmllint --shell "$iphoneFile" | \ | |
| awk -F\" 'NR % 2 == 0 { print $2 }'` | |
| for connect in $iphoneConnects; do | |
| match=`echo $padConnects | grep -e $connect -o` | |
| if [[ $match == "" ]]; then | |
| echo " "$vc | |
| echo " "$connect | |
| echo "" | |
| fi | |
| done | |
| done | |
| done |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
可以检测出以上约束未增加