feat: enhance logging and linting functionality with detailed reports
All checks were successful
Lint / lint (pull_request) Successful in 16s

This commit is contained in:
2026-03-26 13:03:10 +01:00
parent b54a94c6d3
commit 79ea7dfc7e
8 changed files with 133 additions and 44 deletions

41
main.ts
View File

@@ -5,7 +5,15 @@ import mustache from 'mustache';
import path from 'path';
import { program } from 'commander';
import { log, logSuccess, logInfo, logWarning, logError, colors } from './src/utils/logger';
import {
log,
logSuccess,
logWarning,
logError,
logDetail,
initGenerationLog,
colors
} from './src/utils/logger';
import { checkOpenApiGenerator, installOpenApiGenerator } from './src/utils/openapi-generator';
import { createDirectoryStructure, cleanup } from './src/utils/filesystem';
import { analyzeSwagger } from './src/swagger/analyzer';
@@ -18,7 +26,7 @@ import { generateReport } from './src/generators/report.generator';
import { lintGeneratedFiles } from './src/generators/lint.generator';
import { findEnvironmentFile, parseApiKeys } from './src/utils/environment-finder';
import { askApiKeysForTags, askSelectionFilter } from './src/utils/prompt';
import type { SelectionFilter } from './src/types';
import type { SelectionFilter, LintResult } from './src/types';
import type { CliOptions } from './src/types';
import packageJson from './package.json';
@@ -52,15 +60,17 @@ async function main(): Promise<void> {
log(' Angular + Clean Architecture Code Generator', 'cyan');
console.log('='.repeat(60) + '\n');
const logPath = path.join(process.cwd(), 'generation.log');
initGenerationLog(logPath);
logDetail('config', `Input: ${options.input}`);
logDetail('config', `Output: ${options.output}`);
logDetail('config', `Templates: ${options.templates}`);
if (!fs.existsSync(options.input)) {
logError(`File not found: ${options.input}`);
process.exit(1);
}
logInfo(`Input file: ${options.input}`);
logInfo(`Output directory: ${options.output}`);
logInfo(`Templates: ${options.templates}`);
if (options.dryRun) {
logWarning('DRY RUN mode — no files will be generated');
}
@@ -82,7 +92,7 @@ async function main(): Promise<void> {
const analysis = analyzeSwagger(options.input);
if (options.dryRun) {
logInfo('Finishing in DRY RUN mode');
logWarning('Finishing in DRY RUN mode');
return;
}
@@ -110,9 +120,7 @@ async function main(): Promise<void> {
logSuccess(
`environment.ts found: ${colors.cyan}${path.relative(process.cwd(), envFile)}${colors.reset}`
);
if (apiKeys.length > 0) {
logInfo(`Detected API keys: ${apiKeys.map((k) => k.key).join(', ')}`);
} else {
if (apiKeys.length === 0) {
logWarning('No keys containing "api" found in environment.ts. Will be requested manually.');
}
} else {
@@ -120,6 +128,9 @@ async function main(): Promise<void> {
}
const tagApiKeyMap = await askApiKeysForTags(selectedTags, apiKeys);
Object.entries(tagApiKeyMap).forEach(([tag, key]) => {
logDetail('config', `API key for "${tag}": environment.${key}.url`);
});
// ──────────────────────────────────────────────────────────────────────────
const tempDir = generateCode(options.input, options.templates);
@@ -134,11 +145,13 @@ async function main(): Promise<void> {
);
cleanup(tempDir);
if (!options.skipLint) {
lintGeneratedFiles(options.output);
}
const noLintResult: LintResult = {
prettier: { ran: false, filesFormatted: 0 },
eslint: { ran: false, filesFixed: 0 }
};
const lintResult = options.skipLint ? noLintResult : lintGeneratedFiles(options.output);
const report = generateReport(options.output, analysis);
const report = generateReport(options.output, analysis, lintResult);
console.log('\n' + '='.repeat(60));
log(' ✨ Generation completed successfully', 'green');