from pathlib import Path from typing import Any, Dict, Optional class ConfigGenerator: TEMPLATES = { "node": { "name": "my-node-project", "version": "1.0.0", "description": "A Node.js project", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "start": "node index.js", "build": "echo \"No build step required\"", "lint": "eslint .", }, "keywords": [], "author": "", "license": "MIT", "devDependencies": {}, "dependencies": {}, }, "python": { "tool": { "poetry": { "name": "my-python-project", "version": "1.0.0", "description": "A Python project", "authors": [], "license": "MIT", }, "pytest": { "testpaths": ["tests"], "python_files": ["test_*.py"], "python_classes": ["Test*"], "python_functions": ["test_*"], }, }, "build-system": { "requires": ["poetry-core>=1.0.0"], "build-backend": "poetry.core.masonry.api", }, }, "typescript": { "name": "my-ts-project", "version": "1.0.0", "main": "dist/index.js", "types": "dist/index.d.ts", "scripts": { "build": "tsc", "test": "jest", "lint": "eslint src --ext .ts", "dev": "ts-node src/index.ts", }, "compilerOptions": { "target": "ES2020", "module": "commonjs", "lib": ["ES2020"], "outDir": "./dist", "rootDir": "./src", "strict": True, "esModuleInterop": True, "skipLibCheck": True, "forceConsistentCasingInFileNames": True, "declaration": True, "declarationMap": True, "sourceMap": True, }, "include": ["src/**/*"], "exclude": ["node_modules", "dist"], }, } def detect_project_type(self, path: Path) -> Optional[str]: for item in path.iterdir(): if item.is_file(): if item.name == "package.json": return "node" elif item.name == "pyproject.toml": return "python" elif item.name == "tsconfig.json": return "typescript" elif item.name == "requirements.txt": return "python" elif item.name == "Cargo.toml": return "rust" if (path / "src").exists() and (path / "src").is_dir(): for item in (path / "src").iterdir(): if item.suffix == ".ts": return "typescript" elif item.suffix == ".py": return "python" return None def generate_from_template(self, template_type: str, path: Path) -> Dict[str, Any]: template = self.TEMPLATES.get(template_type) if template: return template.copy() raise ValueError(f"Unknown template type: {template_type}") def analyze_project(self, path: Path) -> Dict[str, Any]: project_type = self.detect_project_type(path) return { "type": project_type, "files": [f.name for f in path.rglob("*") if f.is_file()], }