chore: add makefile integration and documentation

Signed-off-by: Tobias O <tobias.olenyi@envipath.com>
This commit is contained in:
2025-10-03 14:06:25 +13:00
parent b7e4abae1c
commit d8dc9598ff
2 changed files with 13 additions and 70 deletions

View File

@ -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 help: ## Show this help message
@echo 'Usage: make [target]' @echo 'Usage: make [target]'
@ -20,10 +20,15 @@ db-down: ## Stop PostgreSQL database
@echo "Stopping PostgreSQL database..." @echo "Stopping PostgreSQL database..."
@docker compose down @docker compose down
js-deps: ## Install Frontenddependencies js-deps: ## Install frontend dependencies
@echo "Installing frontend dependencies..." @echo "Installing frontend dependencies..."
@pnpm install @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 migrate: ## Run database migrations
@echo "Running migrations..." @echo "Running migrations..."
@uv run python manage.py migrate @uv run python manage.py migrate
@ -40,9 +45,14 @@ bootstrap: ## Bootstrap initial data (anonymous user, packages, models)
@echo " Email: admin@envipath.com" @echo " Email: admin@envipath.com"
@echo " Password: SuperSafe" @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 @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 shell: ## Open Django shell
@uv run python manage.py shell @uv run python manage.py shell

View File

@ -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)