-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathcode-pushup.preset.ts
201 lines (191 loc) · 4.73 KB
/
code-pushup.preset.ts
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
import type {
CategoryConfig,
CoreConfig,
} from './packages/models/src/index.js';
import coveragePlugin, {
getNxCoveragePaths,
} from './packages/plugin-coverage/src/index.js';
import eslintPlugin, {
eslintConfigFromAllNxProjects,
eslintConfigFromNxProject,
} from './packages/plugin-eslint/src/index.js';
import jsPackagesPlugin from './packages/plugin-js-packages/src/index.js';
import jsDocsPlugin, {
JsDocsPluginConfig,
} from './packages/plugin-jsdocs/src/index.js';
import {
PLUGIN_SLUG,
groups,
} from './packages/plugin-jsdocs/src/lib/constants.js';
import { filterGroupsByOnlyAudits } from './packages/plugin-jsdocs/src/lib/utils.js';
import lighthousePlugin, {
lighthouseGroupRef,
} from './packages/plugin-lighthouse/src/index.js';
export const jsPackagesCategories: CategoryConfig[] = [
{
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 const lighthouseCategories: CategoryConfig[] = [
{
slug: 'performance',
title: 'Performance',
refs: [lighthouseGroupRef('performance')],
},
{
slug: 'a11y',
title: 'Accessibility',
refs: [lighthouseGroupRef('accessibility')],
},
{
slug: 'best-practices',
title: 'Best Practices',
refs: [lighthouseGroupRef('best-practices')],
},
{
slug: 'seo',
title: 'SEO',
refs: [lighthouseGroupRef('seo')],
},
];
export const eslintCategories: CategoryConfig[] = [
{
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 function getJsDocsCategories(
config: JsDocsPluginConfig,
): CategoryConfig[] {
return [
{
slug: 'docs',
title: 'Documentation',
description: 'Measures how much of your code is **documented**.',
refs: filterGroupsByOnlyAudits(groups, config).map(group => ({
weight: 1,
type: 'group',
plugin: PLUGIN_SLUG,
slug: group.slug,
})),
},
];
}
export const coverageCategories: CategoryConfig[] = [
{
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 const jsPackagesCoreConfig = async (): Promise<CoreConfig> => {
return {
plugins: [await jsPackagesPlugin()],
categories: jsPackagesCategories,
};
};
export const lighthouseCoreConfig = async (
url: string,
): Promise<CoreConfig> => {
return {
plugins: [await lighthousePlugin(url)],
categories: lighthouseCategories,
};
};
export const jsDocsCoreConfig = (
config: JsDocsPluginConfig | string[],
): CoreConfig => {
return {
plugins: [
jsDocsPlugin(Array.isArray(config) ? { patterns: config } : config),
],
categories: getJsDocsCategories(
Array.isArray(config) ? { patterns: config } : config,
),
};
};
export const eslintCoreConfigNx = async (
projectName?: string,
): Promise<CoreConfig> => {
return {
plugins: [
await eslintPlugin(
await (projectName
? eslintConfigFromNxProject(projectName)
: eslintConfigFromAllNxProjects()),
),
],
categories: eslintCategories,
};
};
export const coverageCoreConfigNx = async (
projectName?: string,
): Promise<CoreConfig> => {
if (projectName) {
throw new Error('coverageCoreConfigNx for single projects not implemented');
}
const targetNames = ['unit-test', 'integration-test'];
const targetArgs = [
'-t',
'unit-test',
'integration-test',
'--coverage.enabled',
'--skipNxCache',
];
return {
plugins: [
await coveragePlugin({
coverageToolCommand: {
command: 'npx',
args: [
'nx',
projectName ? `run --project ${projectName}` : 'run-many',
...targetArgs,
],
},
reports: await getNxCoveragePaths(targetNames),
}),
],
categories: coverageCategories,
};
};