build.ps1 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # 启用UTF-8编码
  2. [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
  3. # 获取脚本所在目录
  4. $scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
  5. # 设置默认参数
  6. $moduleName = "apiServices"
  7. $apiServicesPath = Join-Path (Join-Path $scriptDir "..") "src\api-services\"
  8. $apiUrl = "http://localhost:5005/swagger/Default/swagger.json"
  9. # 根据传入的参数修改配置
  10. if ($args[0] -eq "approvalFlow") {
  11. $moduleName = "approvalFlow"
  12. $apiServicesPath = Join-Path (Join-Path $scriptDir "..") "src\api-plugins\approvalFlow\"
  13. $apiUrl = "http://localhost:5005/swagger/ApprovalFlow/swagger.json"
  14. } elseif ($args[0] -eq "dingTalk") {
  15. $moduleName = "dingTalk"
  16. $apiServicesPath = Join-Path (Join-Path $scriptDir "..") "src\api-plugins\dingTalk\"
  17. $apiUrl = "http://localhost:5005/swagger/DingTalk/swagger.json"
  18. } elseif ($args[0] -eq "goView") {
  19. $moduleName = "goView"
  20. $apiServicesPath = Join-Path (Join-Path $scriptDir "..") "src\api-plugins\goView\"
  21. # 注意:PowerShell会自动处理URL编码,所以不需要手动添加%20等
  22. $apiUrl = "http://localhost:5005/swagger/GoView/swagger.json"
  23. }
  24. # 输出信息和删除现有目录
  25. Write-Output "================================ 删除目录 $moduleName ================================"
  26. if (Test-Path $apiServicesPath) {
  27. Remove-Item -Path $apiServicesPath -Recurse -Force
  28. }
  29. # 开始生成代码
  30. Write-Output "================================ 开始生成 $moduleName ================================"
  31. # 输出调试信息
  32. Write-Output "脚本目录: $scriptDir"
  33. Write-Output "模块名称: $moduleName"
  34. Write-Output "输出路径: $apiServicesPath"
  35. Write-Output "API URL: $apiUrl"
  36. # 执行代码生成命令
  37. try {
  38. $codeGenJar = Join-Path $scriptDir "swagger-codegen-cli.jar"
  39. java -jar $codeGenJar generate -i $apiUrl -l typescript-axios -o $apiServicesPath
  40. if ($LASTEXITCODE -ne 0) {
  41. throw "Java命令执行失败,退出代码: $LASTEXITCODE"
  42. }
  43. } catch {
  44. Write-Error "代码生成失败: $_"
  45. exit 1
  46. }
  47. # 删除不必要的文件和文件夹
  48. Write-Output "================================ 删除不必要的文件和文件夹 ================================"
  49. $filesToDelete = @(
  50. "$apiServicesPath\.swagger-codegen",
  51. "$apiServicesPath\.gitignore",
  52. "$apiServicesPath\.npmignore",
  53. "$apiServicesPath\.swagger-codegen-ignore",
  54. "$apiServicesPath\git_push.sh",
  55. "$apiServicesPath\package.json",
  56. "$apiServicesPath\README.md",
  57. "$apiServicesPath\tsconfig.json"
  58. )
  59. foreach ($filePath in $filesToDelete) {
  60. if (Test-Path $filePath) {
  61. if ((Get-Item $filePath) -is [System.IO.DirectoryInfo]) {
  62. Remove-Item -Path $filePath -Recurse -Force
  63. } else {
  64. Remove-Item -Path $filePath -Force
  65. }
  66. }
  67. }
  68. Write-Output "================================ 生成结束 ================================"