-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathconfig.ts
More file actions
71 lines (63 loc) · 2.07 KB
/
config.ts
File metadata and controls
71 lines (63 loc) · 2.07 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
61
62
63
64
65
66
67
68
69
70
71
import * as path from 'node:path';
import type { PersistConfig, UploadConfig } from '@code-pushup/models';
import type { NormalizedExecutorContext } from './context.js';
import { parseEnv } from './env.js';
import type {
BaseNormalizedExecutorContext,
GlobalExecutorOptions,
ProjectExecutorOnlyOptions,
} from './types.js';
export function globalConfig(
options: Partial<GlobalExecutorOptions & Record<string, unknown>>,
context: BaseNormalizedExecutorContext,
): GlobalExecutorOptions {
const { projectConfig } = context;
const { root: projectRoot = '' } = projectConfig ?? {};
const { verbose, config, command } = options;
return {
command,
verbose: !!verbose,
config: config ?? path.join(projectRoot, 'code-pushup.config.ts'),
};
}
export function persistConfig(
options: Partial<PersistConfig & ProjectExecutorOnlyOptions>,
context: BaseNormalizedExecutorContext,
): Partial<PersistConfig> {
const { projectConfig, workspaceRoot } = context;
const { name: projectName = '' } = projectConfig ?? {};
const {
format,
outputDir = path.join(workspaceRoot, '.code-pushup', projectName), // always in <root>/.code-pushup/<project-name>,
filename,
} = options;
return {
outputDir,
...(format ? { format } : {}),
...(filename ? { filename } : {}),
};
}
export function uploadConfig(
options: Partial<UploadConfig & ProjectExecutorOnlyOptions>,
context: NormalizedExecutorContext,
): Partial<UploadConfig> {
const { workspaceRoot, projectName } = context;
const { projectPrefix, server, apiKey, organization, project, timeout } =
options;
const applyPrefix = workspaceRoot !== '.';
const prefix = projectPrefix && applyPrefix ? `${projectPrefix}-` : '';
const derivedProject =
projectName && !project ? `${prefix}${projectName}` : project;
return {
...parseEnv(process.env),
...Object.fromEntries(
Object.entries({
server,
apiKey,
organization,
...(derivedProject ? { project: derivedProject } : {}),
timeout,
}).filter(([_, v]) => v !== undefined),
),
};
}