Skip to content

Commit e13ac97

Browse files
committed
make generators return the generated files
1 parent 467d613 commit e13ac97

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

src/language/commands/GeneratorCommandExecutor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class GeneratorCommandExecutor {
1414
this.serviceRegistry = serviceRegistry
1515
}
1616

17-
async execute (generator: ContextMapperGenerator, args: unknown[], cancelToken: CancellationToken): Promise<string | undefined> {
17+
async execute (generator: ContextMapperGenerator, args: unknown[], cancelToken: CancellationToken): Promise<string[] | undefined> {
1818
const filePath = args[0] as string
1919

2020
const model = await this.extractModel(filePath)

src/language/generators/ContextMapperGenerator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import { ContextMappingModel } from '../generated/ast.js'
22
import { CancellationToken } from 'vscode-languageserver'
33

44
export interface ContextMapperGenerator {
5-
generate(model: ContextMappingModel, filePath: string, args: unknown[], cancelToken: CancellationToken): Promise<string | undefined>
5+
generate(model: ContextMappingModel, filePath: string, args: unknown[], cancelToken: CancellationToken): Promise<string[] | undefined>
66
}

src/language/generators/PlantUMLGenerator.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { ComponentDiagramGenerator } from './plantuml/ComponentDiagramGenerator.
66
import { CancellationToken } from 'vscode-languageserver'
77

88
export class PlantUMLGenerator implements ContextMapperGenerator {
9-
async generate (model: ContextMappingModel, filePath: string, args: unknown[], cancelToken: CancellationToken): Promise<string | undefined> {
9+
async generate (model: ContextMappingModel, filePath: string, args: unknown[], cancelToken: CancellationToken): Promise<string[] | undefined> {
1010
// there must not be any extra spaces especially at the start, since the path will be treated as relative otherwise
1111
const destination = (args[0] as string)?.trim()
1212
if (destination == null || destination === '') {
@@ -23,24 +23,30 @@ export class PlantUMLGenerator implements ContextMapperGenerator {
2323
await fs.promises.mkdir(destination, { recursive: true })
2424
}
2525

26-
await this.generateComponentDiagram(model, destination, fileName)
26+
const diagrams: string[] = []
27+
28+
const componentDiagram = await this.generateComponentDiagram(model, destination, fileName)
29+
if (componentDiagram) {
30+
diagrams.push(componentDiagram)
31+
}
2732

2833
console.log('Successfully generated PlantUML diagrams')
29-
return destination
34+
return diagrams
3035
}
3136

32-
private async generateComponentDiagram (model: ContextMappingModel, destination: string, fileName: string) {
37+
private async generateComponentDiagram (model: ContextMappingModel, destination: string, fileName: string): Promise<string | undefined> {
3338
if (model.contextMap.length === 0) {
3439
return
3540
}
3641

3742
const generator = new ComponentDiagramGenerator()
3843
const diagram = generator.createDiagram(model.contextMap[0])
39-
await this.createFile(destination, fileName, diagram)
44+
return await this.createFile(destination, fileName, diagram)
4045
}
4146

4247
private async createFile (destination: string, fileName: string, content: string) {
4348
const filePath = `${path.join(destination, fileName)}.puml`
4449
await fs.promises.writeFile(filePath, content)
50+
return filePath
4551
}
4652
}

0 commit comments

Comments
 (0)