@code-pushup/cli 0.5.0 → 0.5.2
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
CHANGED
|
@@ -143,8 +143,8 @@ Each example is fully tested to give demonstrate best practices for plugin testi
|
|
|
143
143
|
|
|
144
144
|
**Example for custom plugins:**
|
|
145
145
|
|
|
146
|
-
- [File Size](../../examples/plugins/src/file-size)
|
|
147
|
-
- [Package Json](../../examples/plugins/src/package-json)
|
|
146
|
+
- 📏 [File Size](../../examples/plugins/src/file-size)
|
|
147
|
+
- 📦 [Package Json](../../examples/plugins/src/package-json)
|
|
148
148
|
|
|
149
149
|
## CLI commands and options
|
|
150
150
|
|
package/index.js
CHANGED
|
@@ -201,6 +201,23 @@ function getDuplicateRefsInCategoryMetrics(metrics) {
|
|
|
201
201
|
metrics.map(({ slug, type, plugin }) => `${type} :: ${plugin} / ${slug}`)
|
|
202
202
|
);
|
|
203
203
|
}
|
|
204
|
+
var categoriesSchema = z2.array(categoryConfigSchema, {
|
|
205
|
+
description: "Categorization of individual audits"
|
|
206
|
+
}).min(1).refine(
|
|
207
|
+
(categoryCfg) => !getDuplicateSlugCategories(categoryCfg),
|
|
208
|
+
(categoryCfg) => ({
|
|
209
|
+
message: duplicateSlugCategoriesErrorMsg(categoryCfg)
|
|
210
|
+
})
|
|
211
|
+
);
|
|
212
|
+
function duplicateSlugCategoriesErrorMsg(categories) {
|
|
213
|
+
const duplicateStringSlugs = getDuplicateSlugCategories(categories);
|
|
214
|
+
return `In the categories, the following slugs are duplicated: ${errorItems(
|
|
215
|
+
duplicateStringSlugs
|
|
216
|
+
)}`;
|
|
217
|
+
}
|
|
218
|
+
function getDuplicateSlugCategories(categories) {
|
|
219
|
+
return hasDuplicateStrings(categories.map(({ slug }) => slug));
|
|
220
|
+
}
|
|
204
221
|
|
|
205
222
|
// packages/models/src/lib/core-config.ts
|
|
206
223
|
import { z as z11 } from "zod";
|
|
@@ -209,10 +226,10 @@ import { z as z11 } from "zod";
|
|
|
209
226
|
import { z as z3 } from "zod";
|
|
210
227
|
var formatSchema = z3.enum(["json", "md"]);
|
|
211
228
|
var persistConfigSchema = z3.object({
|
|
212
|
-
outputDir: filePathSchema("Artifacts folder"),
|
|
213
|
-
filename: fileNameSchema(
|
|
214
|
-
"
|
|
215
|
-
),
|
|
229
|
+
outputDir: filePathSchema("Artifacts folder").optional(),
|
|
230
|
+
filename: fileNameSchema(
|
|
231
|
+
"Artifacts file name (without extension)"
|
|
232
|
+
).optional(),
|
|
216
233
|
format: z3.array(formatSchema).default(["json"]).optional()
|
|
217
234
|
// @TODO remove default or optional value and otherwise it will not set defaults.
|
|
218
235
|
});
|
|
@@ -448,17 +465,10 @@ var unrefinedCoreConfigSchema = z11.object({
|
|
|
448
465
|
description: "List of plugins to be used (official, community-provided, or custom)"
|
|
449
466
|
}),
|
|
450
467
|
/** portal configuration for persisting results */
|
|
451
|
-
persist: persistConfigSchema,
|
|
468
|
+
persist: persistConfigSchema.optional(),
|
|
452
469
|
/** portal configuration for uploading results */
|
|
453
470
|
upload: uploadConfigSchema.optional(),
|
|
454
|
-
categories:
|
|
455
|
-
description: "Categorization of individual audits"
|
|
456
|
-
}).min(1).refine(
|
|
457
|
-
(categories) => !getDuplicateSlugCategories(categories),
|
|
458
|
-
(categories) => ({
|
|
459
|
-
message: duplicateSlugCategoriesErrorMsg(categories)
|
|
460
|
-
})
|
|
461
|
-
)
|
|
471
|
+
categories: categoriesSchema
|
|
462
472
|
});
|
|
463
473
|
var coreConfigSchema = refineCoreConfig(unrefinedCoreConfigSchema);
|
|
464
474
|
function refineCoreConfig(schema) {
|
|
@@ -509,15 +519,11 @@ function getMissingRefsForCategories(coreCfg) {
|
|
|
509
519
|
}
|
|
510
520
|
return missingRefs.length ? missingRefs : false;
|
|
511
521
|
}
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
}
|
|
518
|
-
function getDuplicateSlugCategories(categories) {
|
|
519
|
-
return hasDuplicateStrings(categories.map(({ slug }) => slug));
|
|
520
|
-
}
|
|
522
|
+
|
|
523
|
+
// packages/models/src/lib/implementation/constants.ts
|
|
524
|
+
var PERSIST_OUTPUT_DIR = ".code-pushup";
|
|
525
|
+
var PERSIST_FORMAT = ["json"];
|
|
526
|
+
var PERSIST_FILENAME = "report";
|
|
521
527
|
|
|
522
528
|
// packages/models/src/lib/report.ts
|
|
523
529
|
import { z as z12 } from "zod";
|
|
@@ -1491,11 +1497,8 @@ var PersistError = class extends Error {
|
|
|
1491
1497
|
super(`fileName: ${reportPath} could not be saved.`);
|
|
1492
1498
|
}
|
|
1493
1499
|
};
|
|
1494
|
-
async function persistReport(report,
|
|
1495
|
-
const {
|
|
1496
|
-
const outputDir = persist.outputDir;
|
|
1497
|
-
const filename = persist.filename;
|
|
1498
|
-
const format = persist.format ?? [];
|
|
1500
|
+
async function persistReport(report, options2) {
|
|
1501
|
+
const { outputDir, filename, format } = options2;
|
|
1499
1502
|
let scoredReport = scoreReport(report);
|
|
1500
1503
|
console.info(reportToStdout(scoredReport));
|
|
1501
1504
|
const results = [
|
|
@@ -1650,7 +1653,7 @@ function auditOutputsCorrelateWithPluginOutput(auditOutputs, pluginConfigAudits)
|
|
|
1650
1653
|
|
|
1651
1654
|
// packages/core/package.json
|
|
1652
1655
|
var name = "@code-pushup/core";
|
|
1653
|
-
var version = "0.5.
|
|
1656
|
+
var version = "0.5.2";
|
|
1654
1657
|
|
|
1655
1658
|
// packages/core/src/lib/implementation/collect.ts
|
|
1656
1659
|
async function collect(options2) {
|
|
@@ -1748,16 +1751,23 @@ function transformSeverity(severity) {
|
|
|
1748
1751
|
}
|
|
1749
1752
|
}
|
|
1750
1753
|
|
|
1754
|
+
// packages/core/src/lib/normalize.ts
|
|
1755
|
+
var normalizePersistConfig = (cfg) => ({
|
|
1756
|
+
outputDir: PERSIST_OUTPUT_DIR,
|
|
1757
|
+
filename: PERSIST_FILENAME,
|
|
1758
|
+
format: PERSIST_FORMAT,
|
|
1759
|
+
...cfg
|
|
1760
|
+
});
|
|
1761
|
+
|
|
1751
1762
|
// packages/core/src/lib/upload.ts
|
|
1752
1763
|
async function upload(options2, uploadFn = uploadToPortal) {
|
|
1753
|
-
|
|
1754
|
-
|
|
1764
|
+
const persist = normalizePersistConfig(options2?.persist);
|
|
1765
|
+
if (!options2?.upload) {
|
|
1766
|
+
throw new Error("upload config must be set");
|
|
1755
1767
|
}
|
|
1756
1768
|
const { apiKey, server, organization, project } = options2.upload;
|
|
1757
|
-
const { outputDir, filename } = options2.persist;
|
|
1758
1769
|
const report = await loadReport({
|
|
1759
|
-
|
|
1760
|
-
filename,
|
|
1770
|
+
...persist,
|
|
1761
1771
|
format: "json"
|
|
1762
1772
|
});
|
|
1763
1773
|
const commitData = await getLatestCommit();
|
|
@@ -1777,7 +1787,8 @@ async function upload(options2, uploadFn = uploadToPortal) {
|
|
|
1777
1787
|
async function collectAndPersistReports(options2) {
|
|
1778
1788
|
const { exec } = verboseUtils(options2.verbose);
|
|
1779
1789
|
const report = await collect(options2);
|
|
1780
|
-
const
|
|
1790
|
+
const persist = normalizePersistConfig(options2?.persist);
|
|
1791
|
+
const persistResults = await persistReport(report, persist);
|
|
1781
1792
|
exec(() => logPersistedResults(persistResults));
|
|
1782
1793
|
report.plugins.forEach((plugin) => {
|
|
1783
1794
|
pluginReportSchema.parse(plugin);
|
|
@@ -1801,7 +1812,7 @@ async function readCodePushupConfig(filepath) {
|
|
|
1801
1812
|
{
|
|
1802
1813
|
filepath
|
|
1803
1814
|
},
|
|
1804
|
-
coreConfigSchema.parse
|
|
1815
|
+
(d) => coreConfigSchema.parse(d)
|
|
1805
1816
|
);
|
|
1806
1817
|
}
|
|
1807
1818
|
|
|
@@ -1971,9 +1982,13 @@ async function configMiddleware(processArgs) {
|
|
|
1971
1982
|
...importedRc.upload,
|
|
1972
1983
|
...cliOptions.upload
|
|
1973
1984
|
},
|
|
1985
|
+
// we can't use a async rc file as yargs does not support it. see: https://github.com/yargs/yargs/issues/2234
|
|
1986
|
+
// therefore this can't live in option defaults as the order would be `config`->`provided options`->default
|
|
1987
|
+
// so we have to manually implement the order
|
|
1974
1988
|
persist: {
|
|
1975
|
-
|
|
1976
|
-
|
|
1989
|
+
outputDir: cliOptions?.persist?.outputDir || importedRc?.persist?.outputDir || PERSIST_OUTPUT_DIR,
|
|
1990
|
+
filename: cliOptions?.persist?.filename || importedRc?.persist?.filename || PERSIST_FILENAME,
|
|
1991
|
+
format: cliOptions?.persist?.format || importedRc?.persist?.format || PERSIST_FORMAT
|
|
1977
1992
|
},
|
|
1978
1993
|
plugins: filterPluginsByOnlyPluginsOption(importedRc.plugins, cliOptions),
|
|
1979
1994
|
categories: filterCategoryByOnlyPluginsOption(
|
|
@@ -1992,6 +2007,14 @@ var middlewares = [
|
|
|
1992
2007
|
|
|
1993
2008
|
// packages/cli/src/lib/implementation/core-config-options.ts
|
|
1994
2009
|
function yargsCoreConfigOptionsDefinition() {
|
|
2010
|
+
return {
|
|
2011
|
+
// persist
|
|
2012
|
+
...yargsPersistConfigOptionsDefinition(),
|
|
2013
|
+
// upload
|
|
2014
|
+
...yargsUploadConfigOptionsDefinition()
|
|
2015
|
+
};
|
|
2016
|
+
}
|
|
2017
|
+
function yargsPersistConfigOptionsDefinition() {
|
|
1995
2018
|
return {
|
|
1996
2019
|
// persist
|
|
1997
2020
|
"persist.outputDir": {
|
|
@@ -2005,7 +2028,11 @@ function yargsCoreConfigOptionsDefinition() {
|
|
|
2005
2028
|
"persist.format": {
|
|
2006
2029
|
describe: "Format of the report output. e.g. `md`, `json`",
|
|
2007
2030
|
type: "array"
|
|
2008
|
-
}
|
|
2031
|
+
}
|
|
2032
|
+
};
|
|
2033
|
+
}
|
|
2034
|
+
function yargsUploadConfigOptionsDefinition() {
|
|
2035
|
+
return {
|
|
2009
2036
|
// upload
|
|
2010
2037
|
"upload.organization": {
|
|
2011
2038
|
describe: "Organization slug from portal",
|
package/package.json
CHANGED
|
@@ -197,11 +197,6 @@ export declare function configMiddleware<T extends Partial<GeneralCliOptions & C
|
|
|
197
197
|
docsUrl?: string | undefined;
|
|
198
198
|
}[] | undefined;
|
|
199
199
|
}[];
|
|
200
|
-
persist: {
|
|
201
|
-
outputDir: string;
|
|
202
|
-
filename: string;
|
|
203
|
-
format?: ("json" | "md")[] | undefined;
|
|
204
|
-
};
|
|
205
200
|
categories: {
|
|
206
201
|
title: string;
|
|
207
202
|
slug: string;
|
|
@@ -215,6 +210,11 @@ export declare function configMiddleware<T extends Partial<GeneralCliOptions & C
|
|
|
215
210
|
docsUrl?: string | undefined;
|
|
216
211
|
isBinary?: boolean | undefined;
|
|
217
212
|
}[];
|
|
213
|
+
persist?: {
|
|
214
|
+
outputDir?: string | undefined;
|
|
215
|
+
filename?: string | undefined;
|
|
216
|
+
format?: ("json" | "md")[] | undefined;
|
|
217
|
+
} | undefined;
|
|
218
218
|
upload?: {
|
|
219
219
|
server: string;
|
|
220
220
|
apiKey: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Options } from 'yargs';
|
|
2
|
-
import { CoreConfigCliOptions } from './model';
|
|
3
|
-
|
|
4
|
-
export declare function
|
|
5
|
-
export
|
|
2
|
+
import { CoreConfigCliOptions, PersistConfigCliOptions, UploadConfigCliOptions } from './model';
|
|
3
|
+
export declare function yargsCoreConfigOptionsDefinition(): Record<keyof CoreConfigCliOptions, Options>;
|
|
4
|
+
export declare function yargsPersistConfigOptionsDefinition(): Record<keyof PersistConfigCliOptions, Options>;
|
|
5
|
+
export declare function yargsUploadConfigOptionsDefinition(): Record<keyof UploadConfigCliOptions, Options>;
|