-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathcollect.ts
More file actions
46 lines (44 loc) · 1.4 KB
/
collect.ts
File metadata and controls
46 lines (44 loc) · 1.4 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
import { createRequire } from 'node:module';
import {
type CoreConfig,
DEFAULT_PERSIST_OUTPUT_DIR,
type PersistConfig,
type Report,
} from '@code-pushup/models';
import { calcDuration, getLatestCommit } from '@code-pushup/utils';
import type { GlobalOptions } from '../types.js';
import { executePlugins } from './execute-plugin.js';
export type CollectOptions = Pick<CoreConfig, 'plugins' | 'categories'> & {
persist?: Required<Pick<PersistConfig, 'outputDir'>>;
} & Partial<GlobalOptions>;
/**
* Run audits, collect plugin output and aggregate it into a JSON object
* @param options
*/
export async function collect(options: CollectOptions): Promise<Report> {
const { plugins, categories, persist, ...otherOptions } = options;
const date = new Date().toISOString();
const start = performance.now();
const commit = await getLatestCommit();
const pluginOutputs = await executePlugins(
{
plugins,
persist: { outputDir: DEFAULT_PERSIST_OUTPUT_DIR, ...persist },
// implement together with CLI option
cache: { read: false, write: false },
},
otherOptions,
);
const packageJson = createRequire(import.meta.url)(
'../../../package.json',
) as typeof import('../../../package.json');
return {
commit,
packageName: packageJson.name,
version: packageJson.version,
date,
duration: calcDuration(start),
categories,
plugins: pluginOutputs,
};
}