Skip to content

Instantly share code, notes, and snippets.

@Desgard
Last active January 3, 2018 03:12
Show Gist options
  • Select an option

  • Save Desgard/a7b8f696dcc2f838777e564d68724f94 to your computer and use it in GitHub Desktop.

Select an option

Save Desgard/a7b8f696dcc2f838777e564d68724f94 to your computer and use it in GitHub Desktop.
Check the iPad xib and Storyboard fit
#!/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
@Desgard
Copy link
Author

Desgard commented Jan 3, 2018

image

可以检测出以上约束未增加

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment