-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathcollect-and-persist.ts
More file actions
60 lines (53 loc) · 1.58 KB
/
collect-and-persist.ts
File metadata and controls
60 lines (53 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import {
type CoreConfig,
type PersistConfig,
pluginReportSchema,
} from '@code-pushup/models';
import {
isVerbose,
logStdoutSummary,
scoreReport,
sortReport,
ui,
} from '@code-pushup/utils';
import { collect } from './implementation/collect.js';
import {
logPersistedResults,
persistReport,
} from './implementation/persist.js';
import type { GlobalOptions } from './types.js';
export type CollectAndPersistReportsOptions = Pick<
CoreConfig,
'plugins' | 'categories'
> & {
persist: Required<Omit<PersistConfig, 'skipReports'>> &
Pick<PersistConfig, 'skipReports'>;
} & Partial<GlobalOptions>;
export async function collectAndPersistReports(
options: CollectAndPersistReportsOptions,
): Promise<void> {
const logger = ui().logger;
const reportResult = await collect(options);
const sortedScoredReport = sortReport(scoreReport(reportResult));
const { persist } = options;
const { skipReports = false, ...persistOptions } = persist ?? {};
if (skipReports === true) {
logger.info('Skipping saving reports as `persist.skipReports` is true');
} else {
const persistResults = await persistReport(
reportResult,
sortedScoredReport,
persistOptions,
);
if (isVerbose()) {
logPersistedResults(persistResults);
}
}
// terminal output
logStdoutSummary(sortedScoredReport);
// validate report and throw if invalid
reportResult.plugins.forEach(plugin => {
// Running checks after persisting helps while debugging as you can check the invalid output after the error is thrown
pluginReportSchema.parse(plugin);
});
}