Files
bj_power/bj_power_mes/build.bat
T

54 lines
1.3 KiB
Batchfile

@echo off
setlocal enabledelayedexpansion
chcp 65001 >nul
set "EXE_NAME=bj_power_mes"
set "OUTPUT_DIR=.\bin"
set "GOOS=windows"
set "GOARCH=amd64"
set "VERSION=dev"
for /f "tokens=*" %%a in ('git rev-parse --short HEAD 2^>nul') do set "COMMIT=%%a"
if not defined COMMIT set "COMMIT=unknown"
for /f "tokens=*" %%a in ('powershell -Command "Get-Date -Format 'yyyy-MM-dd_HH:mm:ss'"') do set "BUILD_TIME=%%a"
set "LDFLAGS=-s -w -H=windowsgui -X main.Version=%VERSION% -X main.Commit=%COMMIT% -X main.BuildTime=%BUILD_TIME%"
set "BUILD_FLAGS=-trimpath"
echo Step 1: Build frontend...
cd frontend
call npm run build
if errorlevel 1 (
echo Frontend build failed
exit /b 1
)
cd ..
echo Step 2: Copy frontend output to public/ ...
if exist "public" rmdir /s /q "public"
mkdir "public"
xcopy "frontend\dist\*" "public\" /E /I /Y >nul 2>&1
echo Step 3: Clean up...
if exist "%OUTPUT_DIR%" rmdir /s /q "%OUTPUT_DIR%"
if not exist "%OUTPUT_DIR%" mkdir "%OUTPUT_DIR%"
echo Step 4: Build Go binary...
set "CGO_ENABLED=0"
go build %BUILD_FLAGS% -ldflags "%LDFLAGS%" -o "%OUTPUT_DIR%\%EXE_NAME%.exe" .
if errorlevel 1 (
echo Go build failed
exit /b 1
)
echo Step 5: Copy config files...
xcopy ".\etc" "%OUTPUT_DIR%\etc" /I /Y >nul 2>&1
if errorlevel 1 (
echo Copy config files failed
exit /b 1
)
echo Build completed: %OUTPUT_DIR%\%EXE_NAME%.exe
endlocal