Skip to content

Commit

Permalink
Introducing idea
Browse files Browse the repository at this point in the history
  • Loading branch information
francescobianco committed Nov 29, 2024
1 parent 7d2acc5 commit 3781938
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 9 additions & 1 deletion src/commands/generate/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions src/utils/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -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()
Expand Down

0 comments on commit 3781938

Please sign in to comment.