diff --git a/pre_build.sh b/pre_build.sh new file mode 100644 index 00000000..8bdf7f47 --- /dev/null +++ b/pre_build.sh @@ -0,0 +1,39 @@ +#!/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 +