From 59e0ee33a52d6a5eb666873ba637bba0de1bb60f Mon Sep 17 00:00:00 2001 From: partisan Date: Sun, 1 Jun 2025 09:54:09 +0200 Subject: [PATCH] FIxed run.sh and run.bat --- run.bat | 11 +---------- run.sh | 31 ++++++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/run.bat b/run.bat index dd485f9..e1bf056 100755 --- a/run.bat +++ b/run.bat @@ -42,21 +42,12 @@ exit /b 1 rem Use the current directory where the script is executed pushd %~dp0 -rem Collect all .go files in the current directory excluding *_test.go -set GO_FILES= -for %%f in (*.go) do ( - echo %%f | findstr "_test.go" >nul - if errorlevel 1 ( - set GO_FILES=!GO_FILES! %%f - ) -) - rem Always delete and rebuild the binary echo Cleaning previous build... if exist "%BUILD_OUTPUT%" del "%BUILD_OUTPUT%" echo Building application... -go build -o "%BUILD_OUTPUT%" !GO_FILES! +go build -ldflags="-s -w" -o "%BUILD_OUTPUT%" . if errorlevel 1 ( echo Build failed! exit /b 1 diff --git a/run.sh b/run.sh index 089e11f..cfdd84a 100755 --- a/run.sh +++ b/run.sh @@ -5,6 +5,8 @@ SKIP_CONFIG="" PORT="" DOMAIN="" CONFIG_FILE="" +BUILD_ONLY=0 +PLATFORM="linux" BUILD_OUTPUT="qgato" # Parse arguments @@ -22,6 +24,14 @@ while [ $# -gt 0 ]; do CONFIG_FILE=$2 shift 2 ;; + --platform) + PLATFORM=$2 + shift 2 + ;; + --build-only) + BUILD_ONLY=1 + shift + ;; --skip-config-check) SKIP_CONFIG="--skip-config-check" shift @@ -36,15 +46,21 @@ done # Get the directory of the script SCRIPT_DIR=$(dirname "$0") -# List all Go files in the script directory (excluding test files) -GO_FILES=$(find "$SCRIPT_DIR" -name '*.go' ! -name '*_test.go' -print) +# Set GOOS and output filename +if [ "$PLATFORM" = "windows" ]; then + GOOS=windows + BUILD_OUTPUT="qgato.exe" +else + GOOS=linux + BUILD_OUTPUT="qgato" +fi -# Always delete and rebuild the binary +# Clean and build echo "Cleaning previous build..." rm -f "$SCRIPT_DIR/$BUILD_OUTPUT" -echo "Building application..." -go build -o "$SCRIPT_DIR/$BUILD_OUTPUT" $GO_FILES +echo "Building application for $PLATFORM..." +GOOS=$GOOS go build -ldflags="-s -w" -o "$SCRIPT_DIR/$BUILD_OUTPUT" . if [ $? -eq 0 ]; then echo "Build successful! Output: $SCRIPT_DIR/$BUILD_OUTPUT" else @@ -52,6 +68,11 @@ else exit 1 fi +# Skip execution if build-only +if [ "$BUILD_ONLY" -eq 1 ]; then + exit 0 +fi + # Construct the run command CMD="$SCRIPT_DIR/$BUILD_OUTPUT $SKIP_CONFIG" [ -n "$PORT" ] && CMD="$CMD --port $PORT"