-
Notifications
You must be signed in to change notification settings - Fork 3
/
flutterw
89 lines (83 loc) · 2.9 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
#!/usr/bin/env bash
download_dir=".flutter"
distribution_url="https://github.com/flutter/flutter.git"
#https://github.com/flutter/flutter.git 如果下载太慢可以使用 https://gitee.com/mirrors/Flutter.git
flutter_channel="stable"
flutter_version="1.12.13+hotfix.5"
# 初始化命令
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
if [[ "$(uname)" == *NT* ]] #判断是否是Windows系统,嵌套中括号是支持正则使用
then
flutter_command="$download_dir/bin/flutter.bat"
dart_command="$download_dir/bin/cache/dart-sdk/bin/dart.exe"
else
flutter_command="$download_dir/bin/flutter"
dart_command="$download_dir/bin/cache/dart-sdk/bin/dart"
fi
# 执行方法封装,支持flutterw dart 来运行dart文件
execFlutter() {
if [[ $1 == "dart" ]]
then
str=$*
substr=${str:4}
$dart_command $substr
else
$flutter_command $*
fi
}
# 下载
if [ ! -d $download_dir ]
then
echo "Create $download_dir dir"
mkdir $download_dir
fi
if [ ! -r $flutter_command ]
then
echo "Start download SDK:git clone -b $flutter_channel $distribution_url $download_dir"
git clone -b $flutter_channel $distribution_url $download_dir
if [ -r $flutter_command ]
then
# 下载dart sdk
echo "Downloading the Dart using the BITS service, Please wait a moment (maybe ten minutes or twenty minutes)..."
curFlutterVersion=`$flutter_command --version | grep '^Flutter' | cut -d ' ' -f2`
# 更新.android、.ios内部的flutter sdk路径
$flutter_command pub get
# 下载 某些 Flutter assets
$flutter_command doctor
echo "SDK download success:$curFlutterVersion"
else
echo "SDK download failed"
exit -1
fi
fi
# 切换版本
curFlutterVersion=`$flutter_command --version | grep '^Flutter' | cut -d ' ' -f2`
if [ $curFlutterVersion == $flutter_version ]
then
execFlutter $*
else
echo "Current version:$curFlutterVersion,Target version:$flutter_version"
$flutter_command channel $flutter_channel
$flutter_command upgrade
$flutter_command version -f "v$flutter_version"
# 下载dart sdk
echo "Downloading the Dart using the BITS service, Please wait a moment ..."
curFlutterVersion=`$flutter_command --version | grep '^Flutter' | cut -d ' ' -f2`
if [ $curFlutterVersion == $flutter_version ]
then
# 更新.android、.ios内部的flutter sdk路径
$flutter_command pub get
# 下载 某些 Flutter assets
$flutter_command doctor
echo "Change version success"
execFlutter $*
else
echo "Change version failed"
fi
fi
# 备注
# 获取某个命令的返回值 使用 STR=$(uname) 或者 STR=`uname`
# 变量赋值等号前后不能有空格 如 STR="123"
# shell if 是对空格敏感 如:if [ "dd" == "dd" ]
# if [[ "$(uname)" == *AA* ]] 嵌套中括号是支持正则使用