Merge remote-tracking branch 'origin/main'
All checks were successful
Lint / lint (pull_request) Successful in 20s
All checks were successful
Lint / lint (pull_request) Successful in 20s
# Conflicts: # main.ts
This commit is contained in:
54
main.ts
54
main.ts
@@ -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';
|
||||
@@ -25,7 +33,7 @@ import {
|
||||
deriveSelectionFilter,
|
||||
deriveTagApiKeyMap
|
||||
} from './src/utils/config';
|
||||
import type { SelectionFilter } from './src/types';
|
||||
import type { SelectionFilter, LintResult } from './src/types';
|
||||
import type { CliOptions } from './src/types';
|
||||
import packageJson from './package.json';
|
||||
|
||||
@@ -61,6 +69,9 @@ 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);
|
||||
|
||||
// ── CONFIG FILE: override CLI defaults with config values ─────────────────
|
||||
const configFile = options.config;
|
||||
const generationConfig = configFile ? loadConfig(configFile) : undefined;
|
||||
@@ -72,18 +83,18 @@ async function main(): Promise<void> {
|
||||
if (generationConfig.skipInstall !== undefined)
|
||||
options.skipInstall = generationConfig.skipInstall;
|
||||
if (generationConfig.skipLint !== undefined) options.skipLint = generationConfig.skipLint;
|
||||
logInfo(`Using configuration file: ${configFile}`);
|
||||
logDetail('config', `Using configuration file: ${configFile}`);
|
||||
}
|
||||
|
||||
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');
|
||||
}
|
||||
@@ -120,12 +131,15 @@ async function main(): Promise<void> {
|
||||
|
||||
writeConfig(defaultConfig, outputFile);
|
||||
logSuccess(`Configuration file generated: ${outputFile}`);
|
||||
logInfo('Edit the file to customise tags, endpoints and baseUrls, then run with --config');
|
||||
logDetail(
|
||||
'config',
|
||||
'Edit the file to customise tags, endpoints and baseUrls, then run with --config'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (options.dryRun) {
|
||||
logInfo('Finishing in DRY RUN mode');
|
||||
logWarning('Finishing in DRY RUN mode');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -139,7 +153,10 @@ async function main(): Promise<void> {
|
||||
// Config-driven: derive everything from the JSON file
|
||||
selectionFilter = deriveSelectionFilter(generationConfig);
|
||||
tagApiKeyMap = deriveTagApiKeyMap(generationConfig);
|
||||
logInfo(`Tags from config: ${Object.keys(generationConfig.tags).join(', ')}`);
|
||||
logDetail('config', `Tags from config: ${Object.keys(generationConfig.tags).join(', ')}`);
|
||||
Object.entries(tagApiKeyMap).forEach(([tag, key]) => {
|
||||
logDetail('config', `API key for "${tag}": environment.${key}.url`);
|
||||
});
|
||||
} else {
|
||||
// Interactive mode (original behaviour)
|
||||
if (options.selectEndpoints) {
|
||||
@@ -160,9 +177,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 {
|
||||
@@ -170,6 +185,9 @@ async function main(): Promise<void> {
|
||||
}
|
||||
|
||||
tagApiKeyMap = await askApiKeysForTags(selectedTags, apiKeys);
|
||||
Object.entries(tagApiKeyMap).forEach(([tag, key]) => {
|
||||
logDetail('config', `API key for "${tag}": environment.${key}.url`);
|
||||
});
|
||||
}
|
||||
|
||||
// ──────────────────────────────────────────────────────────────────────────
|
||||
@@ -186,11 +204,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');
|
||||
|
||||
Reference in New Issue
Block a user