|
| 1 | +@echo off |
| 2 | + |
| 3 | +rem 1) Ensure the current directory has go.mod |
| 4 | +if not exist "go.mod" ( |
| 5 | + echo Error: failed to find go.mod file in current directory. |
| 6 | + echo To set up the go-webui module, use this script in a module directory. |
| 7 | + exit /b 1 |
| 8 | +) |
| 9 | + |
| 10 | +rem 2) Run go commands |
| 11 | +go mod tidy |
| 12 | +go get github.com/webui-dev/go-webui/v2@main |
| 13 | +go get github.com/webui-dev/webui@main >NUL 2>&1 |
| 14 | + |
| 15 | +rem 3) Retrieve GOPATH (use environment variable if defined, otherwise go env) |
| 16 | +if defined GOPATH ( |
| 17 | + set "go_path=%GOPATH%" |
| 18 | +) else ( |
| 19 | + for /f "delims=" %%I in ('go env GOPATH') do ( |
| 20 | + set "go_path=%%I" |
| 21 | + ) |
| 22 | +) |
| 23 | + |
| 24 | +rem 4) Parse the first matching version lines from go.sum |
| 25 | +rem For go-webui/v2: |
| 26 | +set "go_webui_full_version=" |
| 27 | +for /f "tokens=2" %%I in ('type go.sum ^| findstr /i "github.com/webui-dev/go-webui/v2"') do ( |
| 28 | + if not defined go_webui_full_version ( |
| 29 | + set "go_webui_full_version=%%I" |
| 30 | + ) |
| 31 | +) |
| 32 | + |
| 33 | +rem For webui: |
| 34 | +set "webui_full_version=" |
| 35 | +for /f "tokens=2" %%I in ('type go.sum ^| findstr /i "github.com/webui-dev/webui"') do ( |
| 36 | + if not defined webui_full_version ( |
| 37 | + set "webui_full_version=%%I" |
| 38 | + ) |
| 39 | +) |
| 40 | + |
| 41 | +rem 5) Construct paths based on the parsed versions |
| 42 | +set "go_webui_path=%go_path%\pkg\mod\github.com\webui-dev\go-webui\v2@%go_webui_full_version%" |
| 43 | +set "webui_path=%go_path%\pkg\mod\github.com\webui-dev\webui@%webui_full_version%" |
| 44 | + |
| 45 | +rem 6) Validate that these paths actually exist |
| 46 | +set "has_error=false" |
| 47 | +if not exist "%go_webui_path%\" ( |
| 48 | + echo Failed to find go-webui in "%go_webui_path%" |
| 49 | + set "has_error=true" |
| 50 | +) |
| 51 | +if not exist "%webui_path%\" ( |
| 52 | + echo Failed to find webui in "%webui_path%" |
| 53 | + set "has_error=true" |
| 54 | +) |
| 55 | + |
| 56 | +if "%has_error%"=="true" ( |
| 57 | + exit /b 1 |
| 58 | +) |
| 59 | + |
| 60 | +rem 7) If a "webui" directory or link already exists in the go_webui_path, do nothing |
| 61 | +if exist "%go_webui_path%\webui\" ( |
| 62 | + exit /b 0 |
| 63 | +) |
| 64 | + |
| 65 | +rem 8) Create a directory symlink for the webui folder |
| 66 | +rem (Requires Administrator privileges or Developer Mode) |
| 67 | +echo Creating symlink: %go_webui_path%\webui -> %webui_path% |
| 68 | +mklink /D "%go_webui_path%\webui" "%webui_path%" |
| 69 | +if errorlevel 1 ( |
| 70 | + echo mklink failed. Run as Administrator if needed. |
| 71 | + exit /b 1 |
| 72 | +) |
| 73 | + |
| 74 | +rem 9) Final tidy |
| 75 | +go mod tidy |
| 76 | + |
| 77 | +exit /b 0 |
0 commit comments