build_vscode.bat 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. @echo off
  2. REM Opencode VSCode Extension Build Script for Windows
  3. REM Handles the complete build process for the Opencode VSCode extension
  4. setlocal enabledelayedexpansion
  5. REM Resolve key directories
  6. set "SCRIPT_DIR=%~dp0"
  7. set "ROOT_DIR=%SCRIPT_DIR%..\.."
  8. for %%I in ("%ROOT_DIR%") do set "ROOT_DIR=%%~fI"
  9. set "PLUGIN_DIR=%ROOT_DIR%\hosts\vscode-plugin"
  10. if not exist "%PLUGIN_DIR%\package.json" (
  11. echo [ERROR] package.json not found. Please run this script from the repository root.
  12. exit /b 1
  13. )
  14. echo Opencode VSCode Extension Build Script
  15. echo Plugin directory: %PLUGIN_DIR%
  16. echo Root directory: %ROOT_DIR%
  17. set "BUILD_TYPE=development"
  18. set "SKIP_BINARIES=false"
  19. set "SKIP_TESTS=false"
  20. set "PACKAGE_ONLY=false"
  21. :parse_args
  22. if "%~1"=="" goto args_done
  23. if "%~1"=="--production" (
  24. set "BUILD_TYPE=production"
  25. shift
  26. goto parse_args
  27. )
  28. if "%~1"=="--skip-binaries" (
  29. set "SKIP_BINARIES=true"
  30. shift
  31. goto parse_args
  32. )
  33. if "%~1"=="--skip-tests" (
  34. set "SKIP_TESTS=true"
  35. shift
  36. goto parse_args
  37. )
  38. if "%~1"=="--package-only" (
  39. set "PACKAGE_ONLY=true"
  40. shift
  41. goto parse_args
  42. )
  43. if "%~1"=="--help" (
  44. echo Usage: %0 [OPTIONS]
  45. echo --production Build for production (default: development)
  46. echo --skip-binaries Skip building backend binaries
  47. echo --skip-tests Skip running tests
  48. echo --package-only Only create the .vsix package (skip compilation)
  49. echo --help Show this help message
  50. exit /b 0
  51. )
  52. echo [ERROR] Unknown option: %~1
  53. exit /b 1
  54. :args_done
  55. echo [INFO] Building VSCode extension in %BUILD_TYPE% mode
  56. cd /d "%PLUGIN_DIR%"
  57. if "%PACKAGE_ONLY%"=="false" (
  58. echo [INFO] Cleaning previous build artifacts...
  59. call pnpm run clean 2>nul
  60. if errorlevel 1 echo [WARN] Clean command failed, continuing...
  61. )
  62. if "%PACKAGE_ONLY%"=="false" (
  63. echo [INFO] Installing dependencies...
  64. where pnpm >nul 2>&1
  65. if not errorlevel 1 (
  66. call pnpm install
  67. ) else (
  68. where npm >nul 2>&1
  69. if errorlevel 1 (
  70. echo [ERROR] Neither pnpm nor npm found. Please install a package manager.
  71. exit /b 1
  72. )
  73. call npm install
  74. )
  75. )
  76. if "%SKIP_BINARIES%"=="false" (
  77. if "%PACKAGE_ONLY%"=="false" (
  78. echo [INFO] Building backend binaries...
  79. cd /d "%ROOT_DIR%"
  80. if exist "hosts\scripts\build_opencode.bat" (
  81. call hosts\scripts\build_opencode.bat
  82. ) else (
  83. echo [ERROR] Backend build script not found at hosts\scripts\build_opencode.bat
  84. exit /b 1
  85. )
  86. cd /d "%PLUGIN_DIR%"
  87. )
  88. )
  89. if "%PACKAGE_ONLY%"=="false" (
  90. echo [INFO] Compiling TypeScript...
  91. if "%BUILD_TYPE%"=="production" (
  92. call pnpm run compile:production
  93. ) else (
  94. call pnpm run compile
  95. )
  96. )
  97. if "%PACKAGE_ONLY%"=="false" (
  98. echo [INFO] Running linter...
  99. call pnpm run lint
  100. if errorlevel 1 echo [WARN] Linting failed, continuing with build...
  101. )
  102. if "%SKIP_TESTS%"=="false" (
  103. if "%PACKAGE_ONLY%"=="false" (
  104. echo [INFO] Running tests...
  105. call pnpm run test
  106. if errorlevel 1 echo [WARN] Tests failed, continuing with build...
  107. )
  108. )
  109. echo [INFO] Checking for required binaries...
  110. set "MISSING_BINARIES=false"
  111. if not exist "resources\bin\windows\amd64\opencode.exe" (
  112. echo [WARN] Missing binary: resources\bin\windows\amd64\opencode.exe
  113. set "MISSING_BINARIES=true"
  114. )
  115. if not exist "resources\bin\macos\amd64\opencode" (
  116. echo [WARN] Missing binary: resources\bin\macos\amd64\opencode
  117. set "MISSING_BINARIES=true"
  118. )
  119. if not exist "resources\bin\macos\arm64\opencode" (
  120. echo [WARN] Missing binary: resources\bin\macos\arm64\opencode
  121. set "MISSING_BINARIES=true"
  122. )
  123. if not exist "resources\bin\linux\amd64\opencode" (
  124. echo [WARN] Missing binary: resources\bin\linux\amd64\opencode
  125. set "MISSING_BINARIES=true"
  126. )
  127. if not exist "resources\bin\linux\arm64\opencode" (
  128. echo [WARN] Missing binary: resources\bin\linux\arm64\opencode
  129. set "MISSING_BINARIES=true"
  130. )
  131. if "%MISSING_BINARIES%"=="true" (
  132. echo [WARN] Some binaries are missing. The extension may not work on all platforms.
  133. echo [WARN] Run 'hosts\scripts\build_opencode.bat' from the repository root to build all binaries.
  134. )
  135. echo [INFO] Creating VSCode extension package
  136. REM Prefer local vsce (node_modules/.bin) to avoid global installs.
  137. where pnpm >nul 2>&1
  138. if not errorlevel 1 (
  139. set "VSCE_CMD=pnpm exec vsce"
  140. ) else (
  141. set "VSCE_CMD=npx --yes vsce"
  142. )
  143. REM Use package.json version in the output .vsix name.
  144. set "PLUGIN_VERSION="
  145. for /f "usebackq delims=" %%V in (`node -p "require('./package.json').version" 2^>nul`) do set "PLUGIN_VERSION=%%V"
  146. if "%PLUGIN_VERSION%"=="" set "PLUGIN_VERSION=0.0.0"
  147. set "VSIX_NAME=opencode-vscode-%PLUGIN_VERSION%-dev.vsix"
  148. if "%BUILD_TYPE%"=="production" set "VSIX_NAME=opencode-vscode-%PLUGIN_VERSION%.vsix"
  149. if "%BUILD_TYPE%"=="production" goto package_production
  150. call %VSCE_CMD% package --pre-release --no-dependencies --out "%VSIX_NAME%"
  151. if errorlevel 1 exit /b 1
  152. goto package_complete
  153. :package_production
  154. call %VSCE_CMD% package --no-dependencies --out "%VSIX_NAME%"
  155. if errorlevel 1 exit /b 1
  156. :package_complete
  157. echo [INFO] Build completed successfully!
  158. endlocal