From 08ac829803b921c1435e73d821284e61a98176c1 Mon Sep 17 00:00:00 2001 From: XieHaoLiang <806854015@qq.com> Date: Tue, 23 Jul 2024 17:40:25 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BA=A0=E6=AD=A3=E8=87=AA=E5=8A=A8=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=E5=BA=9F=E5=BC=83=E6=8E=A5=E5=8F=A3=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pre_build.sh | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/pre_build.sh b/pre_build.sh index 4fb0373f..cad9b0cc 100644 --- a/pre_build.sh +++ b/pre_build.sh @@ -8,34 +8,49 @@ ############## 正常情况下只需要修改配置,不需要修改代码 ############### ############################################################### # 设置 -environment="xhj" -main_file="lib/main_xhj_full.dart" -version_string="1.0.69" -file_path="lib/network/api.dart" +# environment 改为命令行参数 +environment=$1 +if [ -z "$environment" ]; then + echo "错误: 请传入环境参数" + exit 1 +fi -############################################################### -############################################################### - -# 判断执行环境 +# main_file 根据环境选择 case $environment in dev) + main_file="lib/main_dev.dart" api_prefix='https://dev.lock.star-lock.cn' ;; pre) + main_file="lib/main_pre.dart" api_prefix='https://pre.lock.star-lock.cn' ;; sky) + main_file="lib/main_sky.dart" api_prefix='https://lock.skychip.top' ;; xhj) + main_file="lib/main_xhj.dart" api_prefix='https://lock.xhjcn.ltd' ;; *) - echo "错误: flavor[$environment] apiPrefix not found" + echo "错误: flavor[$environment] mainFile not found" exit 1 ;; esac + +#version_string="1.0.69" +# 版本改为从 pubspec.yaml 的 version 字段获取 +version_string=$(grep version: pubspec.yaml | awk '{print $2}' | tr -d "'") +# 读取到的版本号为 1.0.69+2024070302 需要去掉 +2024070302 +version_string=${version_string%%+*} + +echo "版本号为: $version_string" + +file_path="lib/network/api.dart" + + echo "API 前缀为: $api_prefix" response=$(curl -s -X POST -d "version=$version_string" "$api_prefix/api/app/checkAppBuildVersion") @@ -61,6 +76,9 @@ echo "* 解析 api 文件数据,开始对比" # 进度条初始化 total_urls=$(echo "$urls" | wc -l | tr -d ' ') current_url=0 +# 打印 string_array +echo "string_array: ${string_array[@]}" + # 比较urls和string_array中的元素 for url in $urls; do @@ -82,6 +100,6 @@ done echo -e "\n* 没有发现废弃 API,开始编译" # 编译命令 -flutter clean && flutter pub get +#flutter clean && flutter pub get flutter build apk --flavor $environment -t $main_file flutter build ios --flavor $environment -t $main_file