From d8dc9598ff8d0bf71c248560e7be6bf61932a522 Mon Sep 17 00:00:00 2001 From: Tobias O Date: Fri, 3 Oct 2025 14:06:25 +1300 Subject: [PATCH] chore: add makefile integration and documentation Signed-off-by: Tobias O --- Makefile | 16 +++++- epdb/management/commands/collectstatic.py | 67 ----------------------- 2 files changed, 13 insertions(+), 70 deletions(-) delete mode 100644 epdb/management/commands/collectstatic.py diff --git a/Makefile b/Makefile index 844b0244..3d0150cf 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: help setup db-up db-down migrate bootstrap dev shell clean +.PHONY: help setup db-up db-down migrate bootstrap build-css collect-static dev shell clean help: ## Show this help message @echo 'Usage: make [target]' @@ -20,10 +20,15 @@ db-down: ## Stop PostgreSQL database @echo "Stopping PostgreSQL database..." @docker compose down -js-deps: ## Install Frontenddependencies +js-deps: ## Install frontend dependencies @echo "Installing frontend dependencies..." @pnpm install +build-css: js-deps ## Build Tailwind CSS for production (minified) + @echo "Building Tailwind CSS..." + @pnpm run build + @echo "✓ CSS built successfully" + migrate: ## Run database migrations @echo "Running migrations..." @uv run python manage.py migrate @@ -40,9 +45,14 @@ bootstrap: ## Bootstrap initial data (anonymous user, packages, models) @echo " Email: admin@envipath.com" @echo " Password: SuperSafe" -dev: db-up js-deps +dev: db-up js-deps ## Start development server with auto CSS watcher @uv run python manage.py runserver +collect-static: build-css ## Build CSS and collect all static files for production + @echo "Collecting static files..." + @uv run python manage.py collectstatic --noinput + @echo "✓ Static files collected successfully" + shell: ## Open Django shell @uv run python manage.py shell diff --git a/epdb/management/commands/collectstatic.py b/epdb/management/commands/collectstatic.py deleted file mode 100644 index 355f4b38..00000000 --- a/epdb/management/commands/collectstatic.py +++ /dev/null @@ -1,67 +0,0 @@ -""" -Custom collectstatic command that automatically builds CSS first. -Overrides Django's default collectstatic to include pnpm build. -""" - -import subprocess -import sys -from pathlib import Path -from django.conf import settings -from django.contrib.staticfiles.management.commands.collectstatic import ( - Command as CollectstaticCommand, -) - - -class Command(CollectstaticCommand): - help = "Collect static files (automatically builds CSS first)" - - def handle(self, *args, **options): - """Build CSS before collecting static files.""" - self.stdout.write(self.style.SUCCESS("Building CSS with pnpm...")) - - try: - # Run pnpm build - result = subprocess.run( - ["pnpm", "run", "build"], - cwd=settings.BASE_DIR, - capture_output=True, - text=True, - timeout=60, # 60 second timeout - ) - - if result.returncode != 0: - self.stdout.write(self.style.ERROR("✗ CSS build failed:")) - self.stdout.write(result.stderr) - sys.exit(1) - - # Verify output.css was created - output_css = Path(settings.BASE_DIR) / "static" / "css" / "output.css" - if not output_css.exists(): - self.stdout.write( - self.style.ERROR("✗ CSS build failed: output.css not generated") - ) - sys.exit(1) - - # Show file size - size_kb = output_css.stat().st_size / 1024 - self.stdout.write( - self.style.SUCCESS(f"✓ CSS built successfully ({size_kb:.1f}KB)\n") - ) - - except FileNotFoundError: - self.stdout.write( - self.style.ERROR( - "✗ Error: pnpm not found. Install pnpm to build CSS.\n" - "See README.md for setup instructions." - ) - ) - sys.exit(1) - except subprocess.TimeoutExpired: - self.stdout.write(self.style.ERROR("✗ CSS build timed out (>60s)")) - sys.exit(1) - except Exception as e: - self.stdout.write(self.style.ERROR(f"✗ CSS build error: {e}")) - sys.exit(1) - - # Run normal collectstatic - super().handle(*args, **options)