Created
June 15, 2023 03:21
-
-
Save DargonLee/084ce3776188ad05e6ada89fd9f26e62 to your computer and use it in GitHub Desktop.
This file contains 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
# 定义ANSI转义码颜色常量 | |
RED='\033[0;31m' | |
GREEN='\033[0;32m' | |
YELLOW='\033[0;33m' | |
CYAN='\033[0;36m' | |
NC='\033[0m' # 恢复默认颜色 | |
# 显示带颜色的文本菜单选项 | |
echo "${GREEN}请选择以下选项:${NC}" | |
echo ">1. ${YELLOW}Debug${NC}" | |
echo ">2. ${YELLOW}AdHoc${NC}" | |
echo ">3. ${YELLOW}AppStore${NC}" | |
echo ">4. 退出" | |
# 读取用户输入 | |
read -p "请输入选项编号: " choice | |
echo $choice | |
buildDebug="Debug" | |
# 根据用户选择执行相应操作 | |
case $choice in | |
1) | |
echo "${CYAN}✓ 你选择了打 Debug 包${NC}" | |
buildDebug="debug" | |
;; | |
2) | |
echo "${CYAN}✓ 你选择了打 AdHoc 包${NC}" | |
buildDebug="adhoc" | |
;; | |
3) | |
echo "${CYAN}✓ 你选择了打 AppStore 包${NC}" | |
buildDebug="release" | |
;; | |
4) | |
echo "退出" | |
exit 0 | |
;; | |
*) | |
echo "${RED}❌无效选项${NC}" | |
;; | |
esac | |
echo $buildDebug | |
exit 0 | |
startTime=`date "+%Y-%m-%d %H:%M:%S"` | |
echo "Start Time: $startTime" | |
startTime=`date +%s` | |
#参数优化 | |
if [ "$buildDebug" == "release" ]; then | |
exportOptions="AppStoreExportOptions.plist" | |
elif [ "$buildDebug" == "adhoc" ]; then | |
exportOptions="AdHocExportOptions.plist" | |
else | |
exportOptions="DebugExportOptions.plist" | |
fi | |
#常量 | |
#export LANG=en_US.UTF-8 | |
rootPath=$(cd "$(dirname "$0")"; pwd) | |
targetName="ZofomoNote" | |
infoPlistPath="${rootPath}/ZofomoNote/SupportingFiles/info.plist" | |
zhHansPath="${rootPath}/ZofomoNote/SupportingFiles/zh-Hans.lproj/InfoPlist.strings" | |
enHansPath="${rootPath}/ZofomoNote/SupportingFiles/en.lproj/InfoPlist.strings" | |
bundleidentifier="com.zofomo.project.note" | |
bundleidentifierPro="com.zofomo.project.note.pro" | |
zhAppName="备忘录" | |
zhAppNamePro="备忘录Pro" | |
enAppName="ZNote" | |
enAppNamePro="ZNotePro" | |
#读取info.plist里面的配置文件的版本号 | |
Version=`/usr/libexec/PlistBuddy -c "print:CFBundleShortVersionString" ${infoPlistPath}` | |
echo "buildDebug = $buildDebug" | |
echo "exportOptions = $exportOptions" | |
exit 0 | |
#解锁钥匙串 | |
# keychainPassWord=123456 | |
# security unlock-keychain -p $keychainPassWord /Users/$(whoami)/Library/Keychains/login.keychain | |
echo "keychainPassWord = $keychainPassWord" | |
rm -drf ${rootPath}/build | |
rm -drf ${rootPath}/output | |
rm -drf ${rootPath}/DerivedData | |
mkdir ${rootPath}/build | |
mkdir ${rootPath}/build/data | |
mkdir ${rootPath}/output | |
pod install | |
if [ "$buildDebug" == "debug" ]; then | |
xcodebuild archive \ | |
-scheme "${targetName}" \ | |
-workspace ${rootPath}/"${targetName}".xcworkspace \ | |
-configuration Debug \ | |
-archivePath ${rootPath}/build/"${targetName}".xcarchive \ | |
-derivedDataPath ${rootPath}/DerivedData | xcpretty | |
xcodebuild -exportArchive \ | |
-archivePath ${rootPath}/build/"${targetName}".xcarchive \ | |
-exportPath ${rootPath}/build/export \ | |
-exportOptionsPlist ${rootPath}/ExportOptions/$exportOptions | xcpretty | |
else | |
xcodebuild archive \ | |
-scheme "${targetName}" \ | |
-workspace ${rootPath}/"${targetName}".xcworkspace \ | |
-configuration Distribution -archivePath ${rootPath}/build/"${targetName}".xcarchive \ | |
-derivedDataPath ${rootPath}/DerivedData | xcpretty | |
xcodebuild -exportArchive \ | |
-archivePath ${rootPath}/build/"${targetName}".xcarchive \ | |
-exportPath ${rootPath}/build/export \ | |
-exportOptionsPlist ${rootPath}/ExportOptions/$exportOptions | xcpretty | |
fi | |
BuildTime=`date "+%Y%m%d%H%M%S"` | |
#拷贝资源文件 | |
cp -r -f ${rootPath}/build/export/"${targetName}".ipa ${rootPath}/output/note_ios_${buildDebug}_${BuildTime}.ipa | |
rm -drf ${rootPath}/build | |
rm -drf ${rootPath}/DerivedData | |
mkdir ${rootPath}/build | |
mkdir ${rootPath}/build/data | |
# 字符串替换 | |
filePath="${rootPath}/ZofomoNote/Classes/Constant/ZNPrefixHeader.pch" | |
searchStr="#define kAppVersion 1" | |
replaceStr="#define kAppVersion 0" | |
#替换普通版资源 | |
cp -r -f ${rootPath}/Packages/Icons/Icon.png ${rootPath}/ZofomoNote/Resources/Assets.xcassets/AppIcon.appiconset/Icon.png | |
cp -r -f ${rootPath}/Packages/Launch/launch.png ${rootPath}/ZofomoNote/Resources/Images/launch.png | |
sed -i '' "s/${searchStr}/${replaceStr}/g" "$filePath" | |
# /usr/libexec/PlistBuddy -c "Set :CFBundleIdentifier $bundleidentifier" $infoPlistPath | |
# /usr/libexec/PlistBuddy -c "Set :CFBundleDisplayName $zhAppName" $zhHansPath | |
# /usr/libexec/PlistBuddy -c "Set :CFBundleDisplayName $enAppName" $enHansPath | |
#打包 | |
if [ "$buildDebug" == "debug" ]; then | |
xcodebuild clean archive \ | |
-scheme "${targetName}" \ | |
-workspace ${rootPath}/"${targetName}".xcworkspace \ | |
-configuration Debug \ | |
-archivePath ${rootPath}/build/"${targetName}".xcarchive \ | |
-derivedDataPath ${rootPath}/DerivedData | xcpretty | |
xcodebuild -exportArchive \ | |
-archivePath ${rootPath}/build/"${targetName}".xcarchive \ | |
-exportPath ${rootPath}/build/export \ | |
-exportOptionsPlist ${rootPath}/ExportOptions/$exportOptions | xcpretty | |
else | |
xcodebuild clean archive \ | |
-scheme "${targetName}" \ | |
-workspace ${rootPath}/"${targetName}".xcworkspace \ | |
-configuration Distribution -archivePath ${rootPath}/build/"${targetName}".xcarchive \ | |
-derivedDataPath ${rootPath}/DerivedData | xcpretty | |
xcodebuild -exportArchive \ | |
-archivePath ${rootPath}/build/"${targetName}".xcarchive \ | |
-exportPath ${rootPath}/build/export \ | |
-exportOptionsPlist ${rootPath}/ExportOptions/$exportOptions | xcpretty | |
fi | |
BuildTime=`date "+%Y%m%d%H%M%S"` | |
# 还原 | |
cp -r -f ${rootPath}/Packages/Icons/Icon-pro.png ${rootPath}/ZofomoNote/Resources/Assets.xcassets/AppIcon.appiconset/Icon.png | |
cp -r -f ${rootPath}/Packages/Launch/launch-pro.png ${rootPath}/ZofomoNote/Resources/Images/launch.png | |
sed -i '' "s/${replaceStr}/${searchStr}/g" "$filePath" | |
# /usr/libexec/PlistBuddy -c "Set :CFBundleIdentifier $bundleidentifierPro" $infoPlistPath | |
# /usr/libexec/PlistBuddy -c "Set :CFBundleDisplayName $zhAppNamePro" $zhHansPath | |
# /usr/libexec/PlistBuddy -c "Set :CFBundleDisplayName $enAppNamePro" $enHansPath | |
#拷贝资源文件 | |
cp -r -f ${rootPath}/build/export/"${targetName}".ipa ${rootPath}/output/note_ios_${buildDebug}_${BuildTime}.ipa | |
#删除临时文件夹 | |
rm -drf ${rootPath}/build | |
rm -drf ${rootPath}/DerivedData | |
#记录执行时间 | |
endTime=`date "+%Y-%m-%d %H:%M:%S"` | |
echo "End Time: $endTime" | |
endTime=`date +%s` | |
secs=`expr $endTime - $startTime` | |
h=`expr $secs / 3600` | |
m=`expr $secs % 3600 / 60` | |
s=`expr $secs % 60` | |
echo "✅ 总时间: ${h}h ${m}m ${s}s" | |
echo "\033[32m 请在output文件夹中查看打包文件 \033[0m\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment