MCPcopy Create free account
hub / github.com/code-pushup/cli / persistReport

Function persistReport

packages/core/src/lib/implementation/persist.ts:20–64  ·  view source on GitHub ↗
(
  report: Report,
  sortedScoredReport: ScoredReport,
  options: Required<Omit<PersistConfig, 'skipReports'>>,
)

Source from the content-addressed store, hash-verified

18};
19
20export async function persistReport(
21 report: Report,
22 sortedScoredReport: ScoredReport,
23 options: Required<Omit<PersistConfig, 'skipReports'>>,
24): Promise<FileSize[]> {
25 const { outputDir, filename, format } = options;
26
27 // format report
28 const results = format.map(
29 (reportType): { format: Format; content: string } => {
30 switch (reportType) {
31 case 'json':
32 return {
33 format: 'json',
34 content: JSON.stringify(report, null, 2),
35 };
36 case 'md':
37 return {
38 format: 'md',
39 content: generateMdReport(sortedScoredReport, { outputDir }),
40 };
41 }
42 },
43 );
44
45 if (!(await directoryExists(outputDir))) {
46 try {
47 await mkdir(outputDir, { recursive: true });
48 } catch (error) {
49 throw new Error(
50 `Failed to create output directory in ${ansis.bold(outputDir)} - ${stringifyError(error)}`,
51 );
52 }
53 }
54
55 // write relevant format outputs to file system
56 return Promise.all(
57 results.map(result =>
58 persistResult(
59 createReportPath({ outputDir, filename, format: result.format }),
60 result.content,
61 ),
62 ),
63 );
64}
65
66function persistResult(reportPath: string, content: string): Promise<FileSize> {
67 return (

Callers 2

collectAndPersistReportsFunction · 0.85

Calls 6

generateMdReportFunction · 0.90
directoryExistsFunction · 0.90
stringifyErrorFunction · 0.90
createReportPathFunction · 0.90
mkdirFunction · 0.85
persistResultFunction · 0.85

Tested by

no test coverage detected