-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathcode-pushup.preset.ts
More file actions
246 lines (238 loc) · 6.57 KB
/
code-pushup.preset.ts
File metadata and controls
246 lines (238 loc) · 6.57 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/* eslint-disable @nx/enforce-module-boundaries */
import { createProjectGraphAsync } from '@nx/devkit';
import type { CoreConfig, PluginUrls } from './packages/models/src/index.js';
import axePlugin, {
type AxePluginOptions,
axeGroupRefs,
} from './packages/plugin-axe/src/index.js';
import coveragePlugin, {
type CoveragePluginConfig,
getNxCoveragePaths,
} from './packages/plugin-coverage/src/index.js';
import eslintPlugin, {
eslintConfigFromAllNxProjects,
} from './packages/plugin-eslint/src/index.js';
import jsPackagesPlugin from './packages/plugin-js-packages/src/index.js';
import jsDocsPlugin from './packages/plugin-jsdocs/src/index.js';
import {
lighthouseGroupRefs,
lighthousePlugin,
} from './packages/plugin-lighthouse/src/index.js';
import typescriptPlugin, {
getCategories,
tsconfigFromAllNxProjects,
} from './packages/plugin-typescript/src/index.js';
export function configureUpload(projectName: string = 'workspace'): CoreConfig {
return {
...(process.env['CP_API_KEY'] && {
upload: {
server: 'https://api.staging.code-pushup.dev/graphql',
apiKey: process.env['CP_API_KEY'],
organization: 'code-pushup',
project: `cli-${projectName}`,
},
}),
plugins: [],
};
}
export async function configureEslintPlugin(
projectName?: string,
): Promise<CoreConfig> {
return {
plugins: [
projectName
? await eslintPlugin(
{ eslintrc: `packages/${projectName}/eslint.config.js` },
{
artifacts: {
// We leverage Nx dependsOn to only run all lint targets before we run code-pushup
// generateArtifactsCommand: 'npx nx run-many -t lint',
artifactsPaths: [
`packages/${projectName}/.eslint/eslint-report.json`,
],
},
},
)
: await eslintPlugin(await eslintConfigFromAllNxProjects()),
],
categories: [
{
slug: 'bug-prevention',
title: 'Bug prevention',
description: 'Lint rules that find **potential bugs** in your code.',
refs: [
{ type: 'group', plugin: 'eslint', slug: 'problems', weight: 1 },
],
},
{
slug: 'code-style',
title: 'Code style',
description:
'Lint rules that promote **good practices** and consistency in your code.',
refs: [
{ type: 'group', plugin: 'eslint', slug: 'suggestions', weight: 1 },
],
},
],
};
}
export async function configureCoveragePlugin(
projectName?: string,
): Promise<CoreConfig> {
const targets = ['unit-test', 'int-test'];
const config: CoveragePluginConfig = projectName
? // We do not need to run a coverageToolCommand. This is handled over the Nx task graph.
{
reports: Object.keys(
(await createProjectGraphAsync()).nodes[projectName]?.data.targets ??
{},
)
.filter(target => targets.includes(target))
.map(target => ({
pathToProject: `packages/${projectName}`,
resultsPath: `coverage/${projectName}/${target}s/lcov.info`,
})),
}
: {
reports: await getNxCoveragePaths(targets),
coverageToolCommand: {
command: `npx nx run-many -t ${targets.join(',')}`,
},
};
return {
plugins: [await coveragePlugin(config)],
categories: [
{
slug: 'code-coverage',
title: 'Code coverage',
description: 'Measures how much of your code is **covered by tests**.',
refs: [
{ type: 'group', plugin: 'coverage', slug: 'coverage', weight: 1 },
],
},
],
};
}
export async function configureJsPackagesPlugin(): Promise<CoreConfig> {
return {
plugins: [await jsPackagesPlugin()],
categories: [
{
slug: 'security',
title: 'Security',
description: 'Finds known **vulnerabilities** in 3rd-party packages.',
refs: [
{
type: 'group',
plugin: 'js-packages',
slug: 'npm-audit',
weight: 1,
},
],
},
{
slug: 'updates',
title: 'Updates',
description: 'Finds **outdated** 3rd-party packages.',
refs: [
{
type: 'group',
plugin: 'js-packages',
slug: 'npm-outdated',
weight: 1,
},
],
},
],
};
}
export async function configureTypescriptPlugin(
projectName?: string,
): Promise<CoreConfig> {
const tsconfig = projectName
? `packages/${projectName}/tsconfig.lib.json`
: await tsconfigFromAllNxProjects({
exclude: [
'test-fixtures', // Intentionally incomplete tsconfigs
'models', // Uses ts-patch transformer plugin
],
});
return {
plugins: [typescriptPlugin({ tsconfig })],
categories: getCategories(),
};
}
export function configureJsDocsPlugin(projectName?: string): CoreConfig {
const patterns: string[] = [
`packages/${projectName ?? '*'}/src/**/*.ts`,
`!**/node_modules`,
`!**/{mocks,mock}`,
`!**/*.{spec,test}.ts`,
`!**/implementation/**`,
`!**/internal/**`,
];
return {
plugins: [jsDocsPlugin(patterns)],
categories: [
{
slug: 'docs',
title: 'Documentation',
description: 'Measures how much of your code is **documented**.',
refs: [
{
type: 'group',
plugin: 'jsdocs',
slug: 'documentation-coverage',
weight: 1,
},
],
},
],
};
}
export async function configureLighthousePlugin(
urls: PluginUrls,
): Promise<CoreConfig> {
const lhPlugin = await lighthousePlugin(urls);
return {
plugins: [lhPlugin],
categories: [
{
slug: 'performance',
title: 'Performance',
refs: lighthouseGroupRefs(lhPlugin, 'performance'),
},
{
slug: 'a11y',
title: 'Accessibility',
refs: lighthouseGroupRefs(lhPlugin, 'accessibility'),
},
{
slug: 'best-practices',
title: 'Best Practices',
refs: lighthouseGroupRefs(lhPlugin, 'best-practices'),
},
{
slug: 'seo',
title: 'SEO',
refs: lighthouseGroupRefs(lhPlugin, 'seo'),
},
],
};
}
export function configureAxePlugin(
urls: PluginUrls,
options?: AxePluginOptions,
): CoreConfig {
const axe = axePlugin(urls, options);
return {
plugins: [axe],
categories: [
{
slug: 'axe-a11y',
title: 'Axe Accessibility',
refs: axeGroupRefs(axe),
},
],
};
}