build_api.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/bin/sh
  2. # 红色信息
  3. function echoRedInfo() {
  4. echo -e "\e[31m$@\e[0m"
  5. }
  6. # 绿色信息
  7. function echoGreenInfo() {
  8. echo -e "\e[32m$@\e[0m"
  9. }
  10. # 蓝色信息
  11. function echoBlueInfo() {
  12. echo -e "\e[34m$@\e[0m"
  13. }
  14. url1="http://172.18.32.33:5050"
  15. url2="http://127.0.0.1:5050"
  16. url3="http://localhost:5005"
  17. # 打印菜单
  18. echoBlueInfo "请选择Swagger地址:"
  19. echoBlueInfo "(1) $url1"
  20. echoBlueInfo "(2) $url2"
  21. echoBlueInfo "(3) $url3"
  22. read -p "请输入选项 [1-3]: " choice
  23. currPath=$(pwd)
  24. parentPath=$(dirname "$currPath")
  25. apiServicesPath=${parentPath}/src/api-services/
  26. echo "生成目录 ${apiServicesPath}"
  27. # 判断目录是否存在
  28. if test -d "$apiServicesPath"; then
  29. echo "删除目录 api-services"
  30. rm -rf "${apiServicesPath}"
  31. fi
  32. echo "开始生成 api-services"
  33. # 检查用户输入并执行相应操作
  34. case $choice in
  35. 1)
  36. echoGreenInfo "您选择了: $url1"
  37. java -jar "${currPath}"/swagger-codegen-cli.jar generate -i $url1/swagger/All%20Groups/swagger.json -l typescript-axios -o "${apiServicesPath}"
  38. ;;
  39. 2)
  40. echoGreenInfo "您选择了: $url2"
  41. java -jar "${currPath}"/swagger-codegen-cli.jar generate -i $url2/swagger/All%20Groups/swagger.json -l typescript-axios -o "${apiServicesPath}"
  42. ;;
  43. 3)
  44. echoGreenInfo "您选择了: $url3"
  45. java -jar "${currPath}"/swagger-codegen-cli.jar generate -i $url3/swagger/All%20Groups/swagger.json -l typescript-axios -o "${apiServicesPath}"
  46. ;;
  47. *)
  48. echoRedInfo "无效的选项,请输入[1-3]。"
  49. exit 1
  50. ;;
  51. esac
  52. rm -rf "${apiServicesPath}".swagger-codegen
  53. rm -f "${apiServicesPath}".gitignore
  54. rm -f "${apiServicesPath}".npmignore
  55. rm -f "${apiServicesPath}".swagger-codegen-ignore
  56. rm -f "${apiServicesPath}"git_push.sh
  57. rm -f "${apiServicesPath}"package.json
  58. rm -f "${apiServicesPath}"README.md
  59. rm -f "${apiServicesPath}"tsconfig.json
  60. echoGreenInfo "生成结束"