-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflutter_tool.sh
164 lines (160 loc) · 3.66 KB
/
flutter_tool.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# // flutter_tool.sh
###
# @Author: your name
# @Date: 2021-07-16 18:05:05
# @LastEditTime: 2021-07-28 13:53:44
# @LastEditors: Please set LastEditors
# @Description: In User Settings Edit
# @FilePath: \puzzlec:\Users\1111\Music\env\flutter_tool.sh
###
#!/bin/bash
# 引导图
function welcome() {
echo ""
echo "欢迎使用 Flutter 多环境打包工具"
# echo "=================================="
echo "===================================================
‖ ‖
‖ # # # # # ##### # # # # ‖
‖ # # # # # # # # # # # ‖
‖ # # # # # ###### # ‖
‖ # # # # # # # # ‖
‖ # # # # # # # # ‖
‖ ####### # # ##### # # # ‖
‖ ‖
===================================================
"
echo ""
}
welcome
# 具体打包命令
function build() {
file=$HOME/Desktop/flutterBuild/$appname/$channel/
flutter build apk $DART_DEFINES --split-per-abi
echo ""
echo "打包完成"
cd $homePwd/build/app/outputs/flutter-apk/
if [ -d "$file" ]; then
cpExport
else
mkdir -p $file
cpExport
fi
# echo $channel
}
# 复制和打开目录
function cpExport() {
cp -R *.apk $file
# cd $file
# if [[ ! $(uname -s | grep NT) = "" ]]; then
# start .
# else
# open .
# fi
# cd -
}
# 检查所有环境
function listEnvAll() {
count=-1
for entry in .env.*; do
# if [ ${entry:5} != "dev" ]; then
envArr[$((count = count + 1))]=${entry:5}
# fi
done
}
# 指定环境的用法
function isEnv() {
VARS=($(cut -d ' ' -f1 $homePwd/.env.$MODEL))
DART_DEFINES=""
for ((i = 0; i < ${#VARS[@]}; i++)); do
DART_DEFINES+=" --dart-define=${VARS[i]}"
if [ "${VARS[i]:0:11}" = "APP_CHANNEL" ]; then
channel=${VARS[i]:12}
fi
if [ "${VARS[i]:0:8}" = "APP_NAME" ]; then
appname=${VARS[i]:9}
fi
if [ "${VARS[i]:0:7}" = "APP_ENV" ]; then
appenv=${VARS[i]:8}
fi
done
# 运行命令
if [ "$1" = "run" ]; then
flutter $1 $DART_DEFINES
fi
# 打包命令
if [ "$1" = "build" ]; then
echo ""
echo "============================= 我是分割线 ============================="
echo ""
echo "开始打包"$appname"的"$channel"渠道,环境为"$appenv
echo ""
build
fi
}
# 未指定环境
function noEnv() {
echo "查找到以下环境=======================>"
echo ""
i=-1
for v in ${envArr[@]}; do
echo $((i = i + 1))"."$v
done
echo "99.全部打包"
echo ""
read -p "请输入对应下标,执行对应环境:" number
if [[ $number =~ ^[0-9]+$ ]]; then
if [ $number -lt ${#envArr[@]} -a $number -gt -1 ]; then
MODEL=${envArr[$number]}
isEnv $1
else
if [[ "$number" == "99" ]]; then
for v in ${envArr[@]}; do
MODEL=$v
isEnv $1
done
fi
fi
else
echo "请输入数字"
fi
}
# 所有环境数组
envArr=()
listEnvAll
# 渠道
channel=""
# app名字
appname=""
# 环境
appenv=""
# 保存当前工作目录
homePwd=$(pwd)
# 判断 执行参数
if [[ "$1" == "" ]]; then
echo "请输入执行参数 run 或者 build"
exit
fi
# 检测是否有环境文件
if [ ${#envArr[@]} = 0 ]; then
echo "未检测到环境文件"
exit
fi
for i in "$@"; do
case $i in
--model=*)
MODEL="${i#*=}"
;;
*)
# unknown option
;;
esac
done
# 判断是否指定了具体环境
if [[ $MODEL != "" ]]; then
isEnv $1
else
echo "未指定具体环境,正查找所有环境........"
echo ""
noEnv $1
fi