-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathflutterw
executable file
·96 lines (82 loc) · 2.68 KB
/
flutterw
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
#!/usr/bin/env sh
WRAPPER_PROPERTIES_FILE="flutter_wrapper.properties"
WRAPPER_SDK_DIRECTORY="${HOME}/.flutter_wrapper"
CURRENT_VERSION=""
CURRENT_CHANNEL=""
CURRENT_URL=""
PARAM=""
# collection current installed flutter version info
collection_sdk_info(){
echo $1
version="$(cut -d'•' -f1 <<< $1)"
CURRENT_VERSION="$(cut -d' ' -f2 <<< ${version})"
channel="$(cut -d'•' -f2 <<< $1)"
CURRENT_CHANNEL="$(cut -d' ' -f2 <<< ${channel})"
git_url="$(cut -d'•' -f3 <<< $1)"
CURRENT_URL="$(cut -d' ' -f1 <<< ${git_url})"
}
# init() will create flutter_wrapper.property file
# This file will according system flutter sdk version collection
# flutter version and channel and download url info
init(){
#check flutter is installed
system_sdk_info="$(flutter --version)"
if [ ! $? -eq 0 ]; then
echo "Error: flutter is not installed."
exit 1
fi
collection_sdk_info "${system_sdk_info}"
# remove old flutter_wrapper.property file
rm -rf ${WRAPPER_PROPERTIES_FILE}
# add to file
echo "VERSION=${CURRENT_VERSION}" >> ${WRAPPER_PROPERTIES_FILE}
echo "CHANNEL=${CURRENT_CHANNEL}" >> ${WRAPPER_PROPERTIES_FILE}
echo "REPO_URL=${CURRENT_URL}" >> ${WRAPPER_PROPERTIES_FILE}
}
# list() list all downloaded flutter version in ~/.flutter
list(){
ls -1 ~/.flutter_wrapper
}
download_sdk(){
required_flutter="${WRAPPER_SDK_DIRECTORY}/${VERSION}/bin/flutter"
if [ ! -e ${required_flutter} ]
then
echo "v${VERSION}"
{
git clone -b "v${VERSION}" https://github.com/flutter/flutter.git "${WRAPPER_SDK_DIRECTORY}/${VERSION}/" --depth 1
} || {
git clone -b "${VERSION}" https://github.com/flutter/flutter.git "${WRAPPER_SDK_DIRECTORY}/${VERSION}/" --depth 1
}
fi
}
# read flutter_wrapper.properties file
check_file_config(){
if [ -f "./$WRAPPER_PROPERTIES_FILE" ]
then
while IFS='=' read -r key value
do
key=$(echo $key | tr '.' '_')
eval ${key}=\${value}
done < "$WRAPPER_PROPERTIES_FILE"
if [[ -z $VERSION || -z $CHANNEL || -z $REPO_URL ]]; then
echo "./$WRAPPER_PROPERTIES_FILE is incorrect,please check it or run 'flutterw init'."
exit 1
fi
else
echo "$WRAPPER_PROPERTIES_FILE not found. please run 'flutterw init' to init project"
fi
}
if [ "$1" == "init" ]; then
init
printf "Init successful"
elif [ "$1" == "list" ]; then
printf "Flutter in [${HOME}/.flutter] directory \n"
list
else
# check properites file exists
check_file_config
download_sdk
# run command
# set -e
"${WRAPPER_SDK_DIRECTORY}/${VERSION}/bin/flutter" "$@"
fi