寫腳本打包的好處就不多說了,我前面也有寫相關(guān)的博客介紹,為了以后換了項(xiàng)目方便,我把腳本貼出來,做個(gè)記錄,以后稍作修改,就可以復(fù)用。
項(xiàng)目目錄:

目錄結(jié)構(gòu).png

同時(shí)打包腳本.png
同時(shí)打iOS和Android包并上傳
測試包
./pack.sh debug
預(yù)生產(chǎn)
./pack.sh pre
正式包
./pack.sh release
當(dāng)前目錄./pack.sh的代碼
cd android
./pack.sh $1
cd ../ios
./pack.sh $1
只打iOS或者Android包并上傳
進(jìn)入ios或者android目錄
測試包
./pack.sh debug
預(yù)生產(chǎn)
./pack.sh pre
正式包
./pack.sh release
ios 目錄下./pack.sh的代碼
configuration=''
scheme=Baima
appDelegatePath="./${scheme}/AppDelegate.m"
archivePath="./${scheme}.xcarchive"
if test $1 == 'debug'
then
configuration='Debug'
elif test $1 == 'pre'
then
configuration='Pre'
elif test $1 == 'release'
then
configuration='Release'
else
echo "命令無效"
exit 2
fi
echo "hello, ${configuration} 開始打包"
echo $archivePath
cd ..
react-native bundle --entry-file index.js --bundle-output ./ios/bundle/index.ios.jsbundle --platform ios --assets-dest ./ios/bundle --dev false
cd ./ios
sed -i "" 's|jsCodeLocation = \[\[RCTBundleURLProvider sharedSettings\] jsBundleURLForBundleRoot:@"index" fallbackResource:nil\];|jsCodeLocation = [NSURL URLWithString:[[NSBundle mainBundle] pathForResource:@"index.ios.jsbundle" ofType:nil]];|g' $appDelegatePath
xcodebuild archive -scheme ${scheme} -configuration $configuration -archivePath $archivePath
if test $1 == 'release'
then
sed -i "" 's/development/app-store/' ./debug.plist
else
echo ''
fi
xcodebuild -exportArchive -archivePath $archivePath -exportPath ./Pack -exportOptionsPlist debug.plist
if test $1 == 'release'
then
echo "hello, ${configuration} Ok"
/Applications/Xcode9.app/Contents/Applications/Application\ Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool --validate-app -f ./Pack/Baima.ipa -t ios -u 開發(fā)者賬號 -p 密碼 -t ios
/Applications/Xcode9.app/Contents/Applications/Application\ Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool --upload-app -f ./Pack/Baima.ipa -t ios -u 開發(fā)者賬號 -p 密碼
else
curl -F "file=@./Pack/Baima.ipa" -F "uKey=蒲公英獲取" -F "_api_key=蒲公英獲取" https://qiniu-storage.pgyer.com/apiv1/app/upload
fi
git checkout -- $appDelegatePath
rm -rf $archivePath ./Pack
sed -i "" 's/app-store/development/' ./debug.plist
echo "hello, ${configuration} Ok"
android 目錄下./pack.sh的代碼
if test $1 == 'debug'
then
command='assembleDebug'
path='debug/app-debug.apk'
elif test $1 == 'pre'
then
command='assemblePre'
path='pre/app-pre.apk'
elif test $1 == 'release'
then
command='assembleRelease'
path='release/app-release.apk'
else
echo "命令無效"
exit 2
fi
cd ..
mkdir android/app/src/main/assets/
react-native bundle --entry-file index.js --platform android --dev false --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/
cd ./android
gradle $command
curl -F "file=@./app/build/outputs/apk/$path" -F "uKey=蒲公英獲取" -F "_api_key=蒲公英獲取" https://qiniu-storage.pgyer.com/apiv1/app/upload
知識點(diǎn):
xcodebuild打包
gradle打包
shell腳本
這里主要用到的shell命令就是參數(shù)的傳遞,內(nèi)容的替換,點(diǎn)擊這里學(xué)習(xí)下