feat: Implement Clean Architecture code generation with Mustache templates

- Added `clean-arch.generator.ts` for generating models, mappers, repositories, use cases, and providers based on OpenAPI specs.
- Introduced `dto.generator.ts` to invoke `openapi-generator-cli` for generating DTOs and organizing them.
- Created `report.generator.ts` to generate a JSON report of the generation process.
- Implemented `analyzer.ts` for parsing OpenAPI/Swagger files and extracting relevant data.
- Defined new types in `cli.types.ts`, `generation.types.ts`, `openapi.types.ts`, and `swagger.types.ts` for better type safety.
- Added utility functions in `filesystem.ts` for creating directory structures and cleaning up temporary files.
- Developed logging utilities in `logger.ts` for better console output.
- Included OpenAPI generator checks and installation in `openapi-generator.ts`.
- Added type mapping utility in `type-mapper.ts` for converting OpenAPI types to TypeScript types.
- Updated `package.json` scripts to lint all TypeScript files.
- Modified `tsconfig.json` to include all TypeScript files in the project.
This commit is contained in:
didavila
2026-03-24 11:16:45 +01:00
parent 8854bc5217
commit bd67e6c6d1
16 changed files with 684 additions and 651 deletions

31
src/swagger/analyzer.ts Normal file
View File

@@ -0,0 +1,31 @@
import fs from 'fs-extra';
import yaml from 'js-yaml';
import { logStep, logInfo, logError } from '../utils/logger';
import type { SwaggerAnalysis } from '../types';
/** Parsea un archivo OpenAPI/Swagger y extrae tags, paths y el documento completo. */
export function analyzeSwagger(swaggerFile: string): SwaggerAnalysis {
logStep('Analizando archivo OpenAPI...');
try {
const fileContent = fs.readFileSync(swaggerFile, 'utf8');
const swagger = yaml.load(fileContent) as Record<string, unknown>;
const tags = Array.isArray(swagger.tags) ? swagger.tags : [];
const paths = (swagger.paths as Record<string, unknown>) || {};
logInfo(`Encontrados ${tags.length} tags en el API`);
logInfo(`Encontrados ${Object.keys(paths).length} endpoints`);
tags.forEach((tag: unknown) => {
const t = tag as { name: string; description?: string };
logInfo(` - ${t.name}: ${t.description || 'Sin descripción'}`);
});
return { tags, paths, swagger };
} catch (error: unknown) {
const err = error as Error;
logError(`Error al leer el archivo Swagger: ${err.message}`);
process.exit(1);
}
}