11import { mkdir , stat , writeFile } from 'node:fs/promises' ;
2- import path from 'node:path' ;
3- import type { PersistConfig , Report } from '@code-pushup/models' ;
2+ import type { Format , PersistConfig , Report } from '@code-pushup/models' ;
43import {
54 type MultipleFileResults ,
65 type ScoredReport ,
6+ createReportPath ,
77 directoryExists ,
88 generateMdReport ,
99 logMultipleFileResults ,
@@ -30,20 +30,22 @@ export async function persistReport(
3030 const { outputDir, filename, format } = options ;
3131
3232 // collect physical format outputs
33- const results = format . map ( reportType => {
34- switch ( reportType ) {
35- case 'json' :
36- return {
37- format : 'json' ,
38- content : JSON . stringify ( report , null , 2 ) ,
39- } ;
40- case 'md' :
41- return {
42- format : 'md' ,
43- content : generateMdReport ( sortedScoredReport , { outputDir } ) ,
44- } ;
45- }
46- } ) ;
33+ const results = format . map (
34+ ( reportType ) : { format : Format ; content : string } => {
35+ switch ( reportType ) {
36+ case 'json' :
37+ return {
38+ format : 'json' ,
39+ content : JSON . stringify ( report , null , 2 ) ,
40+ } ;
41+ case 'md' :
42+ return {
43+ format : 'md' ,
44+ content : generateMdReport ( sortedScoredReport , { outputDir } ) ,
45+ } ;
46+ }
47+ } ,
48+ ) ;
4749
4850 if ( ! ( await directoryExists ( outputDir ) ) ) {
4951 try {
@@ -58,7 +60,7 @@ export async function persistReport(
5860 return Promise . allSettled (
5961 results . map ( result =>
6062 persistResult (
61- path . join ( outputDir , ` ${ filename } . ${ result . format } ` ) ,
63+ createReportPath ( { outputDir, filename, format : result . format } ) ,
6264 result . content ,
6365 ) ,
6466 ) ,
0 commit comments