Skip to content

Commit

Permalink
feat: Write JSON report to the new file.
Browse files Browse the repository at this point in the history
  • Loading branch information
adelkahomolova committed Aug 29, 2019
1 parent 3142f0f commit fe4fb26
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/reporters/IReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '../model';

export interface IReporter {
report(practicesAndComponents: PracticeAndComponent[]): string | JSONReport;
report(practicesAndComponents: PracticeAndComponent[]): string | Promise<JSONReport>;
}

export type JSONReport = { uri: string; components: ComponentReport[] };
Expand Down
15 changes: 13 additions & 2 deletions src/reporters/JSONReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<JSONReport> {
const report: JSONReport = {
uri: this.argumentsProvider.uri,
components: [],
Expand All @@ -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));
}
}

0 comments on commit fe4fb26

Please sign in to comment.