* feat(infra): backend cookiecutter template with fastapi tortoise * feat(infra): cli cookiecutter template with typer entry point * feat(infra): fullstack cookiecutter template with sveltekit frontend * test(infra): cookiecutter template tests and render fixes * style(infra): ruff cleanup for cookiecutter template tests * style(infra): ruff format cookiecutter template tests * fix(infra): handle use_db no use_auth no in cookiecutter --------- Co-authored-by: opencode-agent <agent@opencode.local>
56 lines
No EOL
1.9 KiB
Python
56 lines
No EOL
1.9 KiB
Python
"""Post-generation hook for the fullstack cookiecutter template.
|
|
|
|
Removes files conditional on ``use_auth`` / ``use_db`` from the backend
|
|
sub-tree (the frontend has no such flags).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import shutil
|
|
from pathlib import Path
|
|
|
|
PROJECT_DIR = Path.cwd()
|
|
|
|
|
|
def _remove(path: str) -> None:
|
|
"""Remove a file or directory relative to the generated project root."""
|
|
p = PROJECT_DIR / path
|
|
if p.is_dir():
|
|
shutil.rmtree(p, ignore_errors=True)
|
|
elif p.exists():
|
|
p.unlink()
|
|
|
|
|
|
def main() -> None:
|
|
use_auth = "{{ cookiecutter.use_auth }}"
|
|
use_db = "{{ cookiecutter.use_db }}"
|
|
pkg = "{{ cookiecutter.project_name }}"
|
|
|
|
if use_auth == "no":
|
|
_remove(f"backend/src/{pkg}/api/v1/routes/auth.py")
|
|
_remove(f"backend/src/{pkg}/services/auth_service.py")
|
|
_remove(f"backend/tests/test_auth.py")
|
|
|
|
if use_db == "no":
|
|
# db is the root cause for the broken-conditional findings: files
|
|
# with unconditional ``from ...db.models.user import User`` must be
|
|
# stripped together with db/, otherwise the generated project
|
|
# fails to import (ImportError/NameError on startup).
|
|
_remove(f"backend/src/{pkg}/db")
|
|
_remove("backend/migrations")
|
|
_remove(f"backend/src/{pkg}/services/user_service.py")
|
|
_remove(f"backend/src/{pkg}/api/v1/routes/users.py")
|
|
_remove(f"backend/src/{pkg}/api/v1/dependencies.py")
|
|
_remove(f"backend/src/{pkg}/schemas/user.py")
|
|
_remove(f"backend/tests/unit/test_user.py")
|
|
_remove(f"backend/tests/unit/test_user_service.py")
|
|
_remove(f"backend/tests/api/test_users.py")
|
|
if use_auth == "yes":
|
|
# auth_service imports User; strip it and its wiring too.
|
|
_remove(f"backend/src/{pkg}/api/v1/routes/auth.py")
|
|
_remove(f"backend/src/{pkg}/services/auth_service.py")
|
|
_remove(f"backend/tests/test_auth.py")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main() |