app-starlock/pre_build.sh
2024-06-21 10:36:10 +08:00

40 lines
1.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.51"
file_path="lib/network/api.dart"
urls=$(curl -s -X POST -d "version=$version_string" 'https://lock.xhjcn.ltd/api/app/getDeprecatedApiList' | jq -r '.data[].url')
echo "* 成功获取废弃 api 数据"
string_array=()
# 使用egrep搜索被单引号包裹的字符串
while IFS= read -r line; do
string_array+=("$line")
done < <(egrep -o "'[^']*'" "$file_path")
echo "* 解析 api 文件数据,开始对比"
# 比较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
done
echo "* 没有发现 废弃 api开始编译"
flutter clean && flutter pub get
flutter build apk --flavor $environment -t $main_file
flutter build ios --flavor $environment -t $main_file