├── .android └── local.properties ├── .gitignore ├── .ios └── Flutter │ └── Generated.xconfig ├── LICENSE ├── README.md ├── flutterw └── wrapper └── flutter-wrapper.properties /.android/local.properties: -------------------------------------------------------------------------------- 1 | flutter.sdk=/Users/leo/Desktop/flutterw/.flutter 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .flutter/ 3 | -------------------------------------------------------------------------------- /.ios/Flutter/Generated.xconfig: -------------------------------------------------------------------------------- 1 | FLUTTER_ROOT=/Users/leo/Desktop/flutterw/.flutter 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 leo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # flutterw 2 | flutterw 3 | -------------------------------------------------------------------------------- /flutterw: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | 3 | default_distributionUrl="https://github.com/flutter/flutter" 4 | default_download_flutter_sdk_dir=".flutter" 5 | default_flutterChannel="stable" 6 | default_androidDir="android" 7 | default_iosDir="ios" 8 | 9 | properties='' 10 | if test -e 'wrapper/flutter-wrapper.properties' 11 | then 12 | properties='wrapper/flutter-wrapper.properties' 13 | else 14 | echo '请确认 wrapper/flutter-wrapper.properties 是否存在' 15 | exit -1 16 | fi 17 | 18 | # 读取 flutter-wrapper.properties 中的配置 19 | 20 | distributionUrl="" 21 | flutterVersion="" 22 | flutterChannel="" 23 | androidDir="" 24 | iosDir="" 25 | 26 | IFS=$'\n' 27 | 28 | for line in `cat $properties` 29 | do 30 | # 忽略注释 31 | comment=`echo "$line" | grep '^#'` 32 | if [ -n "$comment" ] 33 | then 34 | echo "忽略注释" 35 | continue 36 | fi 37 | key=`echo $line | cut -d '=' -f1` 38 | value=`echo $line | cut -d '=' -f2` 39 | case $key in 40 | "distributionUrl") 41 | distributionUrl="$value" 42 | ;; 43 | "flutterVersion") 44 | flutterVersion="$value" 45 | ;; 46 | "flutterChannel") 47 | flutterChannel="$value" 48 | ;; 49 | "androidDir") 50 | androidDir="$value" 51 | ;; 52 | "iosDir") 53 | iosDir="$value" 54 | ;; 55 | *) 56 | echo "$key 选项不被支持,请确认" 57 | ;; 58 | esac 59 | done 60 | 61 | 62 | if [ -z $distributionUrl ] 63 | then 64 | echo "distributionUrl 为空,将使用默认值 $default_distributionUrl" 65 | distributionUrl=default_distributionUrl 66 | fi 67 | 68 | if [ -z $flutterVersion ] 69 | then 70 | echo "必须指定 flutterVersion" 71 | exit -1 72 | fi 73 | 74 | if [ -z $flutterChannel ] 75 | then 76 | echo "flutterChannel 为空,将使用默认值 $default_flutterChannel" 77 | flutterChannel=default_flutterChannel 78 | fi 79 | 80 | if [ -z $androidDir ] 81 | then 82 | echo "androidDir 为空,将使用默认值 $default_androidDir" 83 | androidDir=default_androidDir 84 | fi 85 | 86 | if [ -z $iosDir ] 87 | then 88 | echo "iosDir 为空,将使用默认值 $default_iosDir" 89 | iosDir=default_iosDir 90 | fi 91 | 92 | # 判断是否需要下载 SDK 93 | if [ ! -d $default_download_flutter_sdk_dir ] 94 | then 95 | echo "创建 $default_download_flutter_sdk_dir 目录" 96 | mkdir $default_download_flutter_sdk_dir 97 | fi 98 | 99 | flutter_command="$default_download_flutter_sdk_dir/bin/flutter" 100 | 101 | export PUB_HOSTED_URL=https://pub.flutter-io.cn 102 | export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn 103 | 104 | if [ ! -r $flutter_command ] 105 | then 106 | # 下载 SDK 107 | echo "开始下载 SDK..." 108 | git clone $distributionUrl $default_download_flutter_sdk_dir 109 | if [ -r $flutter_command ] 110 | then 111 | echo "SDK 下载成功" 112 | $flutter_command doctor -v 113 | else 114 | echo "SDK 下载失败" 115 | exit -1 116 | fi 117 | fi 118 | 119 | cur_flutter_version=`$flutter_command --version | grep '^Flutter' | cut -d ' ' -f2` 120 | 121 | setupSDK(){ 122 | # 修改 flutter.sdk 123 | local_properties=`find $androidDir -name "local.properties"` 124 | if [ -z $local_properties ] 125 | then 126 | echo "请先创建 local.properties" 127 | exit -1 128 | else 129 | # 删除旧的 flutter.sdk 130 | for line in $local_properties 131 | do 132 | key=`echo $line | cut -d '=' -f1` 133 | if [ key == "flutter.sdk" ] 134 | then 135 | # 删除它 136 | sed "/^$line/d" $local_properties 137 | fi 138 | done 139 | # 插入新的 flutter.sdk 140 | echo "flutter.sdk=`pwd`/$default_download_flutter_sdk_dir" > $local_properties 141 | fi 142 | # 修改 Generated.xcconfig 143 | generated_xconfig=`find $iosDir -name "Generated.xconfig"` 144 | if [ -z $generated_xconfig ] 145 | then 146 | echo "请先创建 Generated.xconfig" 147 | exit -1 148 | else 149 | # 删除旧的 FLUTTER_ROOT 150 | for line in $generated_xconfig 151 | do 152 | key=`echo $line | cut -d '=' -f1` 153 | if [ key == "FLUTTER_ROOT" ] 154 | then 155 | # 删除它 156 | sed "/^$line/d" $generated_xconfig 157 | fi 158 | done 159 | # 插入新的 FLUTTER_ROOT 160 | echo "FLUTTER_ROOT=`pwd`/$default_download_flutter_sdk_dir" > $generated_xconfig 161 | fi 162 | } 163 | 164 | if [ $cur_flutter_version == $flutterVersion ] 165 | then 166 | # 执行 flutter 命令 167 | $flutter_command $* 168 | setupSDK 169 | else 170 | echo "当前版本为 ${cur_flutter_version},切换版本为:${flutterVersion}" 171 | $flutter_command channel $flutterChannel 172 | $flutter_command upgrade 173 | $flutter_command version -f "v$flutterVersion" 174 | $flutter_command doctor -v 175 | cur_flutter_version=`$flutter_command --version | grep '^Flutter' | cut -d ' ' -f2` 176 | if [ $cur_flutter_version == $flutterVersion ] 177 | then 178 | echo "切换版本成功" 179 | # 执行 flutter 命令 180 | $flutter_command $* 181 | setupSDK 182 | else 183 | echo "切换版本失败" 184 | fi 185 | fi 186 | 187 | -------------------------------------------------------------------------------- /wrapper/flutter-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://github.com/flutter/flutter.git 2 | flutterVersion=1.6.6 3 | flutterChannel=dev 4 | androidDir=.android 5 | iosDir=.ios --------------------------------------------------------------------------------