From 0dd00b4250b3bfb2572dc4dbe66389cc62f3a49a Mon Sep 17 00:00:00 2001 From: anfe <448468458@qq.com> Date: Fri, 21 Jun 2024 10:36:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=AE=8C=E6=88=90=20=20=E5=BA=9F=E5=BC=83?= =?UTF-8?q?=20api=20=E6=A3=80=E6=B5=8B=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pre_build.sh | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 pre_build.sh 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 +