({
project,
type,
files,
settings: { directory },
}: {
project: Pick<ProjectConfig, 'name'> | null;
type: OutputType;
files: T;
settings: Pick<Settings, 'directory'>;
})
| 11 | type OutputType = 'current' | 'previous' | 'comparison'; |
| 12 | |
| 13 | export async function saveOutputFiles<T extends Partial<OutputFiles>>({ |
| 14 | project, |
| 15 | type, |
| 16 | files, |
| 17 | settings: { directory }, |
| 18 | }: { |
| 19 | project: Pick<ProjectConfig, 'name'> | null; |
| 20 | type: OutputType; |
| 21 | files: T; |
| 22 | settings: Pick<Settings, 'directory'>; |
| 23 | }): Promise<T> { |
| 24 | const baseDir = project ? path.join(BASE_DIR, project.name) : BASE_DIR; |
| 25 | const outputDir = path.join(directory, baseDir, `.${type}`); |
| 26 | const name = |
| 27 | type === 'comparison' |
| 28 | ? `${DEFAULT_PERSIST_FILENAME}-diff` |
| 29 | : DEFAULT_PERSIST_FILENAME; |
| 30 | |
| 31 | const formats = objectToKeys(files) as Format[]; |
| 32 | const outputs = objectFromEntries( |
| 33 | formats.map(format => [ |
| 34 | format, |
| 35 | path.join(outputDir, `${name}.${format.toString()}`), |
| 36 | ]), |
| 37 | ); |
| 38 | |
| 39 | if (formats.length > 0) { |
| 40 | await mkdir(outputDir, { recursive: true }); |
| 41 | } |
| 42 | |
| 43 | await Promise.all( |
| 44 | formats.map(async format => { |
| 45 | // eslint-disable-next-line @typescript-eslint/no-non-null-assertion |
| 46 | const src = files[format]!; |
| 47 | const dest = outputs[format]; |
| 48 | await copyFile(src, dest); |
| 49 | logDebug(`Copied ${type} report from ${src} to ${dest}`); |
| 50 | }), |
| 51 | ); |
| 52 | |
| 53 | return outputs as T; |
| 54 | } |
no test coverage detected