@code-pushup/cli 0.18.1 → 0.19.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/index.js +95 -58
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -971,16 +971,35 @@ function executeProcess(cfg) {
|
|
|
971
971
|
});
|
|
972
972
|
}
|
|
973
973
|
|
|
974
|
+
// packages/utils/src/lib/transform.ts
|
|
975
|
+
function toArray(val) {
|
|
976
|
+
return Array.isArray(val) ? val : [val];
|
|
977
|
+
}
|
|
978
|
+
function deepClone(obj) {
|
|
979
|
+
return obj == null || typeof obj !== "object" ? obj : structuredClone(obj);
|
|
980
|
+
}
|
|
981
|
+
function toUnixPath(path) {
|
|
982
|
+
return path.replace(/\\/g, "/");
|
|
983
|
+
}
|
|
984
|
+
|
|
974
985
|
// packages/utils/src/lib/git.ts
|
|
986
|
+
import { isAbsolute, join as join2, relative } from "node:path";
|
|
975
987
|
import { simpleGit } from "simple-git";
|
|
976
|
-
|
|
977
|
-
async function getLatestCommit() {
|
|
988
|
+
async function getLatestCommit(git = simpleGit()) {
|
|
978
989
|
const log = await git.log({
|
|
979
990
|
maxCount: 1,
|
|
980
991
|
format: { hash: "%H", message: "%s", author: "%an", date: "%ad" }
|
|
981
992
|
});
|
|
982
993
|
return log.latest;
|
|
983
994
|
}
|
|
995
|
+
function getGitRoot(git = simpleGit()) {
|
|
996
|
+
return git.revparse("--show-toplevel");
|
|
997
|
+
}
|
|
998
|
+
function formatGitPath(path, gitRoot) {
|
|
999
|
+
const absolutePath = isAbsolute(path) ? path : join2(process.cwd(), path);
|
|
1000
|
+
const relativePath = relative(gitRoot, absolutePath);
|
|
1001
|
+
return toUnixPath(relativePath);
|
|
1002
|
+
}
|
|
984
1003
|
function validateCommitData(commitData, options2 = {}) {
|
|
985
1004
|
const { throwError = false } = options2;
|
|
986
1005
|
if (!commitData) {
|
|
@@ -1003,18 +1022,24 @@ function groupByStatus(results) {
|
|
|
1003
1022
|
);
|
|
1004
1023
|
}
|
|
1005
1024
|
|
|
1006
|
-
// packages/utils/src/lib/
|
|
1025
|
+
// packages/utils/src/lib/logging.ts
|
|
1007
1026
|
import chalk2 from "chalk";
|
|
1027
|
+
function link(text) {
|
|
1028
|
+
return chalk2.underline(chalk2.blueBright(text));
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
// packages/utils/src/lib/progress.ts
|
|
1032
|
+
import chalk3 from "chalk";
|
|
1008
1033
|
import { MultiProgressBars } from "multi-progress-bars";
|
|
1009
1034
|
var barStyles = {
|
|
1010
|
-
active: (s) =>
|
|
1011
|
-
done: (s) =>
|
|
1012
|
-
idle: (s) =>
|
|
1035
|
+
active: (s) => chalk3.green(s),
|
|
1036
|
+
done: (s) => chalk3.gray(s),
|
|
1037
|
+
idle: (s) => chalk3.gray(s)
|
|
1013
1038
|
};
|
|
1014
1039
|
var messageStyles = {
|
|
1015
|
-
active: (s) =>
|
|
1016
|
-
done: (s) =>
|
|
1017
|
-
idle: (s) =>
|
|
1040
|
+
active: (s) => chalk3.black(s),
|
|
1041
|
+
done: (s) => chalk3.green(chalk3.bold(s)),
|
|
1042
|
+
idle: (s) => chalk3.gray(s)
|
|
1018
1043
|
};
|
|
1019
1044
|
var mpb;
|
|
1020
1045
|
function getSingletonProgressBars(options2) {
|
|
@@ -1094,7 +1119,7 @@ function h3(text) {
|
|
|
1094
1119
|
}
|
|
1095
1120
|
|
|
1096
1121
|
// packages/utils/src/lib/reports/md/link.ts
|
|
1097
|
-
function
|
|
1122
|
+
function link2(href, text) {
|
|
1098
1123
|
return `[${text || href}](${href})`;
|
|
1099
1124
|
}
|
|
1100
1125
|
|
|
@@ -1145,7 +1170,7 @@ function generateMdReport(report, commitData) {
|
|
|
1145
1170
|
(printCategories ? reportToCategoriesSection(report) + NEW_LINE + NEW_LINE : "") + // audits section
|
|
1146
1171
|
reportToAuditsSection(report) + NEW_LINE + NEW_LINE + // about section
|
|
1147
1172
|
reportToAboutSection(report, commitData) + NEW_LINE + NEW_LINE + // footer section
|
|
1148
|
-
`${FOOTER_PREFIX} ${
|
|
1173
|
+
`${FOOTER_PREFIX} ${link2(README_LINK, "Code PushUp")}`
|
|
1149
1174
|
);
|
|
1150
1175
|
}
|
|
1151
1176
|
function reportToHeaderSection() {
|
|
@@ -1156,7 +1181,7 @@ function reportToOverviewSection(report) {
|
|
|
1156
1181
|
const tableContent = [
|
|
1157
1182
|
reportOverviewTableHeaders,
|
|
1158
1183
|
...categories.map(({ title, refs, score }) => [
|
|
1159
|
-
|
|
1184
|
+
link2(`#${slugify(title)}`, title),
|
|
1160
1185
|
`${getRoundScoreMarker(score)} ${style(formatReportScore(score))}`,
|
|
1161
1186
|
countCategoryAudits(refs, plugins).toString()
|
|
1162
1187
|
])
|
|
@@ -1188,7 +1213,7 @@ function reportToCategoriesSection(report) {
|
|
|
1188
1213
|
}
|
|
1189
1214
|
function auditItemToCategorySection(audit, plugins) {
|
|
1190
1215
|
const pluginTitle = getPluginNameFromSlug(audit.plugin, plugins);
|
|
1191
|
-
const auditTitle =
|
|
1216
|
+
const auditTitle = link2(
|
|
1192
1217
|
`#${slugify(audit.title)}-${slugify(pluginTitle)}`,
|
|
1193
1218
|
audit.title
|
|
1194
1219
|
);
|
|
@@ -1205,7 +1230,7 @@ function groupItemToCategorySection(group, plugins) {
|
|
|
1205
1230
|
`${getRoundScoreMarker(groupScore)} ${group.title} (_${pluginTitle}_)`
|
|
1206
1231
|
);
|
|
1207
1232
|
const groupAudits = group.audits.reduce((acc, audit) => {
|
|
1208
|
-
const auditTitle =
|
|
1233
|
+
const auditTitle = link2(
|
|
1209
1234
|
`#${slugify(audit.title)}-${slugify(pluginTitle)}`,
|
|
1210
1235
|
audit.title
|
|
1211
1236
|
);
|
|
@@ -1292,7 +1317,7 @@ function getDocsAndDescription({
|
|
|
1292
1317
|
description
|
|
1293
1318
|
}) {
|
|
1294
1319
|
if (docsUrl) {
|
|
1295
|
-
const docsLink =
|
|
1320
|
+
const docsLink = link2(docsUrl, "\u{1F4D6} Docs");
|
|
1296
1321
|
if (!description) {
|
|
1297
1322
|
return docsLink + NEW_LINE + NEW_LINE;
|
|
1298
1323
|
}
|
|
@@ -1313,7 +1338,7 @@ function getAuditResult(audit, isHtml = false) {
|
|
|
1313
1338
|
|
|
1314
1339
|
// packages/utils/src/lib/reports/generate-stdout-summary.ts
|
|
1315
1340
|
import cliui from "@isaacs/cliui";
|
|
1316
|
-
import
|
|
1341
|
+
import chalk4 from "chalk";
|
|
1317
1342
|
import CliTable3 from "cli-table3";
|
|
1318
1343
|
function addLine(line = "") {
|
|
1319
1344
|
return line + NEW_LINE;
|
|
@@ -1324,7 +1349,7 @@ function generateStdoutSummary(report) {
|
|
|
1324
1349
|
}
|
|
1325
1350
|
function reportToHeaderSection2(report) {
|
|
1326
1351
|
const { packageName, version: version2 } = report;
|
|
1327
|
-
return `${
|
|
1352
|
+
return `${chalk4.bold(reportHeadlineText)} - ${packageName}@${version2}`;
|
|
1328
1353
|
}
|
|
1329
1354
|
function reportToDetailSection(report) {
|
|
1330
1355
|
const { plugins } = report;
|
|
@@ -1344,13 +1369,13 @@ function reportToDetailSection(report) {
|
|
|
1344
1369
|
padding: [0, 3, 0, 0]
|
|
1345
1370
|
},
|
|
1346
1371
|
{
|
|
1347
|
-
text:
|
|
1372
|
+
text: chalk4.cyanBright(audit.displayValue || `${audit.value}`),
|
|
1348
1373
|
width: 10,
|
|
1349
1374
|
padding: [0, 0, 0, 0]
|
|
1350
1375
|
}
|
|
1351
1376
|
);
|
|
1352
1377
|
});
|
|
1353
|
-
return acc + addLine() + addLine(
|
|
1378
|
+
return acc + addLine() + addLine(chalk4.magentaBright.bold(`${title} audits`)) + addLine() + addLine(ui2.toString()) + addLine();
|
|
1354
1379
|
}, "");
|
|
1355
1380
|
}
|
|
1356
1381
|
function reportToOverviewSection2({
|
|
@@ -1373,11 +1398,11 @@ function reportToOverviewSection2({
|
|
|
1373
1398
|
countCategoryAudits(refs, plugins)
|
|
1374
1399
|
])
|
|
1375
1400
|
);
|
|
1376
|
-
return addLine(
|
|
1401
|
+
return addLine(chalk4.magentaBright.bold("Categories")) + addLine() + addLine(table.toString());
|
|
1377
1402
|
}
|
|
1378
1403
|
function withColor({ score, text }) {
|
|
1379
1404
|
const formattedScore = text ?? formatReportScore(score);
|
|
1380
|
-
const style2 = text ?
|
|
1405
|
+
const style2 = text ? chalk4 : chalk4.bold;
|
|
1381
1406
|
if (score >= SCORE_COLOR_RANGE.GREEN_MIN) {
|
|
1382
1407
|
return style2.green(formattedScore);
|
|
1383
1408
|
}
|
|
@@ -1387,14 +1412,6 @@ function withColor({ score, text }) {
|
|
|
1387
1412
|
return style2.red(formattedScore);
|
|
1388
1413
|
}
|
|
1389
1414
|
|
|
1390
|
-
// packages/utils/src/lib/transform.ts
|
|
1391
|
-
function toArray(val) {
|
|
1392
|
-
return Array.isArray(val) ? val : [val];
|
|
1393
|
-
}
|
|
1394
|
-
function deepClone(obj) {
|
|
1395
|
-
return obj == null || typeof obj !== "object" ? obj : structuredClone(obj);
|
|
1396
|
-
}
|
|
1397
|
-
|
|
1398
1415
|
// packages/utils/src/lib/reports/scoring.ts
|
|
1399
1416
|
var GroupRefInvalidError = class extends Error {
|
|
1400
1417
|
constructor(auditSlug, pluginSlug) {
|
|
@@ -1555,21 +1572,48 @@ var verboseUtils = (verbose = false) => ({
|
|
|
1555
1572
|
exec: getExecVerbose(verbose)
|
|
1556
1573
|
});
|
|
1557
1574
|
|
|
1558
|
-
// packages/utils/src/lib/logging.ts
|
|
1559
|
-
import chalk4 from "chalk";
|
|
1560
|
-
function link2(text) {
|
|
1561
|
-
return chalk4.underline(chalk4.blueBright(text));
|
|
1562
|
-
}
|
|
1563
|
-
|
|
1564
1575
|
// packages/core/package.json
|
|
1565
1576
|
var name = "@code-pushup/core";
|
|
1566
|
-
var version = "0.
|
|
1577
|
+
var version = "0.19.0";
|
|
1567
1578
|
|
|
1568
1579
|
// packages/core/src/lib/implementation/execute-plugin.ts
|
|
1569
1580
|
import chalk5 from "chalk";
|
|
1570
1581
|
|
|
1582
|
+
// packages/core/src/lib/normalize.ts
|
|
1583
|
+
function normalizePersistConfig(cfg) {
|
|
1584
|
+
return {
|
|
1585
|
+
outputDir: PERSIST_OUTPUT_DIR,
|
|
1586
|
+
filename: PERSIST_FILENAME,
|
|
1587
|
+
format: PERSIST_FORMAT,
|
|
1588
|
+
...cfg
|
|
1589
|
+
};
|
|
1590
|
+
}
|
|
1591
|
+
async function normalizeAuditOutputs(audits) {
|
|
1592
|
+
const gitRoot = await getGitRoot();
|
|
1593
|
+
return audits.map((audit) => {
|
|
1594
|
+
if (audit.details?.issues == null || audit.details.issues.every((issue) => issue.source == null)) {
|
|
1595
|
+
return audit;
|
|
1596
|
+
}
|
|
1597
|
+
return {
|
|
1598
|
+
...audit,
|
|
1599
|
+
details: {
|
|
1600
|
+
...audit.details,
|
|
1601
|
+
issues: audit.details.issues.map(
|
|
1602
|
+
(issue) => issue.source == null ? issue : {
|
|
1603
|
+
...issue,
|
|
1604
|
+
source: {
|
|
1605
|
+
...issue.source,
|
|
1606
|
+
file: formatGitPath(issue.source.file, gitRoot)
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
)
|
|
1610
|
+
}
|
|
1611
|
+
};
|
|
1612
|
+
});
|
|
1613
|
+
}
|
|
1614
|
+
|
|
1571
1615
|
// packages/core/src/lib/implementation/runner.ts
|
|
1572
|
-
import { join as
|
|
1616
|
+
import { join as join3 } from "node:path";
|
|
1573
1617
|
async function executeRunnerConfig(cfg, onProgress) {
|
|
1574
1618
|
const { args, command, outputFile, outputTransform } = cfg;
|
|
1575
1619
|
const { duration, date } = await executeProcess({
|
|
@@ -1577,7 +1621,7 @@ async function executeRunnerConfig(cfg, onProgress) {
|
|
|
1577
1621
|
args,
|
|
1578
1622
|
observer: { onStdout: onProgress }
|
|
1579
1623
|
});
|
|
1580
|
-
const outputs = await readJsonFile(
|
|
1624
|
+
const outputs = await readJsonFile(join3(process.cwd(), outputFile));
|
|
1581
1625
|
const audits = outputTransform ? await outputTransform(outputs) : outputs;
|
|
1582
1626
|
return {
|
|
1583
1627
|
duration,
|
|
@@ -1615,7 +1659,8 @@ async function executePlugin(pluginConfig, onProgress) {
|
|
|
1615
1659
|
const { audits: unvalidatedAuditOutputs, ...executionMeta } = runnerResult;
|
|
1616
1660
|
const auditOutputs = auditOutputsSchema.parse(unvalidatedAuditOutputs);
|
|
1617
1661
|
auditOutputsCorrelateWithPluginOutput(auditOutputs, pluginConfigAudits);
|
|
1618
|
-
const
|
|
1662
|
+
const normalizedAuditOutputs = await normalizeAuditOutputs(auditOutputs);
|
|
1663
|
+
const auditReports = normalizedAuditOutputs.map(
|
|
1619
1664
|
(auditOutput) => ({
|
|
1620
1665
|
...auditOutput,
|
|
1621
1666
|
...pluginConfigAudits.find(
|
|
@@ -1693,7 +1738,7 @@ async function collect(options2) {
|
|
|
1693
1738
|
|
|
1694
1739
|
// packages/core/src/lib/implementation/persist.ts
|
|
1695
1740
|
import { mkdir as mkdir2, stat as stat2, writeFile } from "node:fs/promises";
|
|
1696
|
-
import { join as
|
|
1741
|
+
import { join as join4 } from "node:path";
|
|
1697
1742
|
var PersistDirError = class extends Error {
|
|
1698
1743
|
constructor(outputDir) {
|
|
1699
1744
|
super(`outPath: ${outputDir} is no directory.`);
|
|
@@ -1737,7 +1782,7 @@ async function persistReport(report, options2) {
|
|
|
1737
1782
|
return Promise.allSettled(
|
|
1738
1783
|
results.map(
|
|
1739
1784
|
(result) => persistResult(
|
|
1740
|
-
|
|
1785
|
+
join4(outputDir, `${filename}.${result.format}`),
|
|
1741
1786
|
result.content
|
|
1742
1787
|
)
|
|
1743
1788
|
)
|
|
@@ -1753,14 +1798,6 @@ function logPersistedResults(persistResults) {
|
|
|
1753
1798
|
logMultipleFileResults(persistResults, "Generated reports");
|
|
1754
1799
|
}
|
|
1755
1800
|
|
|
1756
|
-
// packages/core/src/lib/normalize.ts
|
|
1757
|
-
var normalizePersistConfig = (cfg) => ({
|
|
1758
|
-
outputDir: PERSIST_OUTPUT_DIR,
|
|
1759
|
-
filename: PERSIST_FILENAME,
|
|
1760
|
-
format: PERSIST_FORMAT,
|
|
1761
|
-
...cfg
|
|
1762
|
-
});
|
|
1763
|
-
|
|
1764
1801
|
// packages/core/src/lib/collect-and-persist.ts
|
|
1765
1802
|
async function collectAndPersistReports(options2) {
|
|
1766
1803
|
const { exec } = verboseUtils(options2.verbose);
|
|
@@ -1776,7 +1813,7 @@ async function collectAndPersistReports(options2) {
|
|
|
1776
1813
|
}
|
|
1777
1814
|
|
|
1778
1815
|
// packages/core/src/lib/implementation/read-rc-file.ts
|
|
1779
|
-
import { join as
|
|
1816
|
+
import { join as join5 } from "node:path";
|
|
1780
1817
|
var ConfigPathError = class extends Error {
|
|
1781
1818
|
constructor(configPath) {
|
|
1782
1819
|
super(`Provided path '${configPath}' is not valid.`);
|
|
@@ -1809,7 +1846,7 @@ async function autoloadRc() {
|
|
|
1809
1846
|
)}) present in ${process.cwd()}`
|
|
1810
1847
|
);
|
|
1811
1848
|
}
|
|
1812
|
-
return readRcByPath(
|
|
1849
|
+
return readRcByPath(join5(process.cwd(), `${CONFIG_FILE_NAME}.${ext}`));
|
|
1813
1850
|
}
|
|
1814
1851
|
|
|
1815
1852
|
// packages/core/src/lib/upload.ts
|
|
@@ -1961,7 +1998,7 @@ function ui() {
|
|
|
1961
1998
|
function renderConfigureCategoriesHint() {
|
|
1962
1999
|
ui().logger.info(
|
|
1963
2000
|
chalk6.gray(
|
|
1964
|
-
`\u{1F4A1} Configure categories to see the scores in an overview table. See: ${
|
|
2001
|
+
`\u{1F4A1} Configure categories to see the scores in an overview table. See: ${link(
|
|
1965
2002
|
"https://github.com/code-pushup/cli/blob/main/packages/cli/README.md"
|
|
1966
2003
|
)}`
|
|
1967
2004
|
)
|
|
@@ -1970,7 +2007,7 @@ function renderConfigureCategoriesHint() {
|
|
|
1970
2007
|
function uploadSuccessfulLog(options2, commit) {
|
|
1971
2008
|
ui().logger.success("Upload successful!");
|
|
1972
2009
|
ui().logger.success(
|
|
1973
|
-
|
|
2010
|
+
link(
|
|
1974
2011
|
// @TODO extend config to maintain baseUrl under upload
|
|
1975
2012
|
portalCommitDashboardLink(
|
|
1976
2013
|
{ ...options2, baseUrl: "<YOUR_PORTAL_URL>" },
|
|
@@ -1988,15 +2025,15 @@ function renderIntegratePortalHint() {
|
|
|
1988
2025
|
"npx code-pushup upload"
|
|
1989
2026
|
)}`
|
|
1990
2027
|
).add(
|
|
1991
|
-
` ${
|
|
2028
|
+
` ${link(
|
|
1992
2029
|
"https://github.com/code-pushup/cli/tree/main/packages/cli#upload-command"
|
|
1993
2030
|
)}`
|
|
1994
2031
|
).add(
|
|
1995
|
-
`${chalk6.gray("\u276F")} ${chalk6.gray("Portal Integration")} - ${
|
|
2032
|
+
`${chalk6.gray("\u276F")} ${chalk6.gray("Portal Integration")} - ${link(
|
|
1996
2033
|
"https://github.com/code-pushup/cli/blob/main/packages/cli/README.md#portal-integration"
|
|
1997
2034
|
)}`
|
|
1998
2035
|
).add(
|
|
1999
|
-
`${chalk6.gray("\u276F")} ${chalk6.gray("Upload Command")} - ${
|
|
2036
|
+
`${chalk6.gray("\u276F")} ${chalk6.gray("Upload Command")} - ${link(
|
|
2000
2037
|
"https://github.com/code-pushup/cli/blob/main/packages/cli/README.md#portal-integration"
|
|
2001
2038
|
)}`
|
|
2002
2039
|
).render();
|
|
@@ -2111,7 +2148,7 @@ function renderUploadAutorunHint() {
|
|
|
2111
2148
|
"Run upload to upload the created report to the server"
|
|
2112
2149
|
)}`
|
|
2113
2150
|
).add(
|
|
2114
|
-
` ${
|
|
2151
|
+
` ${link(
|
|
2115
2152
|
"https://github.com/code-pushup/cli/tree/main/packages/cli#upload-command"
|
|
2116
2153
|
)}`
|
|
2117
2154
|
).add(
|
|
@@ -2119,7 +2156,7 @@ function renderUploadAutorunHint() {
|
|
|
2119
2156
|
"Run collect & upload"
|
|
2120
2157
|
)}`
|
|
2121
2158
|
).add(
|
|
2122
|
-
` ${
|
|
2159
|
+
` ${link(
|
|
2123
2160
|
"https://github.com/code-pushup/cli/tree/main/packages/cli#autorun-command"
|
|
2124
2161
|
)}`
|
|
2125
2162
|
).render();
|