소스 검색

🎈 perf(api_build): 支持选择不同环境的地址生成接口代码

Hans 1 년 전
부모
커밋
1927f875b3
1개의 변경된 파일67개의 추가작업 그리고 0개의 파일을 삭제
  1. 67 0
      Web/api_build/build_api.sh

+ 67 - 0
Web/api_build/build_api.sh

@@ -0,0 +1,67 @@
+#!/bin/sh
+# 红色信息
+function echoRedInfo() {
+    echo -e "\e[31m$@\e[0m"
+}
+# 绿色信息
+function echoGreenInfo() {
+    echo -e "\e[32m$@\e[0m"
+}
+# 蓝色信息
+function echoBlueInfo() {
+    echo -e "\e[34m$@\e[0m"
+}
+url1="http://172.18.32.33:5050"
+url2="http://127.0.0.1:5050"
+url3="http://localhost:5005"
+# 打印菜单
+echoBlueInfo "请选择Swagger地址:"
+echoBlueInfo "(1) $url1"
+echoBlueInfo "(2) $url2"
+echoBlueInfo "(3) $url3"
+read -p "请输入选项 [1-3]: " choice
+
+currPath=$(pwd)
+parentPath=$(dirname "$currPath")
+apiServicesPath=${parentPath}/src/api-services/
+
+echo "生成目录 ${apiServicesPath}"
+
+# 判断目录是否存在
+if test -d "$apiServicesPath"; then
+  echo "删除目录 api-services"
+  rm -rf "${apiServicesPath}"
+fi
+
+echo "开始生成 api-services"
+
+
+# 检查用户输入并执行相应操作
+case $choice in
+    1)
+        echoGreenInfo "您选择了: $url1"
+        java -jar "${currPath}"/swagger-codegen-cli.jar generate -i $url1/swagger/All%20Groups/swagger.json -l typescript-axios -o "${apiServicesPath}"
+        ;;
+    2)
+        echoGreenInfo "您选择了: $url2"
+        java -jar "${currPath}"/swagger-codegen-cli.jar generate -i $url2/swagger/All%20Groups/swagger.json -l typescript-axios -o "${apiServicesPath}"
+        ;;
+    3)
+        echoGreenInfo "您选择了: $url3"
+        java -jar "${currPath}"/swagger-codegen-cli.jar generate -i $url3/swagger/All%20Groups/swagger.json -l typescript-axios -o "${apiServicesPath}"
+        ;;
+    *)
+        echoRedInfo "无效的选项,请输入[1-3]。"
+        exit 1
+        ;;
+esac
+rm -rf "${apiServicesPath}".swagger-codegen
+rm -f "${apiServicesPath}".gitignore
+rm -f "${apiServicesPath}".npmignore
+rm -f "${apiServicesPath}".swagger-codegen-ignore
+rm -f "${apiServicesPath}"git_push.sh
+rm -f "${apiServicesPath}"package.json
+rm -f "${apiServicesPath}"README.md
+rm -f "${apiServicesPath}"tsconfig.json
+
+echoGreenInfo "生成结束"