diff --git a/makefile b/makefile index 8f21887..417e25b 100644 --- a/makefile +++ b/makefile @@ -5,6 +5,8 @@ GOFMT = gofmt BACKEND_DIR = backend FRONTEND_DIR = frontend +BACKEND_LOG = backend.log +BACKEND_PORT = 8080 # Update this if needed deps: @echo "Installing Go dependencies..." @@ -18,25 +20,37 @@ build-frontend: @echo "Building the frontend application..." $(GO) build -o $(FRONTEND_DIR)/$(BINARY_NAME) $(FRONTEND_DIR)/widget.go -run-backend: build-backend +build: build-backend build-frontend + +run-backend: @echo "Running the backend server..." - $(BACKEND_DIR)/$(BINARY_NAME) + @$(BACKEND_DIR)/$(BINARY_NAME) > $(BACKEND_LOG) 2>&1 & # Run in background + @echo "Backend started in the background." + +wait-backend: + @echo "Waiting for backend to start..." + @while ! nc -z localhost $(BACKEND_PORT); do sleep 1; done + @echo "Backend is running!" -run-frontend: build-frontend +run-frontend: @echo "Running the frontend application..." - $(FRONTEND_DIR)/$(BINARY_NAME) + @$(FRONTEND_DIR)/$(BINARY_NAME) + +run-all: deps build run-backend wait-backend run-frontend clean: @echo "Cleaning up..." - rm -f $(BACKEND_DIR)/$(BINARY_NAME) $(FRONTEND_DIR)/$(BINARY_NAME) + rm -f $(BACKEND_DIR)/$(BINARY_NAME) $(FRONTEND_DIR)/$(BINARY_NAME) $(BACKEND_LOG) help: @echo "Makefile for Go application" @echo "" @echo "Available targets:" - @echo " build - Build both backend and frontend applications" - @echo " run-backend - Build and run the backend server" - @echo " run-frontend - Build and run the frontend application" - @echo " clean - Remove the generated binaries" - @echo " deps - Install Go dependencies and tidy up" - @echo " help - Show this help message" + @echo " build - Build both backend and frontend applications" + @echo " run-backend - Build and run the backend server" + @echo " wait-backend - Wait until the backend is ready using a real check" + @echo " run-frontend - Build and run the frontend application" + @echo " run-all - Install deps, build everything, then run backend & frontend" + @echo " clean - Remove generated binaries and logs" + @echo " deps - Install Go dependencies and tidy up" + @echo " help - Show this help message"