This commit is contained in:
parent
8dbfaae1b6
commit
59e0ee33a5
2 changed files with 27 additions and 15 deletions
11
run.bat
11
run.bat
|
@ -42,21 +42,12 @@ exit /b 1
|
||||||
rem Use the current directory where the script is executed
|
rem Use the current directory where the script is executed
|
||||||
pushd %~dp0
|
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
|
rem Always delete and rebuild the binary
|
||||||
echo Cleaning previous build...
|
echo Cleaning previous build...
|
||||||
if exist "%BUILD_OUTPUT%" del "%BUILD_OUTPUT%"
|
if exist "%BUILD_OUTPUT%" del "%BUILD_OUTPUT%"
|
||||||
|
|
||||||
echo Building application...
|
echo Building application...
|
||||||
go build -o "%BUILD_OUTPUT%" !GO_FILES!
|
go build -ldflags="-s -w" -o "%BUILD_OUTPUT%" .
|
||||||
if errorlevel 1 (
|
if errorlevel 1 (
|
||||||
echo Build failed!
|
echo Build failed!
|
||||||
exit /b 1
|
exit /b 1
|
||||||
|
|
31
run.sh
31
run.sh
|
@ -5,6 +5,8 @@ SKIP_CONFIG=""
|
||||||
PORT=""
|
PORT=""
|
||||||
DOMAIN=""
|
DOMAIN=""
|
||||||
CONFIG_FILE=""
|
CONFIG_FILE=""
|
||||||
|
BUILD_ONLY=0
|
||||||
|
PLATFORM="linux"
|
||||||
BUILD_OUTPUT="qgato"
|
BUILD_OUTPUT="qgato"
|
||||||
|
|
||||||
# Parse arguments
|
# Parse arguments
|
||||||
|
@ -22,6 +24,14 @@ while [ $# -gt 0 ]; do
|
||||||
CONFIG_FILE=$2
|
CONFIG_FILE=$2
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
|
--platform)
|
||||||
|
PLATFORM=$2
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
--build-only)
|
||||||
|
BUILD_ONLY=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
--skip-config-check)
|
--skip-config-check)
|
||||||
SKIP_CONFIG="--skip-config-check"
|
SKIP_CONFIG="--skip-config-check"
|
||||||
shift
|
shift
|
||||||
|
@ -36,15 +46,21 @@ done
|
||||||
# Get the directory of the script
|
# Get the directory of the script
|
||||||
SCRIPT_DIR=$(dirname "$0")
|
SCRIPT_DIR=$(dirname "$0")
|
||||||
|
|
||||||
# List all Go files in the script directory (excluding test files)
|
# Set GOOS and output filename
|
||||||
GO_FILES=$(find "$SCRIPT_DIR" -name '*.go' ! -name '*_test.go' -print)
|
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..."
|
echo "Cleaning previous build..."
|
||||||
rm -f "$SCRIPT_DIR/$BUILD_OUTPUT"
|
rm -f "$SCRIPT_DIR/$BUILD_OUTPUT"
|
||||||
|
|
||||||
echo "Building application..."
|
echo "Building application for $PLATFORM..."
|
||||||
go build -o "$SCRIPT_DIR/$BUILD_OUTPUT" $GO_FILES
|
GOOS=$GOOS go build -ldflags="-s -w" -o "$SCRIPT_DIR/$BUILD_OUTPUT" .
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
echo "Build successful! Output: $SCRIPT_DIR/$BUILD_OUTPUT"
|
echo "Build successful! Output: $SCRIPT_DIR/$BUILD_OUTPUT"
|
||||||
else
|
else
|
||||||
|
@ -52,6 +68,11 @@ else
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Skip execution if build-only
|
||||||
|
if [ "$BUILD_ONLY" -eq 1 ]; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
# Construct the run command
|
# Construct the run command
|
||||||
CMD="$SCRIPT_DIR/$BUILD_OUTPUT $SKIP_CONFIG"
|
CMD="$SCRIPT_DIR/$BUILD_OUTPUT $SKIP_CONFIG"
|
||||||
[ -n "$PORT" ] && CMD="$CMD --port $PORT"
|
[ -n "$PORT" ] && CMD="$CMD --port $PORT"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue