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:
32
src/generators/report.generator.ts
Normal file
32
src/generators/report.generator.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import fs from 'fs-extra';
|
||||
import path from 'path';
|
||||
import { logStep, logSuccess } from '../utils/logger';
|
||||
import type { SwaggerAnalysis, GenerationReport } from '../types';
|
||||
|
||||
/** Genera y persiste el reporte `generation-report.json` con las estadísticas del proceso. */
|
||||
export function generateReport(outputDir: string, analysis: SwaggerAnalysis): GenerationReport {
|
||||
logStep('Generando reporte de generación...');
|
||||
|
||||
const report: GenerationReport = {
|
||||
timestamp: new Date().toISOString(),
|
||||
tags: analysis.tags.length,
|
||||
endpoints: Object.keys(analysis.paths).length,
|
||||
outputDirectory: outputDir,
|
||||
structure: {
|
||||
dtos: fs.readdirSync(path.join(outputDir, 'data/dtos')).length,
|
||||
repositories: fs.readdirSync(path.join(outputDir, 'data/repositories')).length,
|
||||
mappers: fs.readdirSync(path.join(outputDir, 'data/mappers')).length,
|
||||
useCases: fs.readdirSync(path.join(outputDir, 'domain/use-cases')).length,
|
||||
providers:
|
||||
fs.readdirSync(path.join(outputDir, 'di/repositories')).length +
|
||||
fs.readdirSync(path.join(outputDir, 'di/use-cases')).length
|
||||
}
|
||||
};
|
||||
|
||||
const reportPath = path.join(process.cwd(), 'generation-report.json');
|
||||
fs.writeJsonSync(reportPath, report, { spaces: 2 });
|
||||
|
||||
logSuccess(`Reporte guardado en: ${reportPath}`);
|
||||
|
||||
return report;
|
||||
}
|
||||
Reference in New Issue
Block a user