├── .gitignore ├── README.md └── flutterw /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .dart_tool/ 3 | 4 | .packages 5 | .pub/ 6 | 7 | .idea/ 8 | *.iml 9 | .vagrant/ 10 | .sconsign.dblite 11 | .svn/ 12 | 13 | *.swp 14 | profile 15 | 16 | DerivedData/ 17 | 18 | .generated/ 19 | 20 | *.pbxuser 21 | *.mode1v3 22 | *.mode2v3 23 | *.perspectivev3 24 | 25 | !default.pbxuser 26 | !default.mode1v3 27 | !default.mode2v3 28 | !default.perspectivev3 29 | 30 | xcuserdata 31 | 32 | *.moved-aside 33 | 34 | *.pyc 35 | *sync/ 36 | Icon? 37 | .tags* 38 | 39 | #build/ 40 | .android/ 41 | .ios/ 42 | .flutter-plugins 43 | .flutter -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | flutterw 2 | ======== 3 | flutterw is a shell script which downloads and executes the Flutter SDK with the exact version defined in itself. It can keep the flutter sdk version consistent for your co-workers and on the CI servers. 4 | 5 | Feature 6 | -------- 7 | - keep the flutter sdk version consistent for your co-workers and on the CI servers. 8 | - added extra commands like "./flutterw dart" can run a dart command, for example: 9 | ```java 10 | ./flutterw dart --version 11 | ``` 12 | - support windows os, need run with git bash 13 | 14 | Config 15 | -------- 16 | - Config flutter version: 17 | ```java 18 | flutter_channel="stable" 19 | flutter_version="1.9.1+hotfix.6" 20 | ``` 21 | 22 | Run 23 | -------- 24 | ```java 25 | ./flutterw --version 26 | ``` 27 | 28 | Thanks 29 | -------- 30 | https://github.com/LinXiaoTao/flutterw 31 | 32 | # Contact me: 33 | 34 | - Blog:http://blog.csdn.net/masonblog 35 | - Email:MasonLiuChn@gmail.com 36 | 37 | 中文: 38 | --------- 39 | 40 | flutterw 41 | ======== 42 | flutterw 用来下载Flutter SDK,类似于gradlew。通过在脚本内配置特定版本号,使得同一工程的所有开发者或CI服务器(例如Jenkins)使用Flutter的版本一致。 43 | 44 | 功能 45 | -------- 46 | - 保证所有开发者或CI服务器(例如Jenkins)使用Flutter的版本一致 47 | - 添加了一些额外的常用命令,如 ./flutterw dart 可以直接运行dart命令: 48 | ```java 49 | ./flutterw dart --version 50 | ``` 51 | - 支持windows系统,需要在 git bash 环境下运行 52 | 53 | 配置 54 | -------- 55 | - 配置flutter版本号: 56 | ```java 57 | flutter_channel="stable" 58 | flutter_version="1.9.1+hotfix.6" 59 | ``` 60 | 61 | 执行 62 | -------- 63 | ```java 64 | ./flutterw --version 65 | ``` 66 | 67 | 感谢 68 | -------- 69 | https://github.com/LinXiaoTao/flutterw 70 | 71 | # Contact me: 72 | 73 | - Blog:http://blog.csdn.net/masonblog 74 | - Email:MasonLiuChn@gmail.com -------------------------------------------------------------------------------- /flutterw: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | flutter_version="1.15.17" 4 | #版本查询地址:https://flutter.cn/docs/development/tools/sdk/releases 5 | distribution_url="https://github.com/flutter/flutter.git" 6 | #git地址:https://github.com/flutter/flutter.git 如果下载太慢可以使用 https://gitee.com/mirrors/Flutter.git 7 | flutter_channel="master" 8 | #master分支上version tag是最全的 9 | 10 | bash_path=$(cd `dirname $0`; pwd) # work_path=$(pwd) 11 | download_dir="$bash_path/.flutter" 12 | 13 | # 初始化命令 14 | export PUB_HOSTED_URL=https://pub.flutter-io.cn 15 | export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn 16 | if [[ "$(uname)" == *NT* ]] #判断是否是Windows系统,嵌套中括号是支持正则使用 17 | then 18 | flutter_command="$download_dir/bin/flutter.bat" 19 | dart_command="$download_dir/bin/cache/dart-sdk/bin/dart.exe" 20 | else 21 | flutter_command="$download_dir/bin/flutter" 22 | dart_command="$download_dir/bin/cache/dart-sdk/bin/dart" 23 | fi 24 | 25 | # 执行方法封装,支持flutterw dart 来运行dart文件 26 | execFlutter() { 27 | if [[ $1 == "dart" ]] 28 | then 29 | str=$* 30 | substr=${str:4} 31 | $dart_command $substr 32 | else 33 | $flutter_command $* 34 | fi 35 | } 36 | 37 | # 更新dart sdk、处理 pub 38 | handleSDK() { 39 | # 下载 或 更新 dart sdk 40 | $flutter_command doctor 41 | # 获取版本号 42 | curFlutterVersion=`$flutter_command --version | grep '^Flutter' | cut -d ' ' -f2` 43 | # 更新.android、.ios内部的flutter sdk路径 44 | $flutter_command pub get 45 | echo "===SDK handle success:$curFlutterVersion" 46 | } 47 | 48 | # 下载 https://ec2-13-250-177-223.ap-southeast-1.compute.amazonaws.com 49 | if [ ! -d $download_dir ] 50 | then 51 | echo "===Create $download_dir dir" 52 | mkdir $download_dir 53 | fi 54 | 55 | if [ ! -r $flutter_command ] 56 | then 57 | echo "===Start download SDK:git clone -b $flutter_channel $distribution_url $download_dir" 58 | git clone -b $flutter_channel $distribution_url $download_dir 59 | if [ -r $flutter_command ] 60 | then 61 | handleSDK 62 | else 63 | echo "===SDK download failed" 64 | exit -1 65 | fi 66 | fi 67 | 68 | # 切换版本 69 | curFlutterVersion=`$flutter_command --version | grep '^Flutter' | cut -d ' ' -f2` 70 | if [ $curFlutterVersion == $flutter_version ] 71 | then 72 | execFlutter $* 73 | else 74 | echo "===Current version:$curFlutterVersion,Target version:$flutter_version" 75 | ################################################################ 切换channel 76 | (cd $download_dir && git reset --hard HEAD) 77 | $flutter_command channel $flutter_channel 78 | #echo "===Upgrading" 79 | #$flutter_command upgrade -f 80 | ################################################################ 切换版本 81 | echo "===Checkout version" 82 | (cd $download_dir && git reset --hard HEAD) 83 | (cd $download_dir && git checkout "v$flutter_version") 84 | #$flutter_command downgrade "v$flutter_version" 85 | echo "===Checkout version done" 86 | ################################################################ 87 | # 预处理SDK 88 | handleSDK 89 | # 判断切换版本是否成功 90 | curFlutterVersion=`$flutter_command --version | grep '^Flutter' | cut -d ' ' -f2` 91 | if [ $curFlutterVersion == $flutter_version ] 92 | then 93 | execFlutter $* 94 | else 95 | echo "===Change version failed" 96 | fi 97 | fi 98 | # 备注 99 | # 获取某个命令的返回值 使用 STR=$(uname) 或者 STR=`uname` 100 | # 变量赋值等号前后不能有空格 如 STR="123" 101 | # shell if 是对空格敏感 如:if [ "dd" == "dd" ] 102 | # if [[ "$(uname)" == *AA* ]] 嵌套中括号是支持正则使用 103 | --------------------------------------------------------------------------------