|
|
@@ -1,6 +1,12 @@
|
|
|
@echo off
|
|
|
REM Opencode VSCode Extension Build Script for Windows
|
|
|
-REM Handles the complete build process for the Opencode VSCode extension
|
|
|
+REM Handles the complete build process for the Opencode VSCode extension.
|
|
|
+REM Supports building two variants:
|
|
|
+REM - Standard: bundles opencode binaries (default)
|
|
|
+REM - GUI-only: no binaries, uses system opencode, embeds webgui-dist
|
|
|
+REM
|
|
|
+REM By default both variants are built. Use --gui-only or --standard-only to
|
|
|
+REM build a single variant.
|
|
|
|
|
|
setlocal enabledelayedexpansion
|
|
|
|
|
|
@@ -9,6 +15,8 @@ set "SCRIPT_DIR=%~dp0"
|
|
|
set "ROOT_DIR=%SCRIPT_DIR%..\.."
|
|
|
for %%I in ("%ROOT_DIR%") do set "ROOT_DIR=%%~fI"
|
|
|
set "PLUGIN_DIR=%ROOT_DIR%\hosts\vscode-plugin"
|
|
|
+set "WEBGUI_DIR=%ROOT_DIR%\packages\opencode\webgui"
|
|
|
+set "WEBGUI_DIST=%ROOT_DIR%\packages\opencode\webgui-dist"
|
|
|
|
|
|
if not exist "%PLUGIN_DIR%\package.json" (
|
|
|
echo [ERROR] package.json not found. Please run this script from the repository root.
|
|
|
@@ -23,6 +31,8 @@ set "BUILD_TYPE=development"
|
|
|
set "SKIP_BINARIES=false"
|
|
|
set "SKIP_TESTS=false"
|
|
|
set "PACKAGE_ONLY=false"
|
|
|
+set "BUILD_STANDARD=true"
|
|
|
+set "BUILD_GUI_ONLY=true"
|
|
|
|
|
|
:parse_args
|
|
|
if "%~1"=="" goto args_done
|
|
|
@@ -46,12 +56,26 @@ if "%~1"=="--package-only" (
|
|
|
shift
|
|
|
goto parse_args
|
|
|
)
|
|
|
+if "%~1"=="--gui-only" (
|
|
|
+ set "BUILD_STANDARD=false"
|
|
|
+ set "BUILD_GUI_ONLY=true"
|
|
|
+ shift
|
|
|
+ goto parse_args
|
|
|
+)
|
|
|
+if "%~1"=="--standard-only" (
|
|
|
+ set "BUILD_STANDARD=true"
|
|
|
+ set "BUILD_GUI_ONLY=false"
|
|
|
+ shift
|
|
|
+ goto parse_args
|
|
|
+)
|
|
|
if "%~1"=="--help" (
|
|
|
echo Usage: %0 [OPTIONS]
|
|
|
echo --production Build for production (default: development)
|
|
|
echo --skip-binaries Skip building backend binaries
|
|
|
echo --skip-tests Skip running tests
|
|
|
echo --package-only Only create the .vsix package (skip compilation)
|
|
|
+ echo --gui-only Build only the gui-only variant (no binaries)
|
|
|
+ echo --standard-only Build only the standard variant (with binaries)
|
|
|
echo --help Show this help message
|
|
|
exit /b 0
|
|
|
)
|
|
|
@@ -61,13 +85,27 @@ exit /b 1
|
|
|
:args_done
|
|
|
|
|
|
echo [INFO] Building VSCode extension in %BUILD_TYPE% mode
|
|
|
+if "%BUILD_STANDARD%"=="true" echo [INFO] Variant: standard (with binaries)
|
|
|
+if "%BUILD_GUI_ONLY%"=="true" echo [INFO] Variant: gui-only (system opencode)
|
|
|
|
|
|
cd /d "%PLUGIN_DIR%"
|
|
|
|
|
|
+REM --- Shared preparation (compile once, package per-variant) ---
|
|
|
+
|
|
|
if "%PACKAGE_ONLY%"=="false" (
|
|
|
echo [INFO] Cleaning previous build artifacts...
|
|
|
- call pnpm run clean 2>nul
|
|
|
- if errorlevel 1 echo [WARN] Clean command failed, continuing...
|
|
|
+ if not exist "node_modules" (
|
|
|
+ echo [WARN] Dependencies not installed; skipping script clean and removing artifacts manually.
|
|
|
+ if exist "out" rmdir /s /q "out"
|
|
|
+ del /f /q *.vsix 2>nul
|
|
|
+ ) else (
|
|
|
+ call pnpm run clean 2>nul
|
|
|
+ if errorlevel 1 (
|
|
|
+ echo [WARN] Clean command failed, applying fallback removal...
|
|
|
+ if exist "out" rmdir /s /q "out"
|
|
|
+ del /f /q *.vsix 2>nul
|
|
|
+ )
|
|
|
+ )
|
|
|
)
|
|
|
|
|
|
if "%PACKAGE_ONLY%"=="false" (
|
|
|
@@ -87,15 +125,17 @@ if "%PACKAGE_ONLY%"=="false" (
|
|
|
|
|
|
if "%SKIP_BINARIES%"=="false" (
|
|
|
if "%PACKAGE_ONLY%"=="false" (
|
|
|
- echo [INFO] Building backend binaries...
|
|
|
- cd /d "%ROOT_DIR%"
|
|
|
- if exist "hosts\scripts\build_opencode.bat" (
|
|
|
- call hosts\scripts\build_opencode.bat
|
|
|
- ) else (
|
|
|
- echo [ERROR] Backend build script not found at hosts\scripts\build_opencode.bat
|
|
|
- exit /b 1
|
|
|
+ if "%BUILD_STANDARD%"=="true" (
|
|
|
+ echo [INFO] Building backend binaries...
|
|
|
+ cd /d "%ROOT_DIR%"
|
|
|
+ if exist "hosts\scripts\build_opencode.bat" (
|
|
|
+ call hosts\scripts\build_opencode.bat
|
|
|
+ ) else (
|
|
|
+ echo [ERROR] Backend build script not found at hosts\scripts\build_opencode.bat
|
|
|
+ exit /b 1
|
|
|
+ )
|
|
|
+ cd /d "%PLUGIN_DIR%"
|
|
|
)
|
|
|
- cd /d "%PLUGIN_DIR%"
|
|
|
)
|
|
|
)
|
|
|
|
|
|
@@ -122,6 +162,62 @@ if "%SKIP_TESTS%"=="false" (
|
|
|
)
|
|
|
)
|
|
|
|
|
|
+REM --- Resolve vsce command ---
|
|
|
+
|
|
|
+set "VSCE_CMD=vsce"
|
|
|
+where vsce >nul 2>&1
|
|
|
+if errorlevel 1 (
|
|
|
+ where npx >nul 2>&1
|
|
|
+ if not errorlevel 1 (
|
|
|
+ set "VSCE_CMD=npx -y @vscode/vsce"
|
|
|
+ ) else (
|
|
|
+ echo [WARN] vsce not found and npx unavailable; attempting global install via npm
|
|
|
+ call npm install -g @vscode/vsce
|
|
|
+ )
|
|
|
+)
|
|
|
+
|
|
|
+REM Generate timestamp
|
|
|
+for /f "tokens=2-4 delims=/ " %%a in ('date /t') do (
|
|
|
+ for /f "tokens=1-2 delims=/" %%c in ("%%a") do (
|
|
|
+ set "MONTH=%%c"
|
|
|
+ set "DAY=%%d"
|
|
|
+ )
|
|
|
+ set "YEAR=%%b"
|
|
|
+)
|
|
|
+for /f "tokens=1-2 delims=: " %%a in ('time /t') do (
|
|
|
+ set "HOUR=%%a"
|
|
|
+ set "MINUTE=%%b"
|
|
|
+)
|
|
|
+set "TIMESTAMP=%YEAR%%MONTH%%DAY%-%HOUR%%MINUTE%"
|
|
|
+
|
|
|
+REM --- Build helper: package a single variant ---
|
|
|
+
|
|
|
+if "%BUILD_STANDARD%"=="true" (
|
|
|
+ call :build_variant_standard
|
|
|
+ if errorlevel 1 exit /b 1
|
|
|
+)
|
|
|
+
|
|
|
+if "%BUILD_GUI_ONLY%"=="true" (
|
|
|
+ call :build_variant_gui_only
|
|
|
+ if errorlevel 1 exit /b 1
|
|
|
+)
|
|
|
+
|
|
|
+echo [INFO] Build completed successfully!
|
|
|
+echo [INFO] Extension packages created in: %PLUGIN_DIR%
|
|
|
+
|
|
|
+echo Packages created:
|
|
|
+for %%F in ("%PLUGIN_DIR%\*.vsix") do echo %%~nxF
|
|
|
+
|
|
|
+endlocal
|
|
|
+exit /b 0
|
|
|
+
|
|
|
+REM --- Build variant: standard ---
|
|
|
+:build_variant_standard
|
|
|
+echo [INFO] === Packaging STANDARD variant ===
|
|
|
+
|
|
|
+cd /d "%PLUGIN_DIR%"
|
|
|
+
|
|
|
+REM Check for required binaries
|
|
|
echo [INFO] Checking for required binaries...
|
|
|
set "MISSING_BINARIES=false"
|
|
|
if not exist "resources\bin\windows\amd64\opencode.exe" (
|
|
|
@@ -149,34 +245,96 @@ if "%MISSING_BINARIES%"=="true" (
|
|
|
echo [WARN] Run 'hosts\scripts\build_opencode.bat' from the repository root to build all binaries.
|
|
|
)
|
|
|
|
|
|
-echo [INFO] Creating VSCode extension package
|
|
|
-REM Prefer local vsce (node_modules/.bin) to avoid global installs.
|
|
|
-where pnpm >nul 2>&1
|
|
|
+REM Package with original package.json and .vscodeignore
|
|
|
+if "%BUILD_TYPE%"=="production" (
|
|
|
+ call %VSCE_CMD% package --no-dependencies --out "opencode-vscode-%TIMESTAMP%.vsix"
|
|
|
+) else (
|
|
|
+ call %VSCE_CMD% package --pre-release --no-dependencies --out "opencode-vscode-dev-%TIMESTAMP%.vsix"
|
|
|
+)
|
|
|
+if errorlevel 1 exit /b 1
|
|
|
+
|
|
|
+echo [INFO] Standard variant packaged successfully
|
|
|
+exit /b 0
|
|
|
+
|
|
|
+REM --- Build variant: gui-only ---
|
|
|
+:build_variant_gui_only
|
|
|
+echo [INFO] === Packaging GUI-ONLY variant ===
|
|
|
+
|
|
|
+cd /d "%PLUGIN_DIR%"
|
|
|
+
|
|
|
+REM Always rebuild webgui to pick up source changes
|
|
|
+REM The monorepo uses bun workspaces a deps are already installed at root level
|
|
|
+echo [INFO] Building webgui...
|
|
|
+cd /d "%WEBGUI_DIR%"
|
|
|
+where bun >nul 2>&1
|
|
|
if not errorlevel 1 (
|
|
|
- set "VSCE_CMD=pnpm exec vsce"
|
|
|
+ call bun run build
|
|
|
) else (
|
|
|
- set "VSCE_CMD=npx --yes vsce"
|
|
|
+ call npm run build
|
|
|
)
|
|
|
+cd /d "%PLUGIN_DIR%"
|
|
|
|
|
|
-REM Use package.json version in the output .vsix name.
|
|
|
-set "PLUGIN_VERSION="
|
|
|
-for /f "usebackq delims=" %%V in (`node -p "require('./package.json').version" 2^>nul`) do set "PLUGIN_VERSION=%%V"
|
|
|
-if "%PLUGIN_VERSION%"=="" set "PLUGIN_VERSION=0.0.0"
|
|
|
+if not exist "%WEBGUI_DIST%" (
|
|
|
+ echo [ERROR] webgui-dist not found at %WEBGUI_DIST% after build
|
|
|
+ exit /b 1
|
|
|
+)
|
|
|
|
|
|
-set "VSIX_NAME=opencode-vscode-%PLUGIN_VERSION%-dev.vsix"
|
|
|
-if "%BUILD_TYPE%"=="production" set "VSIX_NAME=opencode-vscode-%PLUGIN_VERSION%.vsix"
|
|
|
+REM Copy webgui-dist into plugin resources for embedding
|
|
|
+echo [INFO] Embedding webgui-dist into plugin resources...
|
|
|
+if exist "resources\webgui-app" rmdir /s /q "resources\webgui-app"
|
|
|
+xcopy /s /e /i "%WEBGUI_DIST%" "resources\webgui-app\" >nul
|
|
|
|
|
|
-if "%BUILD_TYPE%"=="production" goto package_production
|
|
|
+REM Move binaries completely outside the plugin tree so vsce cannot bundle them
|
|
|
+set "BIN_STASH=%TEMP%\opencode_bin_stash_%RANDOM%"
|
|
|
+if exist "resources\bin" (
|
|
|
+ mkdir "%BIN_STASH%"
|
|
|
+ move "resources\bin" "%BIN_STASH%\bin" >nul
|
|
|
+)
|
|
|
|
|
|
-call %VSCE_CMD% package --pre-release --no-dependencies --out "%VSIX_NAME%"
|
|
|
-if errorlevel 1 exit /b 1
|
|
|
-goto package_complete
|
|
|
+REM Temporarily swap package.json with gui-only overrides and .vscodeignore
|
|
|
+copy "%PLUGIN_DIR%\package.json" "%PLUGIN_DIR%\package.json.bak" >nul
|
|
|
+copy "%PLUGIN_DIR%\.vscodeignore" "%PLUGIN_DIR%\.vscodeignore.bak" >nul
|
|
|
|
|
|
-:package_production
|
|
|
-call %VSCE_CMD% package --no-dependencies --out "%VSIX_NAME%"
|
|
|
-if errorlevel 1 exit /b 1
|
|
|
+REM Deep-merge gui-only overrides into package.json using PowerShell's built-in JSON support
|
|
|
+powershell -NoProfile -Command "$b=Get-Content 'package.json'|ConvertFrom-Json;$o=Get-Content 'package.gui-only.json'|ConvertFrom-Json;function m($t,$s){foreach($p in $s.PSObject.Properties){$v=$p.Value;if($v-is[array]-and$t.($p.Name)-is[array]){$a=$t.($p.Name);for($i=0;$i-lt$v.Count;$i++){if($i-lt$a.Count-and$v[$i]-is[pscustomobject]){m $a[$i] $v[$i]}else{$a[$i]=$v[$i]}}}elseif($v-is[pscustomobject]-and$t.($p.Name)-is[pscustomobject]){m $t.($p.Name) $v}else{$t|Add-Member -MemberType NoteProperty -Name $p.Name -Value $v -Force}}};m $b $o;$b|ConvertTo-Json -Depth 100|Set-Content 'package.json'"
|
|
|
+if errorlevel 1 (
|
|
|
+ echo [ERROR] Failed to merge gui-only package.json overrides
|
|
|
+ call :gui_only_cleanup
|
|
|
+ exit /b 1
|
|
|
+)
|
|
|
|
|
|
-:package_complete
|
|
|
+REM Swap .vscodeignore
|
|
|
+copy "%PLUGIN_DIR%\.vscodeignore.gui-only" "%PLUGIN_DIR%\.vscodeignore" >nul
|
|
|
|
|
|
-echo [INFO] Build completed successfully!
|
|
|
-endlocal
|
|
|
+REM Package gui-only variant
|
|
|
+if "%BUILD_TYPE%"=="production" (
|
|
|
+ call %VSCE_CMD% package --no-dependencies --out "opencode-vscode-gui-only-%TIMESTAMP%.vsix"
|
|
|
+) else (
|
|
|
+ call %VSCE_CMD% package --pre-release --no-dependencies --out "opencode-vscode-gui-only-dev-%TIMESTAMP%.vsix"
|
|
|
+)
|
|
|
+set "PACKAGE_RESULT=%ERRORLEVEL%"
|
|
|
+
|
|
|
+REM Restore originals
|
|
|
+call :gui_only_cleanup
|
|
|
+
|
|
|
+if "%PACKAGE_RESULT%"=="1" exit /b 1
|
|
|
+
|
|
|
+echo [INFO] GUI-only variant packaged successfully
|
|
|
+exit /b 0
|
|
|
+
|
|
|
+REM --- Cleanup helper for gui-only ---
|
|
|
+:gui_only_cleanup
|
|
|
+cd /d "%PLUGIN_DIR%"
|
|
|
+if exist "package.json.bak" (
|
|
|
+ move /y "package.json.bak" "package.json" >nul
|
|
|
+)
|
|
|
+if exist ".vscodeignore.bak" (
|
|
|
+ move /y ".vscodeignore.bak" ".vscodeignore" >nul
|
|
|
+)
|
|
|
+if exist "%BIN_STASH%\bin" (
|
|
|
+ if exist "resources\bin" rmdir /s /q "resources\bin"
|
|
|
+ move "%BIN_STASH%\bin" "resources\bin" >nul
|
|
|
+)
|
|
|
+if exist "%BIN_STASH%" rmdir /s /q "%BIN_STASH%"
|
|
|
+if exist "resources\webgui-app" rmdir /s /q "resources\webgui-app"
|
|
|
+exit /b 0
|