配置文件、打包工具(windows)
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/cmd/server/dist/
|
||||
130
cmd/server/build.bat
Normal file
130
cmd/server/build.bat
Normal file
@@ -0,0 +1,130 @@
|
||||
@echo off
|
||||
chcp 65001 >nul
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
:: =============================================
|
||||
:: Project Build Script - Fixed Encoding Version
|
||||
:: =============================================
|
||||
|
||||
:: Project name
|
||||
set PROJECT=xk-websocket
|
||||
|
||||
:: Fix Windows time format
|
||||
set HOUR=%time:~0,2%
|
||||
if "%HOUR:~0,1%"==" " set HOUR=0%HOUR:~1,1%
|
||||
set MIN=%time:~3,2%
|
||||
set SEC=%time:~6,2%
|
||||
|
||||
:: Create timestamp
|
||||
set DATE_STAMP=%date:~0,4%-%date:~5,2%-%date:~8,2%
|
||||
set TIME_STAMP=%HOUR%-%MIN%-%SEC%
|
||||
set TIMESTAMP=%DATE_STAMP%_%TIME_STAMP%
|
||||
|
||||
:: Target directory
|
||||
set DIST_DIR=dist
|
||||
|
||||
echo.
|
||||
echo [1/5] Preparing build environment...
|
||||
if not exist "%DIST_DIR%" (
|
||||
mkdir "%DIST_DIR%"
|
||||
echo Directory created: %DIST_DIR%
|
||||
) else (
|
||||
echo Directory exists: %DIST_DIR%
|
||||
)
|
||||
|
||||
echo.
|
||||
echo [2/5] Setting build info...
|
||||
echo Project name: %PROJECT%
|
||||
echo Build time: %TIMESTAMP%
|
||||
|
||||
echo.
|
||||
echo [3/5] Building Linux version...
|
||||
set GOOS=linux
|
||||
set GOARCH=amd64
|
||||
|
||||
:: Check if Go files exist in current directory
|
||||
dir *.go >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
echo ERROR: No Go files found in current directory!
|
||||
echo Please run this script in the directory containing .go files
|
||||
echo.
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
go build -o "%DIST_DIR%\%PROJECT%-linux-%TIMESTAMP%"
|
||||
if %errorlevel% neq 0 (
|
||||
echo.
|
||||
echo ERROR: Linux build failed! Error code: %errorlevel%
|
||||
echo Possible reasons:
|
||||
echo - Go environment not properly installed
|
||||
echo - Compilation errors in code
|
||||
echo - Dependency download failed
|
||||
echo - Insufficient disk space
|
||||
echo.
|
||||
echo Please check the above issues and try again...
|
||||
echo.
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo.
|
||||
echo [4/5] Building Windows version...
|
||||
set GOOS=windows
|
||||
set GOARCH=amd64
|
||||
go build -o "%DIST_DIR%\%PROJECT%-windows-%TIMESTAMP%.exe"
|
||||
if %errorlevel% neq 0 (
|
||||
echo.
|
||||
echo ERROR: Windows build failed! Error code: %errorlevel%
|
||||
echo.
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo.
|
||||
echo [5/5] Build successful!
|
||||
echo.
|
||||
echo Output directory: %cd%\%DIST_DIR%\
|
||||
echo Generated files:
|
||||
echo 1. %PROJECT%-linux-%TIMESTAMP%
|
||||
echo 2. %PROJECT%-windows-%TIMESTAMP%.exe
|
||||
echo.
|
||||
|
||||
:clean_prompt
|
||||
echo Clean up old build files? [Y/N]
|
||||
set /p CLEAN_OLD=
|
||||
if /i "%CLEAN_OLD%"=="Y" (
|
||||
call :clean_old_builds
|
||||
goto :run_instructions
|
||||
)
|
||||
if /i "%CLEAN_OLD%"=="N" (
|
||||
goto :run_instructions
|
||||
)
|
||||
echo Please enter Y or N
|
||||
goto :clean_prompt
|
||||
|
||||
:clean_old_builds
|
||||
echo.
|
||||
echo Cleaning old build files...
|
||||
for %%f in ("%DIST_DIR%\%PROJECT%-*") do (
|
||||
if not "%%~nxf"=="%PROJECT%-linux-%TIMESTAMP%" (
|
||||
if not "%%~nxf"=="%PROJECT%-windows-%TIMESTAMP%.exe" (
|
||||
echo Deleting: %%f
|
||||
del /q "%%f"
|
||||
)
|
||||
)
|
||||
)
|
||||
echo Cleanup complete! Kept latest build files.
|
||||
goto :eof
|
||||
|
||||
:run_instructions
|
||||
echo.
|
||||
echo Run instructions:
|
||||
echo Linux: .\%DIST_DIR%\%PROJECT%-linux-%TIMESTAMP% --nodeId=node1 --port=12081
|
||||
echo Windows: .\%DIST_DIR%\%PROJECT%-windows-%TIMESTAMP%.exe --nodeId=win1 --port=12080
|
||||
echo.
|
||||
|
||||
echo Press any key to exit...
|
||||
pause >nul
|
||||
|
||||
endlocal
|
||||
Reference in New Issue
Block a user