import { Logger } from '../logger/logger' ; import { ReporterFactory , CombinedReportParameters } from 'accessibility-insights-report' ; import * as fs from 'fs' ; import { inject , injectable } from 'inversify' ; import { iocTypes } from '../ioc/ioc-types' ; import { TaskConfig } from '../task-config' ; @ injectable ( ) export class ConsolidatedReportGenerator { constructor ( @ inject ( iocTypes . TaskConfig ) private readonly taskConfig , @ inject ( iocTypes . ReportFactory ) private readonly reporterFactoryFunc , @ inject ( Logger ) private readonly logger , private readonly fileSystemObj = fs ) { } public generateReport ( combinedReportData ) { const reporter = this . reporterFactoryFunc ( ) ; const htmlReportContent = reporter . fromCombinedResults ( combinedReportData ) . asHTML ( ) ; const outDirectory = this . taskConfig . getReportOutDir ( ) ; const reportFileName = `${ outDirectory }/index.html` ; if ( ! this . fileSystemObj . existsSync ( outDirectory ) ) { this . logger . logInfo ( `Report output directory does not exists. Creating directory ${ outDirectory }` ) ; this . fileSystemObj . mkdirSync ( outDirectory ) ; } this . saveHtmlReport ( reportFileName , htmlReportContent ) ; return reportFileName ; } private saveHtmlReport ( fileName , content ) { this . fileSystemObj . writeFileSync ( fileName , content ) ; this . logger . logInfo ( `Scan report saved successfully as ${ fileName }` ) ; } }