@code-pushup/create-cli 0.51.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -0
- package/index.js +958 -0
- package/package.json +25 -0
- package/src/index.d.ts +2 -0
- package/src/lib/constants.d.ts +5 -0
- package/src/lib/init.d.ts +3 -0
- package/src/lib/utils.d.ts +15 -0
package/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# @code-pushup/create-cli
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@code-pushup/create-cli)
|
|
4
|
+
[](https://npmtrends.com/@code-pushup/create-cli)
|
|
5
|
+
[](https://www.npmjs.com/package/@code-pushup/create-cli?activeTab=dependencies)
|
|
6
|
+
|
|
7
|
+
A CLI tool to set up Code PushUp in your repository.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
To set up Code PushUp, run the following command:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npx init @code-pushup/cli
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
alternatives:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npx @code-pushup/create-cli
|
|
21
|
+
npm exec @code-pushup/create-cli
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
It should generate the following output:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
> <✓> Generating @code-pushup/nx-plugin:init
|
|
28
|
+
|
|
29
|
+
> <✓> Generating @code-pushup/nx-plugin:configuration
|
|
30
|
+
|
|
31
|
+
CREATE code-pushup.config.ts
|
|
32
|
+
```
|
package/index.js
ADDED
|
@@ -0,0 +1,958 @@
|
|
|
1
|
+
#! /usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// packages/models/src/lib/implementation/schemas.ts
|
|
4
|
+
import { MATERIAL_ICONS } from "vscode-material-icons";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
|
|
7
|
+
// packages/models/src/lib/implementation/limits.ts
|
|
8
|
+
var MAX_SLUG_LENGTH = 128;
|
|
9
|
+
var MAX_TITLE_LENGTH = 256;
|
|
10
|
+
var MAX_DESCRIPTION_LENGTH = 65536;
|
|
11
|
+
var MAX_ISSUE_MESSAGE_LENGTH = 1024;
|
|
12
|
+
|
|
13
|
+
// packages/models/src/lib/implementation/utils.ts
|
|
14
|
+
var slugRegex = /^[a-z\d]+(?:-[a-z\d]+)*$/;
|
|
15
|
+
var filenameRegex = /^(?!.*[ \\/:*?"<>|]).+$/;
|
|
16
|
+
function hasDuplicateStrings(strings) {
|
|
17
|
+
const sortedStrings = [...strings].sort();
|
|
18
|
+
const duplStrings = sortedStrings.filter(
|
|
19
|
+
(item, index) => index !== 0 && item === sortedStrings[index - 1]
|
|
20
|
+
);
|
|
21
|
+
return duplStrings.length === 0 ? false : [...new Set(duplStrings)];
|
|
22
|
+
}
|
|
23
|
+
function hasMissingStrings(toCheck, existing) {
|
|
24
|
+
const nonExisting = toCheck.filter((s) => !existing.includes(s));
|
|
25
|
+
return nonExisting.length === 0 ? false : nonExisting;
|
|
26
|
+
}
|
|
27
|
+
function errorItems(items, transform = (itemArr) => itemArr.join(", ")) {
|
|
28
|
+
return transform(items || []);
|
|
29
|
+
}
|
|
30
|
+
function exists(value) {
|
|
31
|
+
return value != null;
|
|
32
|
+
}
|
|
33
|
+
function getMissingRefsForCategories(categories, plugins) {
|
|
34
|
+
if (categories.length === 0) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
const auditRefsFromCategory = categories.flatMap(
|
|
38
|
+
({ refs }) => refs.filter(({ type }) => type === "audit").map(({ plugin, slug }) => `${plugin}/${slug}`)
|
|
39
|
+
);
|
|
40
|
+
const auditRefsFromPlugins = plugins.flatMap(
|
|
41
|
+
({ audits, slug: pluginSlug }) => audits.map(({ slug }) => `${pluginSlug}/${slug}`)
|
|
42
|
+
);
|
|
43
|
+
const missingAuditRefs = hasMissingStrings(
|
|
44
|
+
auditRefsFromCategory,
|
|
45
|
+
auditRefsFromPlugins
|
|
46
|
+
);
|
|
47
|
+
const groupRefsFromCategory = categories.flatMap(
|
|
48
|
+
({ refs }) => refs.filter(({ type }) => type === "group").map(({ plugin, slug }) => `${plugin}#${slug} (group)`)
|
|
49
|
+
);
|
|
50
|
+
const groupRefsFromPlugins = plugins.flatMap(
|
|
51
|
+
({ groups, slug: pluginSlug }) => Array.isArray(groups) ? groups.map(({ slug }) => `${pluginSlug}#${slug} (group)`) : []
|
|
52
|
+
);
|
|
53
|
+
const missingGroupRefs = hasMissingStrings(
|
|
54
|
+
groupRefsFromCategory,
|
|
55
|
+
groupRefsFromPlugins
|
|
56
|
+
);
|
|
57
|
+
const missingRefs = [missingAuditRefs, missingGroupRefs].filter((refs) => Array.isArray(refs) && refs.length > 0).flat();
|
|
58
|
+
return missingRefs.length > 0 ? missingRefs : false;
|
|
59
|
+
}
|
|
60
|
+
function missingRefsForCategoriesErrorMsg(categories, plugins) {
|
|
61
|
+
const missingRefs = getMissingRefsForCategories(categories, plugins);
|
|
62
|
+
return `The following category references need to point to an audit or group: ${errorItems(
|
|
63
|
+
missingRefs
|
|
64
|
+
)}`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// packages/models/src/lib/implementation/schemas.ts
|
|
68
|
+
var tableCellValueSchema = z.union([z.string(), z.number(), z.boolean(), z.null()]).default(null);
|
|
69
|
+
function executionMetaSchema(options = {
|
|
70
|
+
descriptionDate: "Execution start date and time",
|
|
71
|
+
descriptionDuration: "Execution duration in ms"
|
|
72
|
+
}) {
|
|
73
|
+
return z.object({
|
|
74
|
+
date: z.string({ description: options.descriptionDate }),
|
|
75
|
+
duration: z.number({ description: options.descriptionDuration })
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
var slugSchema = z.string({ description: "Unique ID (human-readable, URL-safe)" }).regex(slugRegex, {
|
|
79
|
+
message: "The slug has to follow the pattern [0-9a-z] followed by multiple optional groups of -[0-9a-z]. e.g. my-slug"
|
|
80
|
+
}).max(MAX_SLUG_LENGTH, {
|
|
81
|
+
message: `slug can be max ${MAX_SLUG_LENGTH} characters long`
|
|
82
|
+
});
|
|
83
|
+
var descriptionSchema = z.string({ description: "Description (markdown)" }).max(MAX_DESCRIPTION_LENGTH).optional();
|
|
84
|
+
var urlSchema = z.string().url();
|
|
85
|
+
var docsUrlSchema = urlSchema.optional().or(z.literal("")).describe("Documentation site");
|
|
86
|
+
var titleSchema = z.string({ description: "Descriptive name" }).max(MAX_TITLE_LENGTH);
|
|
87
|
+
var scoreSchema = z.number({
|
|
88
|
+
description: "Value between 0 and 1"
|
|
89
|
+
}).min(0).max(1);
|
|
90
|
+
function metaSchema(options) {
|
|
91
|
+
const {
|
|
92
|
+
descriptionDescription,
|
|
93
|
+
titleDescription,
|
|
94
|
+
docsUrlDescription,
|
|
95
|
+
description
|
|
96
|
+
} = options ?? {};
|
|
97
|
+
return z.object(
|
|
98
|
+
{
|
|
99
|
+
title: titleDescription ? titleSchema.describe(titleDescription) : titleSchema,
|
|
100
|
+
description: descriptionDescription ? descriptionSchema.describe(descriptionDescription) : descriptionSchema,
|
|
101
|
+
docsUrl: docsUrlDescription ? docsUrlSchema.describe(docsUrlDescription) : docsUrlSchema
|
|
102
|
+
},
|
|
103
|
+
{ description }
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
var filePathSchema = z.string().trim().min(1, { message: "path is invalid" });
|
|
107
|
+
var fileNameSchema = z.string().trim().regex(filenameRegex, {
|
|
108
|
+
message: `The filename has to be valid`
|
|
109
|
+
}).min(1, { message: "file name is invalid" });
|
|
110
|
+
var positiveIntSchema = z.number().int().positive();
|
|
111
|
+
var nonnegativeIntSchema = z.number().int().nonnegative();
|
|
112
|
+
var nonnegativeNumberSchema = z.number().nonnegative();
|
|
113
|
+
function packageVersionSchema(options) {
|
|
114
|
+
const { versionDescription = "NPM version of the package", required } = options ?? {};
|
|
115
|
+
const packageSchema = z.string({ description: "NPM package name" });
|
|
116
|
+
const versionSchema = z.string({ description: versionDescription });
|
|
117
|
+
return z.object(
|
|
118
|
+
{
|
|
119
|
+
packageName: required ? packageSchema : packageSchema.optional(),
|
|
120
|
+
version: required ? versionSchema : versionSchema.optional()
|
|
121
|
+
},
|
|
122
|
+
{ description: "NPM package name and version of a published package" }
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
var weightSchema = nonnegativeNumberSchema.describe(
|
|
126
|
+
"Coefficient for the given score (use weight 0 if only for display)"
|
|
127
|
+
);
|
|
128
|
+
function weightedRefSchema(description, slugDescription) {
|
|
129
|
+
return z.object(
|
|
130
|
+
{
|
|
131
|
+
slug: slugSchema.describe(slugDescription),
|
|
132
|
+
weight: weightSchema.describe("Weight used to calculate score")
|
|
133
|
+
},
|
|
134
|
+
{ description }
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
function scorableSchema(description, refSchema, duplicateCheckFn, duplicateMessageFn) {
|
|
138
|
+
return z.object(
|
|
139
|
+
{
|
|
140
|
+
slug: slugSchema.describe('Human-readable unique ID, e.g. "performance"'),
|
|
141
|
+
refs: z.array(refSchema).min(1).refine(
|
|
142
|
+
(refs) => !duplicateCheckFn(refs),
|
|
143
|
+
(refs) => ({
|
|
144
|
+
message: duplicateMessageFn(refs)
|
|
145
|
+
})
|
|
146
|
+
).refine(hasNonZeroWeightedRef, () => ({
|
|
147
|
+
message: "In a category there has to be at least one ref with weight > 0"
|
|
148
|
+
}))
|
|
149
|
+
},
|
|
150
|
+
{ description }
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
var materialIconSchema = z.enum(MATERIAL_ICONS, {
|
|
154
|
+
description: "Icon from VSCode Material Icons extension"
|
|
155
|
+
});
|
|
156
|
+
function hasNonZeroWeightedRef(refs) {
|
|
157
|
+
return refs.reduce((acc, { weight }) => weight + acc, 0) !== 0;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// packages/models/src/lib/source.ts
|
|
161
|
+
import { z as z2 } from "zod";
|
|
162
|
+
var sourceFileLocationSchema = z2.object(
|
|
163
|
+
{
|
|
164
|
+
file: filePathSchema.describe("Relative path to source file in Git repo"),
|
|
165
|
+
position: z2.object(
|
|
166
|
+
{
|
|
167
|
+
startLine: positiveIntSchema.describe("Start line"),
|
|
168
|
+
startColumn: positiveIntSchema.describe("Start column").optional(),
|
|
169
|
+
endLine: positiveIntSchema.describe("End line").optional(),
|
|
170
|
+
endColumn: positiveIntSchema.describe("End column").optional()
|
|
171
|
+
},
|
|
172
|
+
{ description: "Location in file" }
|
|
173
|
+
).optional()
|
|
174
|
+
},
|
|
175
|
+
{ description: "Source file location" }
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
// packages/models/src/lib/audit.ts
|
|
179
|
+
import { z as z3 } from "zod";
|
|
180
|
+
var auditSchema = z3.object({
|
|
181
|
+
slug: slugSchema.describe("ID (unique within plugin)")
|
|
182
|
+
}).merge(
|
|
183
|
+
metaSchema({
|
|
184
|
+
titleDescription: "Descriptive name",
|
|
185
|
+
descriptionDescription: "Description (markdown)",
|
|
186
|
+
docsUrlDescription: "Link to documentation (rationale)",
|
|
187
|
+
description: "List of scorable metrics for the given plugin"
|
|
188
|
+
})
|
|
189
|
+
);
|
|
190
|
+
var pluginAuditsSchema = z3.array(auditSchema, {
|
|
191
|
+
description: "List of audits maintained in a plugin"
|
|
192
|
+
}).min(1).refine(
|
|
193
|
+
(auditMetadata) => !getDuplicateSlugsInAudits(auditMetadata),
|
|
194
|
+
(auditMetadata) => ({
|
|
195
|
+
message: duplicateSlugsInAuditsErrorMsg(auditMetadata)
|
|
196
|
+
})
|
|
197
|
+
);
|
|
198
|
+
function duplicateSlugsInAuditsErrorMsg(audits) {
|
|
199
|
+
const duplicateRefs = getDuplicateSlugsInAudits(audits);
|
|
200
|
+
return `In plugin audits the following slugs are not unique: ${errorItems(
|
|
201
|
+
duplicateRefs
|
|
202
|
+
)}`;
|
|
203
|
+
}
|
|
204
|
+
function getDuplicateSlugsInAudits(audits) {
|
|
205
|
+
return hasDuplicateStrings(audits.map(({ slug }) => slug));
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// packages/models/src/lib/audit-output.ts
|
|
209
|
+
import { z as z6 } from "zod";
|
|
210
|
+
|
|
211
|
+
// packages/models/src/lib/issue.ts
|
|
212
|
+
import { z as z4 } from "zod";
|
|
213
|
+
var issueSeveritySchema = z4.enum(["info", "warning", "error"], {
|
|
214
|
+
description: "Severity level"
|
|
215
|
+
});
|
|
216
|
+
var issueSchema = z4.object(
|
|
217
|
+
{
|
|
218
|
+
message: z4.string({ description: "Descriptive error message" }).max(MAX_ISSUE_MESSAGE_LENGTH),
|
|
219
|
+
severity: issueSeveritySchema,
|
|
220
|
+
source: sourceFileLocationSchema.optional()
|
|
221
|
+
},
|
|
222
|
+
{ description: "Issue information" }
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
// packages/models/src/lib/table.ts
|
|
226
|
+
import { z as z5 } from "zod";
|
|
227
|
+
var tableAlignmentSchema = z5.enum(["left", "center", "right"], {
|
|
228
|
+
description: "Cell alignment"
|
|
229
|
+
});
|
|
230
|
+
var tableColumnObjectSchema = z5.object({
|
|
231
|
+
key: z5.string(),
|
|
232
|
+
label: z5.string().optional(),
|
|
233
|
+
align: tableAlignmentSchema.optional()
|
|
234
|
+
});
|
|
235
|
+
var tableRowObjectSchema = z5.record(tableCellValueSchema, {
|
|
236
|
+
description: "Object row"
|
|
237
|
+
});
|
|
238
|
+
var tableRowPrimitiveSchema = z5.array(tableCellValueSchema, {
|
|
239
|
+
description: "Primitive row"
|
|
240
|
+
});
|
|
241
|
+
var tableSharedSchema = z5.object({
|
|
242
|
+
title: z5.string().optional().describe("Display title for table")
|
|
243
|
+
});
|
|
244
|
+
var tablePrimitiveSchema = tableSharedSchema.merge(
|
|
245
|
+
z5.object(
|
|
246
|
+
{
|
|
247
|
+
columns: z5.array(tableAlignmentSchema).optional(),
|
|
248
|
+
rows: z5.array(tableRowPrimitiveSchema)
|
|
249
|
+
},
|
|
250
|
+
{ description: "Table with primitive rows and optional alignment columns" }
|
|
251
|
+
)
|
|
252
|
+
);
|
|
253
|
+
var tableObjectSchema = tableSharedSchema.merge(
|
|
254
|
+
z5.object(
|
|
255
|
+
{
|
|
256
|
+
columns: z5.union([
|
|
257
|
+
z5.array(tableAlignmentSchema),
|
|
258
|
+
z5.array(tableColumnObjectSchema)
|
|
259
|
+
]).optional(),
|
|
260
|
+
rows: z5.array(tableRowObjectSchema)
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
description: "Table with object rows and optional alignment or object columns"
|
|
264
|
+
}
|
|
265
|
+
)
|
|
266
|
+
);
|
|
267
|
+
var tableSchema = (description = "Table information") => z5.union([tablePrimitiveSchema, tableObjectSchema], { description });
|
|
268
|
+
|
|
269
|
+
// packages/models/src/lib/audit-output.ts
|
|
270
|
+
var auditValueSchema = nonnegativeNumberSchema.describe("Raw numeric value");
|
|
271
|
+
var auditDisplayValueSchema = z6.string({ description: "Formatted value (e.g. '0.9 s', '2.1 MB')" }).optional();
|
|
272
|
+
var auditDetailsSchema = z6.object(
|
|
273
|
+
{
|
|
274
|
+
issues: z6.array(issueSchema, { description: "List of findings" }).optional(),
|
|
275
|
+
table: tableSchema("Table of related findings").optional()
|
|
276
|
+
},
|
|
277
|
+
{ description: "Detailed information" }
|
|
278
|
+
);
|
|
279
|
+
var auditOutputSchema = z6.object(
|
|
280
|
+
{
|
|
281
|
+
slug: slugSchema.describe("Reference to audit"),
|
|
282
|
+
displayValue: auditDisplayValueSchema,
|
|
283
|
+
value: auditValueSchema,
|
|
284
|
+
score: scoreSchema,
|
|
285
|
+
details: auditDetailsSchema.optional()
|
|
286
|
+
},
|
|
287
|
+
{ description: "Audit information" }
|
|
288
|
+
);
|
|
289
|
+
var auditOutputsSchema = z6.array(auditOutputSchema, {
|
|
290
|
+
description: "List of JSON formatted audit output emitted by the runner process of a plugin"
|
|
291
|
+
}).refine(
|
|
292
|
+
(audits) => !getDuplicateSlugsInAudits2(audits),
|
|
293
|
+
(audits) => ({ message: duplicateSlugsInAuditsErrorMsg2(audits) })
|
|
294
|
+
);
|
|
295
|
+
function duplicateSlugsInAuditsErrorMsg2(audits) {
|
|
296
|
+
const duplicateRefs = getDuplicateSlugsInAudits2(audits);
|
|
297
|
+
return `In plugin audits the slugs are not unique: ${errorItems(
|
|
298
|
+
duplicateRefs
|
|
299
|
+
)}`;
|
|
300
|
+
}
|
|
301
|
+
function getDuplicateSlugsInAudits2(audits) {
|
|
302
|
+
return hasDuplicateStrings(audits.map(({ slug }) => slug));
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// packages/models/src/lib/category-config.ts
|
|
306
|
+
import { z as z7 } from "zod";
|
|
307
|
+
var categoryRefSchema = weightedRefSchema(
|
|
308
|
+
"Weighted references to audits and/or groups for the category",
|
|
309
|
+
"Slug of an audit or group (depending on `type`)"
|
|
310
|
+
).merge(
|
|
311
|
+
z7.object({
|
|
312
|
+
type: z7.enum(["audit", "group"], {
|
|
313
|
+
description: "Discriminant for reference kind, affects where `slug` is looked up"
|
|
314
|
+
}),
|
|
315
|
+
plugin: slugSchema.describe(
|
|
316
|
+
"Plugin slug (plugin should contain referenced audit or group)"
|
|
317
|
+
)
|
|
318
|
+
})
|
|
319
|
+
);
|
|
320
|
+
var categoryConfigSchema = scorableSchema(
|
|
321
|
+
"Category with a score calculated from audits and groups from various plugins",
|
|
322
|
+
categoryRefSchema,
|
|
323
|
+
getDuplicateRefsInCategoryMetrics,
|
|
324
|
+
duplicateRefsInCategoryMetricsErrorMsg
|
|
325
|
+
).merge(
|
|
326
|
+
metaSchema({
|
|
327
|
+
titleDescription: "Category Title",
|
|
328
|
+
docsUrlDescription: "Category docs URL",
|
|
329
|
+
descriptionDescription: "Category description",
|
|
330
|
+
description: "Meta info for category"
|
|
331
|
+
})
|
|
332
|
+
).merge(
|
|
333
|
+
z7.object({
|
|
334
|
+
isBinary: z7.boolean({
|
|
335
|
+
description: 'Is this a binary category (i.e. only a perfect score considered a "pass")?'
|
|
336
|
+
}).optional()
|
|
337
|
+
})
|
|
338
|
+
);
|
|
339
|
+
function duplicateRefsInCategoryMetricsErrorMsg(metrics) {
|
|
340
|
+
const duplicateRefs = getDuplicateRefsInCategoryMetrics(metrics);
|
|
341
|
+
return `In the categories, the following audit or group refs are duplicates: ${errorItems(
|
|
342
|
+
duplicateRefs
|
|
343
|
+
)}`;
|
|
344
|
+
}
|
|
345
|
+
function getDuplicateRefsInCategoryMetrics(metrics) {
|
|
346
|
+
return hasDuplicateStrings(
|
|
347
|
+
metrics.map(({ slug, type, plugin }) => `${type} :: ${plugin} / ${slug}`)
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
var categoriesSchema = z7.array(categoryConfigSchema, {
|
|
351
|
+
description: "Categorization of individual audits"
|
|
352
|
+
}).refine(
|
|
353
|
+
(categoryCfg) => !getDuplicateSlugCategories(categoryCfg),
|
|
354
|
+
(categoryCfg) => ({
|
|
355
|
+
message: duplicateSlugCategoriesErrorMsg(categoryCfg)
|
|
356
|
+
})
|
|
357
|
+
);
|
|
358
|
+
function duplicateSlugCategoriesErrorMsg(categories) {
|
|
359
|
+
const duplicateStringSlugs = getDuplicateSlugCategories(categories);
|
|
360
|
+
return `In the categories, the following slugs are duplicated: ${errorItems(
|
|
361
|
+
duplicateStringSlugs
|
|
362
|
+
)}`;
|
|
363
|
+
}
|
|
364
|
+
function getDuplicateSlugCategories(categories) {
|
|
365
|
+
return hasDuplicateStrings(categories.map(({ slug }) => slug));
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// packages/models/src/lib/commit.ts
|
|
369
|
+
import { z as z8 } from "zod";
|
|
370
|
+
var commitSchema = z8.object(
|
|
371
|
+
{
|
|
372
|
+
hash: z8.string({ description: "Commit SHA (full)" }).regex(
|
|
373
|
+
/^[\da-f]{40}$/,
|
|
374
|
+
"Commit SHA should be a 40-character hexadecimal string"
|
|
375
|
+
),
|
|
376
|
+
message: z8.string({ description: "Commit message" }),
|
|
377
|
+
date: z8.coerce.date({
|
|
378
|
+
description: "Date and time when commit was authored"
|
|
379
|
+
}),
|
|
380
|
+
author: z8.string({
|
|
381
|
+
description: "Commit author name"
|
|
382
|
+
}).trim()
|
|
383
|
+
},
|
|
384
|
+
{ description: "Git commit" }
|
|
385
|
+
);
|
|
386
|
+
|
|
387
|
+
// packages/models/src/lib/core-config.ts
|
|
388
|
+
import { z as z14 } from "zod";
|
|
389
|
+
|
|
390
|
+
// packages/models/src/lib/persist-config.ts
|
|
391
|
+
import { z as z9 } from "zod";
|
|
392
|
+
var formatSchema = z9.enum(["json", "md"]);
|
|
393
|
+
var persistConfigSchema = z9.object({
|
|
394
|
+
outputDir: filePathSchema.describe("Artifacts folder").optional(),
|
|
395
|
+
filename: fileNameSchema.describe("Artifacts file name (without extension)").optional(),
|
|
396
|
+
format: z9.array(formatSchema).optional()
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
// packages/models/src/lib/plugin-config.ts
|
|
400
|
+
import { z as z12 } from "zod";
|
|
401
|
+
|
|
402
|
+
// packages/models/src/lib/group.ts
|
|
403
|
+
import { z as z10 } from "zod";
|
|
404
|
+
var groupRefSchema = weightedRefSchema(
|
|
405
|
+
"Weighted reference to a group",
|
|
406
|
+
"Reference slug to a group within this plugin (e.g. 'max-lines')"
|
|
407
|
+
);
|
|
408
|
+
var groupMetaSchema = metaSchema({
|
|
409
|
+
titleDescription: "Descriptive name for the group",
|
|
410
|
+
descriptionDescription: "Description of the group (markdown)",
|
|
411
|
+
docsUrlDescription: "Group documentation site",
|
|
412
|
+
description: "Group metadata"
|
|
413
|
+
});
|
|
414
|
+
var groupSchema = scorableSchema(
|
|
415
|
+
'A group aggregates a set of audits into a single score which can be referenced from a category. E.g. the group slug "performance" groups audits and can be referenced in a category',
|
|
416
|
+
groupRefSchema,
|
|
417
|
+
getDuplicateRefsInGroups,
|
|
418
|
+
duplicateRefsInGroupsErrorMsg
|
|
419
|
+
).merge(groupMetaSchema);
|
|
420
|
+
var groupsSchema = z10.array(groupSchema, {
|
|
421
|
+
description: "List of groups"
|
|
422
|
+
}).optional().refine(
|
|
423
|
+
(groups) => !getDuplicateSlugsInGroups(groups),
|
|
424
|
+
(groups) => ({
|
|
425
|
+
message: duplicateSlugsInGroupsErrorMsg(groups)
|
|
426
|
+
})
|
|
427
|
+
);
|
|
428
|
+
function duplicateRefsInGroupsErrorMsg(groups) {
|
|
429
|
+
const duplicateRefs = getDuplicateRefsInGroups(groups);
|
|
430
|
+
return `In plugin groups the following references are not unique: ${errorItems(
|
|
431
|
+
duplicateRefs
|
|
432
|
+
)}`;
|
|
433
|
+
}
|
|
434
|
+
function getDuplicateRefsInGroups(groups) {
|
|
435
|
+
return hasDuplicateStrings(groups.map(({ slug: ref }) => ref).filter(exists));
|
|
436
|
+
}
|
|
437
|
+
function duplicateSlugsInGroupsErrorMsg(groups) {
|
|
438
|
+
const duplicateRefs = getDuplicateSlugsInGroups(groups);
|
|
439
|
+
return `In groups the following slugs are not unique: ${errorItems(
|
|
440
|
+
duplicateRefs
|
|
441
|
+
)}`;
|
|
442
|
+
}
|
|
443
|
+
function getDuplicateSlugsInGroups(groups) {
|
|
444
|
+
return Array.isArray(groups) ? hasDuplicateStrings(groups.map(({ slug }) => slug)) : false;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// packages/models/src/lib/runner-config.ts
|
|
448
|
+
import { z as z11 } from "zod";
|
|
449
|
+
var outputTransformSchema = z11.function().args(z11.unknown()).returns(z11.union([auditOutputsSchema, z11.promise(auditOutputsSchema)]));
|
|
450
|
+
var runnerConfigSchema = z11.object(
|
|
451
|
+
{
|
|
452
|
+
command: z11.string({
|
|
453
|
+
description: "Shell command to execute"
|
|
454
|
+
}),
|
|
455
|
+
args: z11.array(z11.string({ description: "Command arguments" })).optional(),
|
|
456
|
+
outputFile: filePathSchema.describe("Output path"),
|
|
457
|
+
outputTransform: outputTransformSchema.optional()
|
|
458
|
+
},
|
|
459
|
+
{
|
|
460
|
+
description: "How to execute runner"
|
|
461
|
+
}
|
|
462
|
+
);
|
|
463
|
+
var onProgressSchema = z11.function().args(z11.unknown()).returns(z11.void());
|
|
464
|
+
var runnerFunctionSchema = z11.function().args(onProgressSchema.optional()).returns(z11.union([auditOutputsSchema, z11.promise(auditOutputsSchema)]));
|
|
465
|
+
|
|
466
|
+
// packages/models/src/lib/plugin-config.ts
|
|
467
|
+
var pluginMetaSchema = packageVersionSchema().merge(
|
|
468
|
+
metaSchema({
|
|
469
|
+
titleDescription: "Descriptive name",
|
|
470
|
+
descriptionDescription: "Description (markdown)",
|
|
471
|
+
docsUrlDescription: "Plugin documentation site",
|
|
472
|
+
description: "Plugin metadata"
|
|
473
|
+
})
|
|
474
|
+
).merge(
|
|
475
|
+
z12.object({
|
|
476
|
+
slug: slugSchema.describe("Unique plugin slug within core config"),
|
|
477
|
+
icon: materialIconSchema
|
|
478
|
+
})
|
|
479
|
+
);
|
|
480
|
+
var pluginDataSchema = z12.object({
|
|
481
|
+
runner: z12.union([runnerConfigSchema, runnerFunctionSchema]),
|
|
482
|
+
audits: pluginAuditsSchema,
|
|
483
|
+
groups: groupsSchema
|
|
484
|
+
});
|
|
485
|
+
var pluginConfigSchema = pluginMetaSchema.merge(pluginDataSchema).refine(
|
|
486
|
+
(pluginCfg) => !getMissingRefsFromGroups(pluginCfg),
|
|
487
|
+
(pluginCfg) => ({
|
|
488
|
+
message: missingRefsFromGroupsErrorMsg(pluginCfg)
|
|
489
|
+
})
|
|
490
|
+
);
|
|
491
|
+
function missingRefsFromGroupsErrorMsg(pluginCfg) {
|
|
492
|
+
const missingRefs = getMissingRefsFromGroups(pluginCfg);
|
|
493
|
+
return `The following group references need to point to an existing audit in this plugin config: ${errorItems(
|
|
494
|
+
missingRefs
|
|
495
|
+
)}`;
|
|
496
|
+
}
|
|
497
|
+
function getMissingRefsFromGroups(pluginCfg) {
|
|
498
|
+
return hasMissingStrings(
|
|
499
|
+
pluginCfg.groups?.flatMap(
|
|
500
|
+
({ refs: audits }) => audits.map(({ slug: ref }) => ref)
|
|
501
|
+
) ?? [],
|
|
502
|
+
pluginCfg.audits.map(({ slug }) => slug)
|
|
503
|
+
);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
// packages/models/src/lib/upload-config.ts
|
|
507
|
+
import { z as z13 } from "zod";
|
|
508
|
+
var uploadConfigSchema = z13.object({
|
|
509
|
+
server: urlSchema.describe("URL of deployed portal API"),
|
|
510
|
+
apiKey: z13.string({
|
|
511
|
+
description: "API key with write access to portal (use `process.env` for security)"
|
|
512
|
+
}),
|
|
513
|
+
organization: slugSchema.describe(
|
|
514
|
+
"Organization slug from Code PushUp portal"
|
|
515
|
+
),
|
|
516
|
+
project: slugSchema.describe("Project slug from Code PushUp portal"),
|
|
517
|
+
timeout: z13.number({ description: "Request timeout in minutes (default is 5)" }).positive().int().optional()
|
|
518
|
+
});
|
|
519
|
+
|
|
520
|
+
// packages/models/src/lib/core-config.ts
|
|
521
|
+
var unrefinedCoreConfigSchema = z14.object({
|
|
522
|
+
plugins: z14.array(pluginConfigSchema, {
|
|
523
|
+
description: "List of plugins to be used (official, community-provided, or custom)"
|
|
524
|
+
}).min(1),
|
|
525
|
+
/** portal configuration for persisting results */
|
|
526
|
+
persist: persistConfigSchema.optional(),
|
|
527
|
+
/** portal configuration for uploading results */
|
|
528
|
+
upload: uploadConfigSchema.optional(),
|
|
529
|
+
categories: categoriesSchema.optional()
|
|
530
|
+
});
|
|
531
|
+
var coreConfigSchema = refineCoreConfig(unrefinedCoreConfigSchema);
|
|
532
|
+
function refineCoreConfig(schema) {
|
|
533
|
+
return schema.refine(
|
|
534
|
+
(coreCfg) => !getMissingRefsForCategories(coreCfg.categories ?? [], coreCfg.plugins),
|
|
535
|
+
(coreCfg) => ({
|
|
536
|
+
message: missingRefsForCategoriesErrorMsg(
|
|
537
|
+
coreCfg.categories ?? [],
|
|
538
|
+
coreCfg.plugins
|
|
539
|
+
)
|
|
540
|
+
})
|
|
541
|
+
);
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
// packages/models/src/lib/report.ts
|
|
545
|
+
import { z as z15 } from "zod";
|
|
546
|
+
var auditReportSchema = auditSchema.merge(auditOutputSchema);
|
|
547
|
+
var pluginReportSchema = pluginMetaSchema.merge(
|
|
548
|
+
executionMetaSchema({
|
|
549
|
+
descriptionDate: "Start date and time of plugin run",
|
|
550
|
+
descriptionDuration: "Duration of the plugin run in ms"
|
|
551
|
+
})
|
|
552
|
+
).merge(
|
|
553
|
+
z15.object({
|
|
554
|
+
audits: z15.array(auditReportSchema).min(1),
|
|
555
|
+
groups: z15.array(groupSchema).optional()
|
|
556
|
+
})
|
|
557
|
+
).refine(
|
|
558
|
+
(pluginReport) => !getMissingRefsFromGroups2(pluginReport.audits, pluginReport.groups ?? []),
|
|
559
|
+
(pluginReport) => ({
|
|
560
|
+
message: missingRefsFromGroupsErrorMsg2(
|
|
561
|
+
pluginReport.audits,
|
|
562
|
+
pluginReport.groups ?? []
|
|
563
|
+
)
|
|
564
|
+
})
|
|
565
|
+
);
|
|
566
|
+
function missingRefsFromGroupsErrorMsg2(audits, groups) {
|
|
567
|
+
const missingRefs = getMissingRefsFromGroups2(audits, groups);
|
|
568
|
+
return `group references need to point to an existing audit in this plugin report: ${errorItems(
|
|
569
|
+
missingRefs
|
|
570
|
+
)}`;
|
|
571
|
+
}
|
|
572
|
+
function getMissingRefsFromGroups2(audits, groups) {
|
|
573
|
+
return hasMissingStrings(
|
|
574
|
+
groups.flatMap(
|
|
575
|
+
({ refs: auditRefs }) => auditRefs.map(({ slug: ref }) => ref)
|
|
576
|
+
),
|
|
577
|
+
audits.map(({ slug }) => slug)
|
|
578
|
+
);
|
|
579
|
+
}
|
|
580
|
+
var reportSchema = packageVersionSchema({
|
|
581
|
+
versionDescription: "NPM version of the CLI",
|
|
582
|
+
required: true
|
|
583
|
+
}).merge(
|
|
584
|
+
executionMetaSchema({
|
|
585
|
+
descriptionDate: "Start date and time of the collect run",
|
|
586
|
+
descriptionDuration: "Duration of the collect run in ms"
|
|
587
|
+
})
|
|
588
|
+
).merge(
|
|
589
|
+
z15.object(
|
|
590
|
+
{
|
|
591
|
+
categories: z15.array(categoryConfigSchema),
|
|
592
|
+
plugins: z15.array(pluginReportSchema).min(1),
|
|
593
|
+
commit: commitSchema.describe("Git commit for which report was collected").nullable()
|
|
594
|
+
},
|
|
595
|
+
{ description: "Collect output data" }
|
|
596
|
+
)
|
|
597
|
+
).refine(
|
|
598
|
+
(report) => !getMissingRefsForCategories(report.categories, report.plugins),
|
|
599
|
+
(report) => ({
|
|
600
|
+
message: missingRefsForCategoriesErrorMsg(
|
|
601
|
+
report.categories,
|
|
602
|
+
report.plugins
|
|
603
|
+
)
|
|
604
|
+
})
|
|
605
|
+
);
|
|
606
|
+
|
|
607
|
+
// packages/models/src/lib/reports-diff.ts
|
|
608
|
+
import { z as z16 } from "zod";
|
|
609
|
+
function makeComparisonSchema(schema) {
|
|
610
|
+
const sharedDescription = schema.description || "Result";
|
|
611
|
+
return z16.object({
|
|
612
|
+
before: schema.describe(`${sharedDescription} (source commit)`),
|
|
613
|
+
after: schema.describe(`${sharedDescription} (target commit)`)
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
function makeArraysComparisonSchema(diffSchema, resultSchema, description) {
|
|
617
|
+
return z16.object(
|
|
618
|
+
{
|
|
619
|
+
changed: z16.array(diffSchema),
|
|
620
|
+
unchanged: z16.array(resultSchema),
|
|
621
|
+
added: z16.array(resultSchema),
|
|
622
|
+
removed: z16.array(resultSchema)
|
|
623
|
+
},
|
|
624
|
+
{ description }
|
|
625
|
+
);
|
|
626
|
+
}
|
|
627
|
+
var scorableMetaSchema = z16.object({
|
|
628
|
+
slug: slugSchema,
|
|
629
|
+
title: titleSchema,
|
|
630
|
+
docsUrl: docsUrlSchema
|
|
631
|
+
});
|
|
632
|
+
var scorableWithPluginMetaSchema = scorableMetaSchema.merge(
|
|
633
|
+
z16.object({
|
|
634
|
+
plugin: pluginMetaSchema.pick({ slug: true, title: true, docsUrl: true }).describe("Plugin which defines it")
|
|
635
|
+
})
|
|
636
|
+
);
|
|
637
|
+
var scorableDiffSchema = scorableMetaSchema.merge(
|
|
638
|
+
z16.object({
|
|
639
|
+
scores: makeComparisonSchema(scoreSchema).merge(
|
|
640
|
+
z16.object({
|
|
641
|
+
diff: z16.number().min(-1).max(1).describe("Score change (`scores.after - scores.before`)")
|
|
642
|
+
})
|
|
643
|
+
).describe("Score comparison")
|
|
644
|
+
})
|
|
645
|
+
);
|
|
646
|
+
var scorableWithPluginDiffSchema = scorableDiffSchema.merge(
|
|
647
|
+
scorableWithPluginMetaSchema
|
|
648
|
+
);
|
|
649
|
+
var categoryDiffSchema = scorableDiffSchema;
|
|
650
|
+
var groupDiffSchema = scorableWithPluginDiffSchema;
|
|
651
|
+
var auditDiffSchema = scorableWithPluginDiffSchema.merge(
|
|
652
|
+
z16.object({
|
|
653
|
+
values: makeComparisonSchema(auditValueSchema).merge(
|
|
654
|
+
z16.object({
|
|
655
|
+
diff: z16.number().int().describe("Value change (`values.after - values.before`)")
|
|
656
|
+
})
|
|
657
|
+
).describe("Audit `value` comparison"),
|
|
658
|
+
displayValues: makeComparisonSchema(auditDisplayValueSchema).describe(
|
|
659
|
+
"Audit `displayValue` comparison"
|
|
660
|
+
)
|
|
661
|
+
})
|
|
662
|
+
);
|
|
663
|
+
var categoryResultSchema = scorableMetaSchema.merge(
|
|
664
|
+
z16.object({ score: scoreSchema })
|
|
665
|
+
);
|
|
666
|
+
var groupResultSchema = scorableWithPluginMetaSchema.merge(
|
|
667
|
+
z16.object({ score: scoreSchema })
|
|
668
|
+
);
|
|
669
|
+
var auditResultSchema = scorableWithPluginMetaSchema.merge(
|
|
670
|
+
auditOutputSchema.pick({ score: true, value: true, displayValue: true })
|
|
671
|
+
);
|
|
672
|
+
var reportsDiffSchema = z16.object({
|
|
673
|
+
commits: makeComparisonSchema(commitSchema).nullable().describe("Commits identifying compared reports"),
|
|
674
|
+
portalUrl: urlSchema.optional().describe("Link to comparison page in Code PushUp portal"),
|
|
675
|
+
label: z16.string().optional().describe("Label (e.g. project name)"),
|
|
676
|
+
categories: makeArraysComparisonSchema(
|
|
677
|
+
categoryDiffSchema,
|
|
678
|
+
categoryResultSchema,
|
|
679
|
+
"Changes affecting categories"
|
|
680
|
+
),
|
|
681
|
+
groups: makeArraysComparisonSchema(
|
|
682
|
+
groupDiffSchema,
|
|
683
|
+
groupResultSchema,
|
|
684
|
+
"Changes affecting groups"
|
|
685
|
+
),
|
|
686
|
+
audits: makeArraysComparisonSchema(
|
|
687
|
+
auditDiffSchema,
|
|
688
|
+
auditResultSchema,
|
|
689
|
+
"Changes affecting audits"
|
|
690
|
+
)
|
|
691
|
+
}).merge(
|
|
692
|
+
packageVersionSchema({
|
|
693
|
+
versionDescription: "NPM version of the CLI (when `compare` was run)",
|
|
694
|
+
required: true
|
|
695
|
+
})
|
|
696
|
+
).merge(
|
|
697
|
+
executionMetaSchema({
|
|
698
|
+
descriptionDate: "Start date and time of the compare run",
|
|
699
|
+
descriptionDuration: "Duration of the compare run in ms"
|
|
700
|
+
})
|
|
701
|
+
);
|
|
702
|
+
|
|
703
|
+
// packages/utils/src/lib/execute-process.ts
|
|
704
|
+
import {
|
|
705
|
+
spawn
|
|
706
|
+
} from "node:child_process";
|
|
707
|
+
|
|
708
|
+
// packages/utils/src/lib/reports/utils.ts
|
|
709
|
+
import ansis from "ansis";
|
|
710
|
+
import { md } from "build-md";
|
|
711
|
+
|
|
712
|
+
// packages/utils/src/lib/reports/constants.ts
|
|
713
|
+
var CODE_PUSHUP_UNICODE_LOGO = "<\u2713>";
|
|
714
|
+
|
|
715
|
+
// packages/utils/src/lib/reports/utils.ts
|
|
716
|
+
function calcDuration(start, stop) {
|
|
717
|
+
return Math.round((stop ?? performance.now()) - start);
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
// packages/utils/src/lib/execute-process.ts
|
|
721
|
+
var ProcessError = class extends Error {
|
|
722
|
+
code;
|
|
723
|
+
stderr;
|
|
724
|
+
stdout;
|
|
725
|
+
constructor(result) {
|
|
726
|
+
super(result.stderr);
|
|
727
|
+
this.code = result.code;
|
|
728
|
+
this.stderr = result.stderr;
|
|
729
|
+
this.stdout = result.stdout;
|
|
730
|
+
}
|
|
731
|
+
};
|
|
732
|
+
function executeProcess(cfg) {
|
|
733
|
+
const { command, args, observer, ignoreExitCode = false, ...options } = cfg;
|
|
734
|
+
const { onStdout, onStderr, onError, onComplete } = observer ?? {};
|
|
735
|
+
const date = (/* @__PURE__ */ new Date()).toISOString();
|
|
736
|
+
const start = performance.now();
|
|
737
|
+
return new Promise((resolve, reject) => {
|
|
738
|
+
const spawnedProcess = spawn(command, args ?? [], {
|
|
739
|
+
shell: true,
|
|
740
|
+
...options
|
|
741
|
+
});
|
|
742
|
+
let stdout = "";
|
|
743
|
+
let stderr = "";
|
|
744
|
+
spawnedProcess.stdout.on("data", (data) => {
|
|
745
|
+
stdout += String(data);
|
|
746
|
+
onStdout?.(String(data), spawnedProcess);
|
|
747
|
+
});
|
|
748
|
+
spawnedProcess.stderr.on("data", (data) => {
|
|
749
|
+
stderr += String(data);
|
|
750
|
+
onStderr?.(String(data), spawnedProcess);
|
|
751
|
+
});
|
|
752
|
+
spawnedProcess.on("error", (err) => {
|
|
753
|
+
stderr += err.toString();
|
|
754
|
+
});
|
|
755
|
+
spawnedProcess.on("close", (code2) => {
|
|
756
|
+
const timings = { date, duration: calcDuration(start) };
|
|
757
|
+
if (code2 === 0 || ignoreExitCode) {
|
|
758
|
+
onComplete?.();
|
|
759
|
+
resolve({ code: code2, stdout, stderr, ...timings });
|
|
760
|
+
} else {
|
|
761
|
+
const errorMsg = new ProcessError({ code: code2, stdout, stderr, ...timings });
|
|
762
|
+
onError?.(errorMsg);
|
|
763
|
+
reject(errorMsg);
|
|
764
|
+
}
|
|
765
|
+
});
|
|
766
|
+
});
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
// packages/utils/src/lib/file-system.ts
|
|
770
|
+
import { bold, gray } from "ansis";
|
|
771
|
+
import { bundleRequire } from "bundle-require";
|
|
772
|
+
|
|
773
|
+
// packages/utils/src/lib/logging.ts
|
|
774
|
+
import isaacs_cliui from "@isaacs/cliui";
|
|
775
|
+
import { cliui } from "@poppinss/cliui";
|
|
776
|
+
import { underline } from "ansis";
|
|
777
|
+
|
|
778
|
+
// packages/utils/src/lib/git/git.ts
|
|
779
|
+
import { simpleGit } from "simple-git";
|
|
780
|
+
|
|
781
|
+
// packages/utils/src/lib/transform.ts
|
|
782
|
+
function objectToCliArgs(params) {
|
|
783
|
+
if (!params) {
|
|
784
|
+
return [];
|
|
785
|
+
}
|
|
786
|
+
return Object.entries(params).flatMap(([key, value]) => {
|
|
787
|
+
if (key === "_") {
|
|
788
|
+
return Array.isArray(value) ? value : [`${value}`];
|
|
789
|
+
}
|
|
790
|
+
const prefix = key.length === 1 ? "-" : "--";
|
|
791
|
+
if (Array.isArray(value)) {
|
|
792
|
+
return value.map((v) => `${prefix}${key}="${v}"`);
|
|
793
|
+
}
|
|
794
|
+
if (Array.isArray(value)) {
|
|
795
|
+
return value.map((v) => `${prefix}${key}="${v}"`);
|
|
796
|
+
}
|
|
797
|
+
if (typeof value === "object") {
|
|
798
|
+
return Object.entries(value).flatMap(
|
|
799
|
+
// transform nested objects to the dot notation `key.subkey`
|
|
800
|
+
([k, v]) => objectToCliArgs({ [`${key}.${k}`]: v })
|
|
801
|
+
);
|
|
802
|
+
}
|
|
803
|
+
if (typeof value === "string") {
|
|
804
|
+
return [`${prefix}${key}="${value}"`];
|
|
805
|
+
}
|
|
806
|
+
if (typeof value === "number") {
|
|
807
|
+
return [`${prefix}${key}=${value}`];
|
|
808
|
+
}
|
|
809
|
+
if (typeof value === "boolean") {
|
|
810
|
+
return [`${prefix}${value ? "" : "no-"}${key}`];
|
|
811
|
+
}
|
|
812
|
+
throw new Error(`Unsupported type ${typeof value} for key ${key}`);
|
|
813
|
+
});
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
// packages/utils/src/lib/git/git.commits-and-tags.ts
|
|
817
|
+
import { simpleGit as simpleGit2 } from "simple-git";
|
|
818
|
+
|
|
819
|
+
// packages/utils/src/lib/semver.ts
|
|
820
|
+
import { rcompare, valid } from "semver";
|
|
821
|
+
|
|
822
|
+
// packages/utils/src/lib/progress.ts
|
|
823
|
+
import { black, bold as bold2, gray as gray2, green } from "ansis";
|
|
824
|
+
import { MultiProgressBars } from "multi-progress-bars";
|
|
825
|
+
|
|
826
|
+
// packages/utils/src/lib/reports/generate-md-report.ts
|
|
827
|
+
import { MarkdownDocument as MarkdownDocument3, md as md4 } from "build-md";
|
|
828
|
+
|
|
829
|
+
// packages/utils/src/lib/reports/formatting.ts
|
|
830
|
+
import {
|
|
831
|
+
MarkdownDocument,
|
|
832
|
+
md as md2
|
|
833
|
+
} from "build-md";
|
|
834
|
+
|
|
835
|
+
// packages/utils/src/lib/reports/generate-md-report-categoy-section.ts
|
|
836
|
+
import { MarkdownDocument as MarkdownDocument2, md as md3 } from "build-md";
|
|
837
|
+
|
|
838
|
+
// packages/utils/src/lib/reports/generate-md-reports-diff.ts
|
|
839
|
+
import {
|
|
840
|
+
MarkdownDocument as MarkdownDocument5,
|
|
841
|
+
md as md6
|
|
842
|
+
} from "build-md";
|
|
843
|
+
|
|
844
|
+
// packages/utils/src/lib/reports/generate-md-reports-diff-utils.ts
|
|
845
|
+
import { MarkdownDocument as MarkdownDocument4, md as md5 } from "build-md";
|
|
846
|
+
|
|
847
|
+
// packages/utils/src/lib/reports/log-stdout-summary.ts
|
|
848
|
+
import { bold as bold4, cyan, cyanBright, green as green2, red } from "ansis";
|
|
849
|
+
|
|
850
|
+
// packages/create-cli/src/lib/utils.ts
|
|
851
|
+
import { readFile, rm, stat, writeFile } from "node:fs/promises";
|
|
852
|
+
|
|
853
|
+
// packages/create-cli/src/lib/constants.ts
|
|
854
|
+
var NX_JSON_FILENAME = "nx.json";
|
|
855
|
+
var NX_JSON_CONTENT = JSON.stringify({
|
|
856
|
+
$schema: "./node_modules/nx/schemas/nx-schema.json",
|
|
857
|
+
targetDefaults: {}
|
|
858
|
+
});
|
|
859
|
+
var PROJECT_NAME = "source-root";
|
|
860
|
+
var PROJECT_JSON_FILENAME = "project.json";
|
|
861
|
+
var PROJECT_JSON_CONTENT = JSON.stringify({
|
|
862
|
+
$schema: "node_modules/nx/schemas/project-schema.json",
|
|
863
|
+
name: PROJECT_NAME
|
|
864
|
+
});
|
|
865
|
+
|
|
866
|
+
// packages/create-cli/src/lib/utils.ts
|
|
867
|
+
async function setupFile(filename, content = "") {
|
|
868
|
+
const setupResult = {
|
|
869
|
+
filename,
|
|
870
|
+
teardown: false
|
|
871
|
+
};
|
|
872
|
+
try {
|
|
873
|
+
const stats = await stat(filename);
|
|
874
|
+
if (!stats.isFile()) {
|
|
875
|
+
await writeFile(filename, content);
|
|
876
|
+
}
|
|
877
|
+
} catch (error) {
|
|
878
|
+
if (error instanceof Error && error.message.includes("no such file or directory")) {
|
|
879
|
+
await writeFile(filename, content);
|
|
880
|
+
return {
|
|
881
|
+
...setupResult,
|
|
882
|
+
teardown: true
|
|
883
|
+
};
|
|
884
|
+
} else {
|
|
885
|
+
console.error(error);
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
return setupResult;
|
|
889
|
+
}
|
|
890
|
+
function parseNxProcessOutput(output) {
|
|
891
|
+
return output.trim().replace("NX", CODE_PUSHUP_UNICODE_LOGO);
|
|
892
|
+
}
|
|
893
|
+
async function setupNxContext() {
|
|
894
|
+
const { teardown: nxJsonTeardown } = await setupFile(
|
|
895
|
+
NX_JSON_FILENAME,
|
|
896
|
+
NX_JSON_CONTENT
|
|
897
|
+
);
|
|
898
|
+
const { teardown: projectJsonTeardown } = await setupFile(
|
|
899
|
+
PROJECT_JSON_FILENAME,
|
|
900
|
+
PROJECT_JSON_CONTENT
|
|
901
|
+
);
|
|
902
|
+
const projectJsonContent = await readFile(PROJECT_JSON_FILENAME, "utf8");
|
|
903
|
+
const { name = PROJECT_NAME } = JSON.parse(projectJsonContent);
|
|
904
|
+
return {
|
|
905
|
+
nxJsonTeardown,
|
|
906
|
+
projectJsonTeardown,
|
|
907
|
+
projectName: name
|
|
908
|
+
};
|
|
909
|
+
}
|
|
910
|
+
async function teardownNxContext({
|
|
911
|
+
nxJsonTeardown,
|
|
912
|
+
projectJsonTeardown
|
|
913
|
+
}) {
|
|
914
|
+
const filesToDelete = [
|
|
915
|
+
...nxJsonTeardown ? [NX_JSON_FILENAME] : [],
|
|
916
|
+
...projectJsonTeardown ? [PROJECT_JSON_FILENAME] : []
|
|
917
|
+
];
|
|
918
|
+
await Promise.all(filesToDelete.map((file) => rm(file)));
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
// packages/create-cli/src/lib/init.ts
|
|
922
|
+
function nxPluginGenerator(generator, opt = {}) {
|
|
923
|
+
return {
|
|
924
|
+
command: "npx",
|
|
925
|
+
args: objectToCliArgs({
|
|
926
|
+
_: ["nx", "g", `@code-pushup/nx-plugin:${generator}`],
|
|
927
|
+
...opt
|
|
928
|
+
})
|
|
929
|
+
};
|
|
930
|
+
}
|
|
931
|
+
async function initCodePushup() {
|
|
932
|
+
const setupResult = await setupNxContext();
|
|
933
|
+
await executeProcess({
|
|
934
|
+
...nxPluginGenerator("init", {
|
|
935
|
+
skipNxJson: true
|
|
936
|
+
}),
|
|
937
|
+
observer: {
|
|
938
|
+
onStdout: (data) => {
|
|
939
|
+
console.info(parseNxProcessOutput(data.toString()));
|
|
940
|
+
},
|
|
941
|
+
onError: (error) => {
|
|
942
|
+
console.error(parseNxProcessOutput(error.message.toString()));
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
});
|
|
946
|
+
const { stdout: configStdout, stderr: configStderr } = await executeProcess(
|
|
947
|
+
nxPluginGenerator("configuration", {
|
|
948
|
+
skipTarget: true,
|
|
949
|
+
project: setupResult.projectName
|
|
950
|
+
})
|
|
951
|
+
);
|
|
952
|
+
console.info(parseNxProcessOutput(configStdout));
|
|
953
|
+
console.warn(parseNxProcessOutput(configStderr));
|
|
954
|
+
await teardownNxContext(setupResult);
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
// packages/create-cli/src/index.ts
|
|
958
|
+
await initCodePushup();
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@code-pushup/create-cli",
|
|
3
|
+
"version": "0.51.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"bin": "index.js",
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"@code-pushup/nx-plugin": "0.51.0",
|
|
11
|
+
"@code-pushup/utils": "0.51.0"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/code-pushup/cli/tree/main/packages/create-cli#readme",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/code-pushup/cli/issues"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/code-pushup/cli.git",
|
|
20
|
+
"directory": "packages/create-cli"
|
|
21
|
+
},
|
|
22
|
+
"type": "module",
|
|
23
|
+
"main": "./index.js",
|
|
24
|
+
"types": "./src/index.d.ts"
|
|
25
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type SetupResult = {
|
|
2
|
+
filename: string;
|
|
3
|
+
teardown: boolean;
|
|
4
|
+
};
|
|
5
|
+
export declare function setupFile(filename: string, content?: string): Promise<SetupResult>;
|
|
6
|
+
export declare function parseNxProcessOutput(output: string): string;
|
|
7
|
+
export declare function setupNxContext(): Promise<{
|
|
8
|
+
nxJsonTeardown: boolean;
|
|
9
|
+
projectJsonTeardown: boolean;
|
|
10
|
+
projectName: string;
|
|
11
|
+
}>;
|
|
12
|
+
export declare function teardownNxContext({ nxJsonTeardown, projectJsonTeardown, }: {
|
|
13
|
+
nxJsonTeardown: boolean;
|
|
14
|
+
projectJsonTeardown: boolean;
|
|
15
|
+
}): Promise<void>;
|