From fe4fb26c9da3bca52ad1b7d3c8dfc484188d1542 Mon Sep 17 00:00:00 2001 From: Adela Homolova Date: Thu, 29 Aug 2019 18:26:48 +0200 Subject: [PATCH] feat: Write JSON report to the new file. --- src/reporters/IReporter.ts | 2 +- src/reporters/JSONReporter.ts | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/reporters/IReporter.ts b/src/reporters/IReporter.ts index f539eea22..a7bccad6a 100644 --- a/src/reporters/IReporter.ts +++ b/src/reporters/IReporter.ts @@ -8,7 +8,7 @@ import { } from '../model'; export interface IReporter { - report(practicesAndComponents: PracticeAndComponent[]): string | JSONReport; + report(practicesAndComponents: PracticeAndComponent[]): string | Promise; } export type JSONReport = { uri: string; components: ComponentReport[] }; diff --git a/src/reporters/JSONReporter.ts b/src/reporters/JSONReporter.ts index cbab3eca8..b7017e5ab 100644 --- a/src/reporters/JSONReporter.ts +++ b/src/reporters/JSONReporter.ts @@ -4,16 +4,22 @@ import { injectable, inject } from 'inversify'; import { Types } from '../types'; import { ArgumentsProvider } from '../inversify.config'; import _ from 'lodash'; +import { FileSystemService } from '../services/FileSystemService'; @injectable() export class JSONReporter implements IReporter { private readonly argumentsProvider: ArgumentsProvider; + private readonly fileSystemService: FileSystemService; - constructor(@inject(Types.ArgumentsProvider) argumentsProvider: ArgumentsProvider) { + constructor( + @inject(Types.ArgumentsProvider) argumentsProvider: ArgumentsProvider, + @inject(FileSystemService) fileSystemService: FileSystemService, + ) { this.argumentsProvider = argumentsProvider; + this.fileSystemService = fileSystemService; } - report(practicesAndComponents: PracticeAndComponent[]): JSONReport { + async report(practicesAndComponents: PracticeAndComponent[]): Promise { const report: JSONReport = { uri: this.argumentsProvider.uri, components: [], @@ -29,7 +35,12 @@ export class JSONReporter implements IReporter { } component.practices.push(pac.practice); } + await this.reportInFile(report); return report; } + + async reportInFile(report: JSONReport) { + await this.fileSystemService.writeFile(`${process.cwd()}/dxScannerOutput.json`, JSON.stringify(report, null, 4)); + } }