@code-pushup/utils 0.1.1 → 0.2.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 +71 -62
- package/package.json +1 -1
- package/src/index.d.ts +6 -6
- package/src/lib/file-system.d.ts +3 -2
package/index.js
CHANGED
|
@@ -606,6 +606,22 @@ function logPromiseResults(results, logMessage, callback) {
|
|
|
606
606
|
}
|
|
607
607
|
|
|
608
608
|
// packages/utils/src/lib/file-system.ts
|
|
609
|
+
async function readTextFile(path) {
|
|
610
|
+
const buffer = await readFile(path);
|
|
611
|
+
return buffer.toString();
|
|
612
|
+
}
|
|
613
|
+
async function readJsonFile(path) {
|
|
614
|
+
const text = await readTextFile(path);
|
|
615
|
+
return JSON.parse(text);
|
|
616
|
+
}
|
|
617
|
+
async function fileExists(path) {
|
|
618
|
+
try {
|
|
619
|
+
const stats = await stat(path);
|
|
620
|
+
return stats.isFile();
|
|
621
|
+
} catch {
|
|
622
|
+
return false;
|
|
623
|
+
}
|
|
624
|
+
}
|
|
609
625
|
function toUnixPath(path, options) {
|
|
610
626
|
const unixPath = path.replace(/\\/g, "/");
|
|
611
627
|
if (options?.toRelative) {
|
|
@@ -624,14 +640,6 @@ async function ensureDirectoryExists(baseDir) {
|
|
|
624
640
|
}
|
|
625
641
|
}
|
|
626
642
|
}
|
|
627
|
-
async function readTextFile(path) {
|
|
628
|
-
const buffer = await readFile(path);
|
|
629
|
-
return buffer.toString();
|
|
630
|
-
}
|
|
631
|
-
async function readJsonFile(path) {
|
|
632
|
-
const text = await readTextFile(path);
|
|
633
|
-
return JSON.parse(text);
|
|
634
|
-
}
|
|
635
643
|
function logMultipleFileResults(fileResults, messagePrefix) {
|
|
636
644
|
const succeededCallback = (result) => {
|
|
637
645
|
const [fileName, size] = result.value;
|
|
@@ -968,60 +976,6 @@ async function getLatestCommit() {
|
|
|
968
976
|
return log?.latest;
|
|
969
977
|
}
|
|
970
978
|
|
|
971
|
-
// packages/utils/src/lib/progress.ts
|
|
972
|
-
import chalk2 from "chalk";
|
|
973
|
-
import { MultiProgressBars } from "multi-progress-bars";
|
|
974
|
-
var barStyles = {
|
|
975
|
-
active: (s) => chalk2.green(s),
|
|
976
|
-
done: (s) => chalk2.gray(s),
|
|
977
|
-
idle: (s) => chalk2.gray(s)
|
|
978
|
-
};
|
|
979
|
-
var messageStyles = {
|
|
980
|
-
active: (s) => chalk2.black(s),
|
|
981
|
-
done: (s) => chalk2.green(chalk2.bold(s)),
|
|
982
|
-
idle: (s) => chalk2.gray(s)
|
|
983
|
-
};
|
|
984
|
-
var mpb;
|
|
985
|
-
function getSingletonProgressBars(options) {
|
|
986
|
-
if (!mpb) {
|
|
987
|
-
mpb = new MultiProgressBars({
|
|
988
|
-
initMessage: "",
|
|
989
|
-
border: true,
|
|
990
|
-
...options
|
|
991
|
-
});
|
|
992
|
-
}
|
|
993
|
-
return mpb;
|
|
994
|
-
}
|
|
995
|
-
function getProgressBar(taskName) {
|
|
996
|
-
const tasks = getSingletonProgressBars();
|
|
997
|
-
tasks.addTask(taskName, {
|
|
998
|
-
type: "percentage",
|
|
999
|
-
percentage: 0,
|
|
1000
|
-
message: "",
|
|
1001
|
-
barTransformFn: barStyles.idle
|
|
1002
|
-
});
|
|
1003
|
-
return {
|
|
1004
|
-
incrementInSteps: (numPlugins) => {
|
|
1005
|
-
tasks.incrementTask(taskName, {
|
|
1006
|
-
percentage: 1 / numPlugins,
|
|
1007
|
-
barTransformFn: barStyles.active
|
|
1008
|
-
});
|
|
1009
|
-
},
|
|
1010
|
-
updateTitle: (title) => {
|
|
1011
|
-
tasks.updateTask(taskName, {
|
|
1012
|
-
message: title,
|
|
1013
|
-
barTransformFn: barStyles.active
|
|
1014
|
-
});
|
|
1015
|
-
},
|
|
1016
|
-
endProgress: (message = "") => {
|
|
1017
|
-
tasks.done(taskName, {
|
|
1018
|
-
message: messageStyles.done(message),
|
|
1019
|
-
barTransformFn: barStyles.done
|
|
1020
|
-
});
|
|
1021
|
-
}
|
|
1022
|
-
};
|
|
1023
|
-
}
|
|
1024
|
-
|
|
1025
979
|
// packages/utils/src/lib/md/details.ts
|
|
1026
980
|
function details(title, content, cfg = { open: false }) {
|
|
1027
981
|
return `<details${cfg.open ? " open" : ""}>
|
|
@@ -1099,6 +1053,60 @@ function li(text, order = "unordered") {
|
|
|
1099
1053
|
return `${style2} ${text}`;
|
|
1100
1054
|
}
|
|
1101
1055
|
|
|
1056
|
+
// packages/utils/src/lib/progress.ts
|
|
1057
|
+
import chalk2 from "chalk";
|
|
1058
|
+
import { MultiProgressBars } from "multi-progress-bars";
|
|
1059
|
+
var barStyles = {
|
|
1060
|
+
active: (s) => chalk2.green(s),
|
|
1061
|
+
done: (s) => chalk2.gray(s),
|
|
1062
|
+
idle: (s) => chalk2.gray(s)
|
|
1063
|
+
};
|
|
1064
|
+
var messageStyles = {
|
|
1065
|
+
active: (s) => chalk2.black(s),
|
|
1066
|
+
done: (s) => chalk2.green(chalk2.bold(s)),
|
|
1067
|
+
idle: (s) => chalk2.gray(s)
|
|
1068
|
+
};
|
|
1069
|
+
var mpb;
|
|
1070
|
+
function getSingletonProgressBars(options) {
|
|
1071
|
+
if (!mpb) {
|
|
1072
|
+
mpb = new MultiProgressBars({
|
|
1073
|
+
initMessage: "",
|
|
1074
|
+
border: true,
|
|
1075
|
+
...options
|
|
1076
|
+
});
|
|
1077
|
+
}
|
|
1078
|
+
return mpb;
|
|
1079
|
+
}
|
|
1080
|
+
function getProgressBar(taskName) {
|
|
1081
|
+
const tasks = getSingletonProgressBars();
|
|
1082
|
+
tasks.addTask(taskName, {
|
|
1083
|
+
type: "percentage",
|
|
1084
|
+
percentage: 0,
|
|
1085
|
+
message: "",
|
|
1086
|
+
barTransformFn: barStyles.idle
|
|
1087
|
+
});
|
|
1088
|
+
return {
|
|
1089
|
+
incrementInSteps: (numPlugins) => {
|
|
1090
|
+
tasks.incrementTask(taskName, {
|
|
1091
|
+
percentage: 1 / numPlugins,
|
|
1092
|
+
barTransformFn: barStyles.active
|
|
1093
|
+
});
|
|
1094
|
+
},
|
|
1095
|
+
updateTitle: (title) => {
|
|
1096
|
+
tasks.updateTask(taskName, {
|
|
1097
|
+
message: title,
|
|
1098
|
+
barTransformFn: barStyles.active
|
|
1099
|
+
});
|
|
1100
|
+
},
|
|
1101
|
+
endProgress: (message = "") => {
|
|
1102
|
+
tasks.done(taskName, {
|
|
1103
|
+
message: messageStyles.done(message),
|
|
1104
|
+
barTransformFn: barStyles.done
|
|
1105
|
+
});
|
|
1106
|
+
}
|
|
1107
|
+
};
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1102
1110
|
// packages/utils/src/lib/report-to-md.ts
|
|
1103
1111
|
function reportToMd(report, commitData) {
|
|
1104
1112
|
let md = reportToHeaderSection() + NEW_LINE;
|
|
@@ -1509,6 +1517,7 @@ export {
|
|
|
1509
1517
|
ensureDirectoryExists,
|
|
1510
1518
|
executeProcess,
|
|
1511
1519
|
factorOf,
|
|
1520
|
+
fileExists,
|
|
1512
1521
|
findLineNumberInText,
|
|
1513
1522
|
formatBytes,
|
|
1514
1523
|
formatDuration,
|
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
export { CliArgsObject, ProcessConfig, ProcessError, ProcessObserver, ProcessResult, executeProcess, objectToCliArgs, } from './lib/execute-process';
|
|
2
|
+
export { FileResult, MultipleFileResults, crawlFileSystem, ensureDirectoryExists, fileExists, findLineNumberInText, importEsmModule, logMultipleFileResults, pluginWorkDir, readJsonFile, readTextFile, toUnixPath, } from './lib/file-system';
|
|
3
|
+
export { formatBytes, formatDuration, pluralize, pluralizeToken, slugify, } from './lib/formatting';
|
|
2
4
|
export { getLatestCommit, git } from './lib/git';
|
|
5
|
+
export { isPromiseFulfilledResult, isPromiseRejectedResult, } from './lib/guards';
|
|
6
|
+
export { logMultipleResults } from './lib/log-results';
|
|
7
|
+
export { NEW_LINE } from './lib/md';
|
|
3
8
|
export { ProgressBar, getProgressBar } from './lib/progress';
|
|
4
9
|
export { CODE_PUSHUP_DOMAIN, FOOTER_PREFIX, README_LINK, calcDuration, compareIssueSeverity, loadReport, } from './lib/report';
|
|
5
10
|
export { reportToMd } from './lib/report-to-md';
|
|
6
11
|
export { reportToStdout } from './lib/report-to-stdout';
|
|
7
12
|
export { ScoredReport, scoreReport } from './lib/scoring';
|
|
8
|
-
export {
|
|
13
|
+
export { countOccurrences, distinct, factorOf, objectToEntries, objectToKeys, toArray, } from './lib/transformation';
|
|
9
14
|
export { verboseUtils } from './lib/verbose-utils';
|
|
10
|
-
export { toArray, objectToKeys, objectToEntries, countOccurrences, distinct, factorOf, } from './lib/transformation';
|
|
11
|
-
export { slugify, pluralize, pluralizeToken, formatBytes, formatDuration, } from './lib/formatting';
|
|
12
|
-
export { NEW_LINE } from './lib/md';
|
|
13
|
-
export { logMultipleResults } from './lib/log-results';
|
|
14
|
-
export { isPromiseFulfilledResult, isPromiseRejectedResult, } from './lib/guards';
|
package/src/lib/file-system.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { type Options } from 'bundle-require';
|
|
2
|
+
export declare function readTextFile(path: string): Promise<string>;
|
|
3
|
+
export declare function readJsonFile<T = unknown>(path: string): Promise<T>;
|
|
4
|
+
export declare function fileExists(path: string): Promise<boolean>;
|
|
2
5
|
export declare function toUnixPath(path: string, options?: {
|
|
3
6
|
toRelative?: boolean;
|
|
4
7
|
}): string;
|
|
5
8
|
export declare function ensureDirectoryExists(baseDir: string): Promise<void>;
|
|
6
|
-
export declare function readTextFile(path: string): Promise<string>;
|
|
7
|
-
export declare function readJsonFile<T = unknown>(path: string): Promise<T>;
|
|
8
9
|
export type FileResult = readonly [string] | readonly [string, number];
|
|
9
10
|
export type MultipleFileResults = PromiseSettledResult<FileResult>[];
|
|
10
11
|
export declare function logMultipleFileResults(fileResults: MultipleFileResults, messagePrefix: string): void;
|