Skip to content

Commit 69f5ddf

Browse files
committed
feat: Support productFlavor
1 parent 845f5a1 commit 69f5ddf

7 files changed

+39
-26
lines changed

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ npx upload-pgy --no-android
124124
npx upload-pgy --no-ios
125125

126126
# 安卓默认打包release版本,可以改成debug版本
127-
npx upload-pgy --debug
127+
npx upload-pgy --variant=debug
128128
```
129129

130130
### fir.im
@@ -139,7 +139,7 @@ npx upload-fir --no-android
139139
npx upload-fir --no-ios
140140

141141
# 安卓默认打包release版本,可以改成debug版本
142-
npx upload-fir --debug
142+
npx upload-fir --variant=debug
143143
```
144144

145145
### App Store
@@ -164,6 +164,9 @@ npx upload-tf
164164
### 同时打包android和ios
165165
```bash
166166
npx upload-build --ios-export-plist path/to/xxx.plist
167+
168+
# 安卓默认打包release版本,可以改成debug版本
169+
npx upload-build --ios-export-plist path/to/xxx.plist --variant=debug
167170
```
168171

169172

src/build-android.sh

+5-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ libs=$dir/libs
1212

1313
echo -e "\n\033[32mBuilding android app...\033[0m\n"
1414

15-
pack_type=$(node $libs/pack-type.js "$@")
15+
eval $(node $libs/pack-type.js "$@")
16+
# pack_variant=
17+
# pack_output_path=
1618

17-
bash $libs/build-android.sh $pack_type
19+
bash $libs/build-android.sh $pack_variant
1820

19-
echo -e "\nView apk file at: \033[32m./android/app/build/outputs/apk/$pack_type\033[0m\n"
21+
echo -e "\nView apk file at: \033[32m./android/app/build/outputs/apk/$pack_output_path\033[0m\n"

src/build.sh

+6-3
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,16 @@ ios_app_save_dir=./ios/build/app-$(date +%Y-%m-%d-%H-%M-%S)
2323

2424
echo -e "\n\033[32mBuilding android app...\033[0m\n"
2525

26-
pack_type=$(node $libs/pack-type.js "$@")
27-
bash $libs/build-android.sh $pack_type
26+
eval $(node $libs/pack-type.js "$@")
27+
# pack_variant=
28+
# pack_output_path=
29+
30+
bash $libs/build-android.sh $pack_variant
2831

2932
echo -e "\n\033[32mBuilding ios app...\033[0m\n"
3033

3134
bash $libs/archive.sh
3235
bash $libs/export-ipa.sh $ios_export_plist $ios_app_save_dir
3336

34-
echo -e "\nView apk file at: \033[32m./android/app/build/outputs/apk/release\033[0m"
37+
echo -e "\nView apk file at: \033[32m./android/app/build/outputs/apk/$pack_output_path\033[0m"
3538
echo -e "\nView ipa file at: \033[32m$ios_app_save_dir\033[0m\n"

src/libs/build-android.sh

+2-7
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,14 @@
22

33
set -e
44

5-
pack_type=$1
5+
pack_variant=$1
66

77
# Build for android
88
# The apk file will be at
99
# android/app/build/outputs/apk/app-release.apk
1010
cd android
1111
rm -rf build/ app/build/
1212

13-
if [ $pack_type = "debug" ]
14-
then
15-
./gradlew assembleDebug
16-
else
17-
./gradlew assembleRelease
18-
fi
13+
eval "./gradlew assemble$pack_variant"
1914

2015
cd -

src/libs/pack-type.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@ const minimist = require('minimist');
22

33
const args = minimist(process.argv.slice(2));
44

5-
let releaseType = 'release';
6-
7-
if (args.debug === true) {
8-
releaseType = 'debug';
5+
if (!args.variant || typeof args.variant !== 'string') {
6+
args.variant = 'release';
97
}
108

11-
console.log(releaseType);
9+
// path is case-insensitive on macos
10+
const packVariant = args.variant.toLowerCase();
11+
12+
console.log(
13+
`
14+
pack_variant=${packVariant}
15+
pack_output_path=${packVariant.replace(/^(.*)(release|debug)$/, '$1/$2')}
16+
`
17+
);

src/upload-fir.sh

+5-3
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ else
2525
echo -e "\033[32m[$log_prefix] Building android app...\033[0m"
2626
sleep 1
2727

28-
pack_type=$(node $libs/pack-type.js "$@")
28+
eval $(node $libs/pack-type.js "$@")
29+
# pack_variant=
30+
# pack_output_path=
2931

30-
sh $libs/build-android.sh $pack_type
32+
sh $libs/build-android.sh $pack_variant
3133

32-
android_app=$(ls -l ./android/app/build/outputs/apk/$pack_type/*.apk | tail -n 1 | awk '{print $NF}')
34+
android_app=$(ls -l ./android/app/build/outputs/apk/$pack_output_path/*.apk | tail -n 1 | awk '{print $NF}')
3335
apk_info=$(node $libs/apk-info.js $android_app)
3436
eval "$apk_info"
3537
fi

src/upload-pgy.sh

+5-3
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ else
3333
echo -e "\033[32m[$log_prefix] Building android app...\033[0m"
3434
sleep 1
3535

36-
pack_type=$(node $libs/pack-type.js "$@")
36+
eval $(node $libs/pack-type.js "$@")
37+
# pack_variant=
38+
# pack_output_path=
3739

38-
sh $libs/build-android.sh $pack_type
39-
android_app=$(ls -l ./android/app/build/outputs/apk/$pack_type/*.apk | tail -n 1 | awk '{print $NF}')
40+
sh $libs/build-android.sh $pack_variant
41+
android_app=$(ls -l ./android/app/build/outputs/apk/$pack_output_path/*.apk | tail -n 1 | awk '{print $NF}')
4042
fi
4143

4244
if [ $ios -eq 0 ]

0 commit comments

Comments
 (0)