diff --git a/Makefile b/Makefile index 7ef06f0..320f71b 100644 --- a/Makefile +++ b/Makefile @@ -3,4 +3,4 @@ test: npm run build - npx nestarch generate --path ./example/project --output diagram.puml + npx nestarch generate --path ./test/fixtures/simple-app --output diagram.puml diff --git a/src/commands/generate/index.ts b/src/commands/generate/index.ts index dc5d0a6..24c359d 100644 --- a/src/commands/generate/index.ts +++ b/src/commands/generate/index.ts @@ -1,6 +1,7 @@ import { Command, Flags } from '@oclif/core'; import { parseModules } from '../../utils/parser.js'; +import * as fs from 'fs'; export default class Generate extends Command { static description = 'Genera un diagramma UML dei moduli NestJS'; @@ -28,7 +29,14 @@ export default class Generate extends Command { } const uml = this.generatePlantUML(modules); - this.log((`Diagramma UML generato:\n\n${uml}`)); + // Se รจ stato specificato un file di output, lo salviamo + if (flags.output) { + fs.writeFileSync(flags.output, uml); + this.log(`Diagramma salvato in: ${flags.output}`); + } else { + // Altrimenti, stampa sulla console + this.log(uml); + } } generatePlantUML(modules: { name: string; imports: string[] }[]): string { diff --git a/src/utils/parser.ts b/src/utils/parser.ts index 9eb9404..7a0987c 100644 --- a/src/utils/parser.ts +++ b/src/utils/parser.ts @@ -12,6 +12,12 @@ export function parseModules(path: string): ModuleInfo[] { // Aggiunge tutti i file con estensione .module.ts nella directory specificata project.addSourceFilesAtPaths(`${path}/**/*.module.ts`); + project.getSourceFiles().forEach((sourceFile) => { + if (sourceFile.getFilePath().includes('node_modules')) { + sourceFile.delete(); + } + }); + // Analizza ogni file trovato const modules: ModuleInfo[] = project.getSourceFiles().map((sourceFile) => extractModuleInfo(sourceFile)); @@ -22,6 +28,7 @@ function extractModuleInfo(sourceFile: SourceFile): ModuleInfo { // Nome del modulo (nome del file senza estensione) const name = sourceFile.getBaseNameWithoutExtension(); + console.log(name); // Trova tutte le dichiarazioni di import nel file const imports = sourceFile .getImportDeclarations()