build_jetbrains.sh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. # Opencode JetBrains Plugin Build Script
  4. # Supports building two variants:
  5. # - Standard: bundles opencode binaries (default)
  6. # - GUI-only: no binaries, uses system opencode, embeds webgui-dist
  7. #
  8. # By default both variants are built. Use --gui-only or --standard-only to
  9. # build a single variant.
  10. SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  11. ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)"
  12. PLUGIN_DIR="$ROOT_DIR/hosts/jetbrains-plugin"
  13. GRADLEW="$PLUGIN_DIR/gradlew"
  14. WEBGUI_DIR="$ROOT_DIR/packages/opencode/webgui"
  15. WEBGUI_DIST="$ROOT_DIR/packages/opencode/webgui-dist"
  16. BUILD_STANDARD=true
  17. BUILD_GUI_ONLY=true
  18. SKIP_BINARIES=false
  19. EXTRA_ARGS=()
  20. while [[ $# -gt 0 ]]; do
  21. case $1 in
  22. --gui-only)
  23. BUILD_STANDARD=false
  24. BUILD_GUI_ONLY=true
  25. shift
  26. ;;
  27. --standard-only)
  28. BUILD_STANDARD=true
  29. BUILD_GUI_ONLY=false
  30. shift
  31. ;;
  32. --skip-binaries)
  33. SKIP_BINARIES=true
  34. shift
  35. ;;
  36. --help)
  37. echo "Usage: $0 [OPTIONS]"
  38. echo "Options:"
  39. echo " --gui-only Build only the gui-only variant (no binaries)"
  40. echo " --standard-only Build only the standard variant (with binaries)"
  41. echo " --skip-binaries Skip building backend binaries"
  42. echo " --help Show this help message"
  43. exit 0
  44. ;;
  45. *)
  46. EXTRA_ARGS+=("$1")
  47. shift
  48. ;;
  49. esac
  50. done
  51. echo "Opencode JetBrains Plugin Build Script"
  52. echo "Plugin directory: $PLUGIN_DIR"
  53. [ "$BUILD_STANDARD" = true ] && echo " Variant: standard (with binaries)"
  54. [ "$BUILD_GUI_ONLY" = true ] && echo " Variant: gui-only (system opencode)"
  55. echo "=> Verifying JetBrains plugin workspace"
  56. if [ ! -d "$PLUGIN_DIR" ]; then
  57. echo "Error: JetBrains plugin directory not found at $PLUGIN_DIR" >&2
  58. exit 1
  59. fi
  60. if [ ! -x "$GRADLEW" ] && [ -f "$GRADLEW" ]; then
  61. chmod +x "$GRADLEW"
  62. fi
  63. if [ ! -f "$GRADLEW" ]; then
  64. echo "Error: gradlew not found at $GRADLEW" >&2
  65. exit 1
  66. fi
  67. # ─── Standard variant ────────────────────────────────────────────────────
  68. if [ "$BUILD_STANDARD" = true ]; then
  69. echo "=> Building standard variant"
  70. if [ "$SKIP_BINARIES" = false ]; then
  71. echo "=> Building opencode binaries"
  72. "$SCRIPT_DIR/build_opencode.sh"
  73. fi
  74. cd "$PLUGIN_DIR"
  75. "$GRADLEW" clean buildPlugin "${EXTRA_ARGS[@]+"${EXTRA_ARGS[@]}"}"
  76. echo "=> Standard variant built"
  77. fi
  78. # ─── GUI-only variant ────────────────────────────────────────────────────
  79. if [ "$BUILD_GUI_ONLY" = true ]; then
  80. echo "=> Building gui-only variant"
  81. # Build webgui if webgui-dist doesn't exist yet
  82. if [ ! -d "$WEBGUI_DIST" ] || [ -z "$(ls -A "$WEBGUI_DIST" 2>/dev/null)" ]; then
  83. echo "=> Building webgui..."
  84. cd "$WEBGUI_DIR"
  85. if command -v bun >/dev/null 2>&1; then
  86. bun run build
  87. elif command -v pnpm >/dev/null 2>&1; then
  88. pnpm run build
  89. else
  90. npm run build
  91. fi
  92. fi
  93. if [ ! -d "$WEBGUI_DIST" ]; then
  94. echo "Error: webgui-dist not found at $WEBGUI_DIST after build" >&2
  95. exit 1
  96. fi
  97. cd "$PLUGIN_DIR"
  98. "$GRADLEW" buildPlugin -PguiOnly=true "-PwebguiDist=$WEBGUI_DIST" "${EXTRA_ARGS[@]+"${EXTRA_ARGS[@]}"}"
  99. echo "=> GUI-only variant built"
  100. fi
  101. echo "=> Build completed"
  102. # List output artifacts
  103. shopt -s nullglob
  104. ARTIFACTS=( "$PLUGIN_DIR"/build/distributions/*.zip )
  105. shopt -u nullglob
  106. if ((${#ARTIFACTS[@]} > 0)); then
  107. echo "Artifacts:"
  108. for a in "${ARTIFACTS[@]}"; do
  109. echo " $(basename "$a")"
  110. done
  111. fi