diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6bf63b2 --- /dev/null +++ b/Makefile @@ -0,0 +1,40 @@ +.PHONY: build-wasm build-native build-server clean update-cache + +# Build WASM Client mit Cache-Version Update +build-wasm: update-cache + @echo "๐Ÿ”จ Building WASM Client..." + cd cmd/client && GOOS=js GOARCH=wasm go build -o web/main.wasm + @echo "โœ… WASM build complete: cmd/client/web/main.wasm" + +# Update Cache-Version vor dem Build +update-cache: + @echo "๐Ÿ”„ Updating cache version..." + @./scripts/cache-version.sh + +# Build Native Client +build-native: + @echo "๐Ÿ”จ Building Native Client..." + cd cmd/client && go build -o ../../build/client + @echo "โœ… Native client build complete: build/client" + +# Build Server +build-server: + @echo "๐Ÿ”จ Building Server..." + cd cmd/server && go build -o ../../build/server + @echo "โœ… Server build complete: build/server" + +# Build All +build-all: build-wasm build-native build-server + +# Clean build artifacts +clean: + @echo "๐Ÿงน Cleaning build artifacts..." + rm -f cmd/client/web/main.wasm + rm -rf build/ + @echo "โœ… Clean complete" + +# Development: Build WASM and run local server +dev: build-wasm + @echo "๐Ÿš€ Starting development server..." + @echo "Open http://localhost:8080 in your browser" + cd cmd/client/web && python3 -m http.server 8080 diff --git a/scripts/cache-version.sh b/scripts/cache-version.sh new file mode 100755 index 0000000..5e4f1d0 --- /dev/null +++ b/scripts/cache-version.sh @@ -0,0 +1,21 @@ +#!/bin/bash +# Generiert eine Cache-Version basierend auf aktuellem Timestamp + +VERSION=$(date +%s%3N) # Unix timestamp in Millisekunden +JS_FILE="cmd/client/web/game.js" +HTML_FILE="cmd/client/web/index.html" + +echo "๐Ÿ”„ Updating cache version to: $VERSION" + +# Ersetze CACHE_VERSION in game.js und BUILD_VERSION in index.html +if [[ "$OSTYPE" == "darwin"* ]]; then + # macOS + sed -i '' "s/const CACHE_VERSION = .*;/const CACHE_VERSION = $VERSION;/" "$JS_FILE" + sed -i '' "s/const BUILD_VERSION = .*;/const BUILD_VERSION = $VERSION;/" "$HTML_FILE" +else + # Linux + sed -i "s/const CACHE_VERSION = .*;/const CACHE_VERSION = $VERSION;/" "$JS_FILE" + sed -i "s/const BUILD_VERSION = .*;/const BUILD_VERSION = $VERSION;/" "$HTML_FILE" +fi + +echo "โœ… Cache version updated: $JS_FILE and $HTML_FILE"