.PHONY: install frontend dev serve test lint build docker docker-up docker-test clean

# A workspace outside the repository, so the explorer and file pickers show your
# graphs and data rather than the source tree (as in the devcontainer).
WORKSPACE ?= $(HOME)/noodlelab-workspace

install:            ## Python env (with dev tools and the science pack) + frontend deps
	uv sync --all-extras
	cd frontend && npm install

frontend:           ## Build the editor into src/noodlelab/static
	cd frontend && npm run build

serve:              ## Run the server (serves the built editor)
	mkdir -p $(WORKSPACE) && uv run noodlelab serve $(WORKSPACE)

dev:                ## API on :8000 plus Vite with hot reload on :5173
	mkdir -p $(WORKSPACE) && uv run noodlelab serve $(WORKSPACE) --no-browser & cd frontend && npm run dev

test:
	uv run pytest -q

lint:
	uv run ruff check . && uv run ruff format --check .
	cd frontend && npm run typecheck

build: frontend     ## Wheel + sdist with the editor included
	uv build

# The version as hatch-vcs gives it: v0.1.1 builds 0.1.1, later commits 0.1.2.devN+g<sha>.
VERSION = $(shell uvx --quiet --from setuptools-scm python -m setuptools_scm 2>/dev/null || echo 0.0.0)

docker:
	docker build -t noodlelab --build-arg NOODLELAB_VERSION=$(VERSION) .

docker-up:          ## Build and start docker-compose.yml, versioned from the git tag
	NOODLELAB_VERSION=$(VERSION) docker compose up -d --build

docker-test:        ## tsc + vite build + pytest inside a container with Python and Node
	docker build -f Dockerfile.test -t noodlelab:test .
	docker run --rm noodlelab:test

clean:
	rm -rf dist .pytest_cache .ruff_cache src/noodlelab/static/assets src/noodlelab/static/index.html src/noodlelab/static/admin.html
