This commit is contained in:
64
main.ts
64
main.ts
@@ -30,18 +30,14 @@ import packageJson from './package.json';
|
|||||||
|
|
||||||
program
|
program
|
||||||
.name('generate-clean-arch')
|
.name('generate-clean-arch')
|
||||||
.description('Generador de código Angular con Clean Architecture desde OpenAPI/Swagger')
|
.description('Angular Clean Architecture code generator from OpenAPI/Swagger')
|
||||||
.version(packageJson.version)
|
.version(packageJson.version)
|
||||||
.option('-i, --input <file>', 'Archivo OpenAPI/Swagger (yaml o json)', 'swagger.yaml')
|
.option('-i, --input <file>', 'OpenAPI/Swagger file (yaml or json)', 'swagger.yaml')
|
||||||
.option('-o, --output <dir>', 'Directorio de salida', './src/app')
|
.option('-o, --output <dir>', 'Output directory', './src/app')
|
||||||
.option(
|
.option('-t, --templates <dir>', 'Custom templates directory', path.join(__dirname, 'templates'))
|
||||||
'-t, --templates <dir>',
|
.option('--skip-install', 'Skip dependency installation')
|
||||||
'Directorio de templates personalizados',
|
.option('--dry-run', 'Simulate without generating files')
|
||||||
path.join(__dirname, 'templates')
|
.option('-s, --select-endpoints', 'Interactively select which tags and endpoints to generate')
|
||||||
)
|
|
||||||
.option('--skip-install', 'No instalar dependencias')
|
|
||||||
.option('--dry-run', 'Simular sin generar archivos')
|
|
||||||
.option('-s, --select-endpoints', 'Seleccionar interactivamente qué tags y endpoints generar')
|
|
||||||
.parse(process.argv);
|
.parse(process.argv);
|
||||||
|
|
||||||
const options = program.opts<CliOptions>();
|
const options = program.opts<CliOptions>();
|
||||||
@@ -55,36 +51,36 @@ async function main(): Promise<void> {
|
|||||||
console.log('='.repeat(60) + '\n');
|
console.log('='.repeat(60) + '\n');
|
||||||
|
|
||||||
if (!fs.existsSync(options.input)) {
|
if (!fs.existsSync(options.input)) {
|
||||||
logError(`Archivo no encontrado: ${options.input}`);
|
logError(`File not found: ${options.input}`);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
logInfo(`Archivo de entrada: ${options.input}`);
|
logInfo(`Input file: ${options.input}`);
|
||||||
logInfo(`Directorio de salida: ${options.output}`);
|
logInfo(`Output directory: ${options.output}`);
|
||||||
logInfo(`Templates: ${options.templates}`);
|
logInfo(`Templates: ${options.templates}`);
|
||||||
|
|
||||||
if (options.dryRun) {
|
if (options.dryRun) {
|
||||||
logWarning('Modo DRY RUN - No se generarán archivos');
|
logWarning('DRY RUN mode — no files will be generated');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!checkOpenApiGenerator()) {
|
if (!checkOpenApiGenerator()) {
|
||||||
logWarning('OpenAPI Generator CLI no encontrado');
|
logWarning('OpenAPI Generator CLI not found');
|
||||||
if (!options.skipInstall) {
|
if (!options.skipInstall) {
|
||||||
installOpenApiGenerator();
|
installOpenApiGenerator();
|
||||||
} else {
|
} else {
|
||||||
logError(
|
logError(
|
||||||
'Instala openapi-generator-cli con: npm install -g @openapitools/openapi-generator-cli'
|
'Install openapi-generator-cli with: npm install -g @openapitools/openapi-generator-cli'
|
||||||
);
|
);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logSuccess('OpenAPI Generator CLI encontrado');
|
logSuccess('OpenAPI Generator CLI found');
|
||||||
}
|
}
|
||||||
|
|
||||||
const analysis = analyzeSwagger(options.input);
|
const analysis = analyzeSwagger(options.input);
|
||||||
|
|
||||||
if (options.dryRun) {
|
if (options.dryRun) {
|
||||||
logInfo('Finalizando en modo DRY RUN');
|
logInfo('Finishing in DRY RUN mode');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,19 +106,15 @@ async function main(): Promise<void> {
|
|||||||
const envContent = fs.readFileSync(envFile, 'utf8');
|
const envContent = fs.readFileSync(envFile, 'utf8');
|
||||||
apiKeys = parseApiKeys(envContent);
|
apiKeys = parseApiKeys(envContent);
|
||||||
logSuccess(
|
logSuccess(
|
||||||
`environment.ts encontrado: ${colors.cyan}${path.relative(process.cwd(), envFile)}${colors.reset}`
|
`environment.ts found: ${colors.cyan}${path.relative(process.cwd(), envFile)}${colors.reset}`
|
||||||
);
|
);
|
||||||
if (apiKeys.length > 0) {
|
if (apiKeys.length > 0) {
|
||||||
logInfo(`Claves de API detectadas: ${apiKeys.map((k) => k.key).join(', ')}`);
|
logInfo(`Detected API keys: ${apiKeys.map((k) => k.key).join(', ')}`);
|
||||||
} else {
|
} else {
|
||||||
logWarning(
|
logWarning('No keys containing "api" found in environment.ts. Will be requested manually.');
|
||||||
'No se encontraron claves con "api" en environment.ts. Se solicitará manualmente.'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logWarning(
|
logWarning('No environment.ts found. The key will be requested manually per repository.');
|
||||||
'No se encontró environment.ts. Se solicitará la clave manualmente por repositorio.'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const tagApiKeyMap = await askApiKeysForTags(selectedTags, apiKeys);
|
const tagApiKeyMap = await askApiKeysForTags(selectedTags, apiKeys);
|
||||||
@@ -143,20 +135,20 @@ async function main(): Promise<void> {
|
|||||||
const report = generateReport(options.output, analysis);
|
const report = generateReport(options.output, analysis);
|
||||||
|
|
||||||
console.log('\n' + '='.repeat(60));
|
console.log('\n' + '='.repeat(60));
|
||||||
log(' ✨ Generación completada con éxito', 'green');
|
log(' ✨ Generation completed successfully', 'green');
|
||||||
console.log('='.repeat(60));
|
console.log('='.repeat(60));
|
||||||
console.log(`\n📊 Resumen:`);
|
console.log(`\n📊 Summary:`);
|
||||||
console.log(` - DTOs generados: ${report.structure.dtos}`);
|
console.log(` - DTOs generated: ${report.structure.dtos}`);
|
||||||
console.log(` - Repositories: ${report.structure.repositories}`);
|
console.log(` - Repositories: ${report.structure.repositories}`);
|
||||||
console.log(` - Mappers: ${report.structure.mappers}`);
|
console.log(` - Mappers: ${report.structure.mappers}`);
|
||||||
console.log(` - Use Cases: ${report.structure.useCases}`);
|
console.log(` - Use Cases: ${report.structure.useCases}`);
|
||||||
console.log(` - Providers: ${report.structure.providers}`);
|
console.log(` - Providers: ${report.structure.providers}`);
|
||||||
console.log(`\n📁 Archivos generados en: ${colors.cyan}${options.output}${colors.reset}\n`);
|
console.log(`\n📁 Files generated in: ${colors.cyan}${options.output}${colors.reset}\n`);
|
||||||
}
|
}
|
||||||
|
|
||||||
main().catch((error: unknown) => {
|
main().catch((error: unknown) => {
|
||||||
const err = error as Error;
|
const err = error as Error;
|
||||||
logError(`Error fatal: ${err.message}`);
|
logError(`Fatal error: ${err.message}`);
|
||||||
console.error(error);
|
console.error(error);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user