.PHONY: all build test clean backend frontend run dev

all: build

build: frontend-build backend-build

backend-build:
	cd backend && go build -o ../bin/markdown-editor-backend

frontend-build:
	cd frontend && npm run build
	@mkdir -p backend/static
	@cp -r frontend/dist/* backend/static/
	@ln -sf backend/static static

test: backend-test frontend-test

backend-test:
	cd backend && go test ./... -v

frontend-test:
	cd frontend && npm test

dev:
	@echo "Starting development servers..."
	@echo "Backend will run on http://127.0.0.1:8080"
	@make -j2 dev-backend dev-frontend

dev-backend:
	cd backend && go run main.go --data-dir=./data

dev-frontend:
	cd frontend && npm run dev

run: build
	./bin/markdown-editor-backend --data-dir=./data

clean:
	rm -rf bin/
	rm -rf backend/static/
	rm -rf frontend/dist/
