app-starlock/pre_build.sh

111 lines
2.9 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 废弃 api 检测脚本+项目编译脚本
# 首次使用记得安装jq brew install jq
###############################################################
############## 正常情况下只需要修改配置,不需要修改代码 ###############
###############################################################
# 设置
# 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_lite.dart"
api_prefix='https://lock.skychip.top'
;;
xhj)
main_file="lib/main_xhj_lite.dart"
api_prefix='https://lock.xhjcn.ltd'
;;
local)
main_file="lib/main_local.dart"
api_prefix='http://zhou.lock.star-lock.cn'
;;
*)
echo "错误: flavor[$environment] mainFile not found"
exit 1
;;
esac
# 版本改为从 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")
error_code=$(echo $response | jq '.errorCode')
# 判断是否成功
if [ "$error_code" != "0" ]; then
error_msg=$(echo $response | jq -r '.errorMsg')
echo "失败:$error_msg"
exit 1
fi
urls=$(curl -s -X POST -d "version=$version_string" "$api_prefix/api/app/getDeprecatedApiList" | jq -r '.data[].url')
echo "* 成功获取废弃 api 数据"
# 解析 api 文件数据
string_array=()
while IFS= read -r line; do
string_array+=("$line")
done < <(egrep -o "'[^']*'" "$file_path")
echo "* 解析 api 文件数据,开始对比"
# 进度条初始化
total_urls=$(echo "$urls" | wc -l | tr -d ' ')
current_url=0
# 检查每个废弃的API URL
for url in $urls; do
#删除${string_array[@]}中的单引号
string_array=(${string_array[@]//\'/})
for element in "${string_array[@]}"; do
if [[ "$element" == "$url" ]]; then
echo "错误: 存在废弃 api: $url"
exit 1
fi
done
# 更新进度条
let current_url++
let progress=(current_url*100/total_urls)
printf "\r进度: [%-50s] %d%%" $(printf '%*s' $((progress/2)) | tr ' ' '#') $progress
done
# 新的输出从新行开始
echo -e "\n* 没有发现废弃 API开始编译"
# 编译命令
#flutter clean && flutter pub get
#flutter build apk --flavor $environment -t $main_file
#flutter build ios --flavor $environment -t $main_file
#flutter build appbundle --flavor $environment -t $main_file