File size: 1,239 Bytes
71b4454
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from __future__ import annotations

import json
import logging
from pathlib import Path
from typing import Any

logger = logging.getLogger("generator.project")

ROOT = Path(__file__).resolve().parents[2]
GENERATED_ROOT = ROOT / "generated_projects"


class ProjectGenerator:
    async def generate_from_template(
        self,
        project_id: str,
        template: str,
    ) -> dict[str, Any]:
        if not project_id or not project_id.strip():
            raise ValueError("project_id is required")

        if not template or not template.strip():
            raise ValueError("template is required")

        project_root = GENERATED_ROOT / project_id
        project_root.mkdir(parents=True, exist_ok=True)

        metadata = {
            "project_id": project_id,
            "template": template,
            "project_root": str(project_root),
            "status": "generated",
        }

        (project_root / "project.json").write_text(
            json.dumps(metadata, indent=2),
            encoding="utf-8",
        )

        logger.info(
            "Generated project %s from template %s",
            project_id,
            template,
        )

        return metadata


project_generator = ProjectGenerator()