build_jetbrains.bat 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. @echo off
  2. setlocal EnableExtensions EnableDelayedExpansion
  3. REM Opencode JetBrains Plugin Build Script
  4. REM Supports building two variants:
  5. REM - Standard: bundles opencode binaries (default)
  6. REM - GUI-only: no binaries, uses system opencode, embeds webgui-dist
  7. REM
  8. REM By default both variants are built. Use --gui-only or --standard-only to
  9. REM build a single variant.
  10. set "SCRIPT_DIR=%~dp0"
  11. set "ROOT_DIR=%SCRIPT_DIR%..\.."
  12. for %%I in ("%ROOT_DIR%") do set "ROOT_DIR=%%~fI"
  13. set "PLUGIN_DIR=%ROOT_DIR%\hosts\jetbrains-plugin"
  14. set "GRADLEW=%PLUGIN_DIR%\gradlew.bat"
  15. set "WEBGUI_DIR=%ROOT_DIR%\packages\opencode\webgui"
  16. set "WEBGUI_DIST=%ROOT_DIR%\packages\opencode\webgui-dist"
  17. set "BUILD_STANDARD=true"
  18. set "BUILD_GUI_ONLY=true"
  19. set "SKIP_BINARIES=false"
  20. :parse_args
  21. if "%~1"=="" goto args_done
  22. if "%~1"=="--gui-only" (
  23. set "BUILD_STANDARD=false"
  24. set "BUILD_GUI_ONLY=true"
  25. shift
  26. goto parse_args
  27. )
  28. if "%~1"=="--standard-only" (
  29. set "BUILD_STANDARD=true"
  30. set "BUILD_GUI_ONLY=false"
  31. shift
  32. goto parse_args
  33. )
  34. if "%~1"=="--skip-binaries" (
  35. set "SKIP_BINARIES=true"
  36. shift
  37. goto parse_args
  38. )
  39. if "%~1"=="--help" (
  40. echo Usage: %~nx0 [OPTIONS]
  41. echo Options:
  42. echo --gui-only Build only the gui-only variant (no binaries)
  43. echo --standard-only Build only the standard variant (with binaries)
  44. echo --skip-binaries Skip building backend binaries
  45. echo --help Show this help message
  46. exit /b 0
  47. )
  48. shift
  49. goto parse_args
  50. :args_done
  51. if not exist "%PLUGIN_DIR%" (
  52. echo [ERROR] JetBrains plugin directory not found at %PLUGIN_DIR%
  53. exit /b 1
  54. )
  55. if not exist "%GRADLEW%" (
  56. echo [ERROR] gradlew.bat not found at %GRADLEW%
  57. exit /b 1
  58. )
  59. echo Opencode JetBrains Plugin Build Script
  60. echo Plugin directory: %PLUGIN_DIR%
  61. if "%BUILD_STANDARD%"=="true" echo Variant: standard (with binaries)
  62. if "%BUILD_GUI_ONLY%"=="true" echo Variant: gui-only (system opencode)
  63. REM ─── Standard variant ──────────────────────────────────────────────────
  64. if not "%BUILD_STANDARD%"=="true" goto skip_standard
  65. echo [INFO] Building standard variant
  66. if "%SKIP_BINARIES%"=="true" goto skip_std_binaries
  67. echo [INFO] Building opencode binaries
  68. pushd "%ROOT_DIR%" >nul
  69. call hosts\scripts\build_opencode.bat
  70. set "BIN_STATUS=%ERRORLEVEL%"
  71. popd >nul
  72. if not "%BIN_STATUS%"=="0" (
  73. echo [ERROR] Failed to build opencode binaries
  74. exit /b %BIN_STATUS%
  75. )
  76. :skip_std_binaries
  77. pushd "%PLUGIN_DIR%" >nul
  78. call "%GRADLEW%" clean buildPlugin
  79. set "GRADLE_STATUS=%ERRORLEVEL%"
  80. popd >nul
  81. if not "%GRADLE_STATUS%"=="0" (
  82. echo [ERROR] Standard JetBrains plugin build failed
  83. exit /b %GRADLE_STATUS%
  84. )
  85. echo [INFO] Standard variant built
  86. :skip_standard
  87. REM ─── GUI-only variant ──────────────────────────────────────────────────
  88. if not "%BUILD_GUI_ONLY%"=="true" goto skip_gui_only
  89. echo [INFO] Building gui-only variant
  90. if not exist "%WEBGUI_DIST%" (
  91. echo [INFO] Building webgui...
  92. pushd "%WEBGUI_DIR%" >nul
  93. if exist "node_modules\.bin\vite" (
  94. call npm run build
  95. ) else (
  96. call npm install
  97. call npm run build
  98. )
  99. popd >nul
  100. )
  101. if not exist "%WEBGUI_DIST%" (
  102. echo [ERROR] webgui-dist not found at %WEBGUI_DIST% after build
  103. exit /b 1
  104. )
  105. pushd "%PLUGIN_DIR%" >nul
  106. call "%GRADLEW%" buildPlugin -PguiOnly=true "-PwebguiDist=%WEBGUI_DIST%"
  107. set "GRADLE_STATUS=%ERRORLEVEL%"
  108. popd >nul
  109. if not "%GRADLE_STATUS%"=="0" (
  110. echo [ERROR] GUI-only JetBrains plugin build failed
  111. exit /b %GRADLE_STATUS%
  112. )
  113. echo [INFO] GUI-only variant built
  114. :skip_gui_only
  115. echo [INFO] Build completed successfully
  116. exit /b 0