app-starlock/pre_build.sh

78 lines
2.1 KiB
Bash
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="xhj"
main_file="lib/main_xhj_full.dart"
version_string="1.0.52"
file_path="lib/network/api.dart"
###############################################################
###############################################################
# 判断执行环境
case $environment in
dev)
api_prefix='https://dev.lock.star-lock.cn'
;;
pre)
api_prefix='https://pre.lock.star-lock.cn'
;;
sky)
api_prefix='https://lock.skychip.top'
;;
xhj)
api_prefix='https://lock.xhjcn.ltd'
;;
*)
echo "错误: flavor[$environment] apiPrefix not found"
exit 1
;;
esac
echo "API 前缀为: $api_prefix"
urls=$(curl -s -X POST -d "version=$version_string" "$environment/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
# 比较urls和string_array中的元素
for url in $urls; do
for string in "${string_array[@]}"; do
# 移除单引号以便比较
cleaned_string=$(echo "$string" | tr -d "'")
if [[ "$cleaned_string" == "$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