build: add Sense Windows package script (#37)
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
@echo off
|
||||
setlocal
|
||||
|
||||
for %%I in ("%~dp0..") do set "SENSE_ROOT=%%~fI"
|
||||
for %%I in ("%SENSE_ROOT%\dist") do set "OUTPUT_ROOT=%%~fI"
|
||||
for %%I in ("%OUTPUT_ROOT%\sense-windows-amd64") do set "PACKAGE_DIR=%%~fI"
|
||||
for %%I in ("%OUTPUT_ROOT%\sense-windows-amd64.zip") do set "ZIP_PATH=%%~fI"
|
||||
for %%I in ("%SENSE_ROOT%\ui\dist") do set "UI_DIST=%%~fI"
|
||||
|
||||
if /I not "%PACKAGE_DIR%"=="%SENSE_ROOT%\dist\sense-windows-amd64" (
|
||||
echo [ERROR] Unsafe package directory: %PACKAGE_DIR%
|
||||
exit /b 1
|
||||
)
|
||||
if /I not "%ZIP_PATH%"=="%SENSE_ROOT%\dist\sense-windows-amd64.zip" (
|
||||
echo [ERROR] Unsafe ZIP path: %ZIP_PATH%
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
where go >nul 2>nul || goto :missing_go
|
||||
for /f "tokens=3" %%V in ('go version') do set "GO_VERSION=%%V"
|
||||
if not "%GO_VERSION%"=="go1.26.5" (
|
||||
echo [ERROR] Go 1.26.5 is required, found %GO_VERSION%.
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
where node >nul 2>nul || goto :missing_node
|
||||
for /f "delims=" %%V in ('node --version') do set "NODE_VERSION=%%V"
|
||||
if not "%NODE_VERSION%"=="v22.22.1" (
|
||||
echo [ERROR] Node.js 22.22.1 is required, found %NODE_VERSION%.
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
where corepack >nul 2>nul || goto :missing_corepack
|
||||
for /f "delims=" %%V in ('corepack pnpm@9.15.1 --version') do set "PNPM_VERSION=%%V"
|
||||
if not "%PNPM_VERSION%"=="9.15.1" (
|
||||
echo [ERROR] pnpm 9.15.1 is required, found %PNPM_VERSION%.
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo [1/5] Installing frozen frontend dependencies...
|
||||
pushd "%SENSE_ROOT%\ui" || goto :failed
|
||||
call corepack pnpm@9.15.1 install --frozen-lockfile || goto :failed_popd
|
||||
|
||||
echo [2/5] Building frontend...
|
||||
call corepack pnpm@9.15.1 build || goto :failed_popd
|
||||
popd
|
||||
|
||||
if exist "%PACKAGE_DIR%" rmdir /s /q "%PACKAGE_DIR%"
|
||||
if exist "%ZIP_PATH%" del /q "%ZIP_PATH%"
|
||||
mkdir "%PACKAGE_DIR%\config" || goto :failed
|
||||
|
||||
echo [3/5] Building Windows backend...
|
||||
set "CGO_ENABLED=0"
|
||||
set "GOOS=windows"
|
||||
set "GOARCH=amd64"
|
||||
pushd "%SENSE_ROOT%\server" || goto :failed
|
||||
go build -trimpath -ldflags "-s -w" -o "%PACKAGE_DIR%\sense-server.exe" . || goto :failed_popd
|
||||
popd
|
||||
|
||||
echo [4/5] Assembling package...
|
||||
robocopy "%UI_DIST%" "%PACKAGE_DIR%\ui" /E /NFL /NDL /NJH /NJS /NP >nul
|
||||
if errorlevel 8 goto :failed
|
||||
robocopy "%SENSE_ROOT%\LICENSES" "%PACKAGE_DIR%\LICENSES" /E /NFL /NDL /NJH /NJS /NP >nul
|
||||
if errorlevel 8 goto :failed
|
||||
copy /y "%SENSE_ROOT%\config\sense.env.example" "%PACKAGE_DIR%\config\sense.env.example" >nul || goto :failed
|
||||
copy /y "%SENSE_ROOT%\scripts\runtime\start-sense.bat" "%PACKAGE_DIR%\start-sense.bat" >nul || goto :failed
|
||||
copy /y "%SENSE_ROOT%\scripts\runtime\README-WINDOWS.md" "%PACKAGE_DIR%\README-WINDOWS.md" >nul || goto :failed
|
||||
|
||||
echo [5/5] Creating ZIP...
|
||||
powershell -NoProfile -ExecutionPolicy Bypass -Command "Compress-Archive -Path '%PACKAGE_DIR%' -DestinationPath '%ZIP_PATH%' -Force" || goto :failed
|
||||
|
||||
echo.
|
||||
echo Package directory: %PACKAGE_DIR%
|
||||
echo ZIP archive: %ZIP_PATH%
|
||||
exit /b 0
|
||||
|
||||
:failed_popd
|
||||
popd
|
||||
:failed
|
||||
echo [ERROR] Packaging failed.
|
||||
exit /b 1
|
||||
|
||||
:missing_go
|
||||
echo [ERROR] Go was not found in PATH.
|
||||
exit /b 1
|
||||
|
||||
:missing_node
|
||||
echo [ERROR] Node.js was not found in PATH.
|
||||
exit /b 1
|
||||
|
||||
:missing_corepack
|
||||
echo [ERROR] Corepack was not found in PATH.
|
||||
exit /b 1
|
||||
Reference in New Issue
Block a user