(
options: Required<Omit<PersistConfig, 'format'>> & {
format: T;
},
)
| 15 | type LoadedReportFormat<T extends Format> = T extends 'json' ? Report : string; |
| 16 | |
| 17 | export async function loadReport<T extends Format>( |
| 18 | options: Required<Omit<PersistConfig, 'format'>> & { |
| 19 | format: T; |
| 20 | }, |
| 21 | ): Promise<LoadedReportFormat<T>> { |
| 22 | const { outputDir, filename, format } = options; |
| 23 | await ensureDirectoryExists(outputDir); |
| 24 | const filePath = path.join(outputDir, `${filename}.${format}`); |
| 25 | |
| 26 | if (format === 'json') { |
| 27 | const content = await readJsonFile(filePath); |
| 28 | const report: Report = validate(reportSchema, content); |
| 29 | return report as LoadedReportFormat<T>; |
| 30 | } |
| 31 | |
| 32 | const text: string = await readTextFile(filePath); |
| 33 | return text as LoadedReportFormat<T>; |
| 34 | } |
no test coverage detected