lighthouse-badges 1.4.5 → 1.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 +1 -1
- package/bun.lock +747 -0
- package/package.json +8 -8
- package/src/argparser.d.ts +2 -2
- package/src/argparser.d.ts.map +1 -1
- package/src/argparser.js +8 -32
- package/src/argparser.js.map +1 -1
- package/src/calculations.d.ts.map +1 -1
- package/src/calculations.js +21 -65
- package/src/calculations.js.map +1 -1
- package/src/index.js +2 -2
- package/src/index.js.map +1 -1
- package/src/lighthouse-badges.d.ts +3 -3
- package/src/lighthouse-badges.d.ts.map +1 -1
- package/src/lighthouse-badges.js +40 -137
- package/src/lighthouse-badges.js.map +1 -1
- package/src/main.d.ts.map +1 -1
- package/src/main.js +9 -21
- package/src/main.js.map +1 -1
- package/src/types.d.ts +6 -12
- package/src/types.d.ts.map +1 -1
- package/src/util.d.ts +0 -2
- package/src/util.d.ts.map +1 -1
- package/src/util.js +4 -17
- package/src/util.js.map +1 -1
- package/src/argparse.d.ts +0 -27
- package/src/ramda.d.ts +0 -32
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lighthouse-badges",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.2",
|
|
4
4
|
"description": "🚦Generate gh-badges (shields.io) based on Lighthouse performance.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"build": "bun run build:prepare && bun run build:compile && bun run build:copy-declarations",
|
|
15
15
|
"build:compile": "tsc",
|
|
16
16
|
"build:copy-declarations": "cp src/*.d.ts dist/src/ 2>/dev/null || true",
|
|
17
|
-
"build:prepare": "bun run clean && mkdir -p dist &&
|
|
18
|
-
"ci:publish": "
|
|
17
|
+
"build:prepare": "bun run clean && mkdir -p dist && jq '.main = \"src/index.js\" | .bin[\"lighthouse-badges\"] = \"src/index.js\"' package.json > dist/package.json && cp README.md LICENSE.md bun.lock dist/",
|
|
18
|
+
"ci:publish": "cd dist && npm publish",
|
|
19
19
|
"clean": "rm -rf *.svg *.html coverage dist results",
|
|
20
20
|
"docker:build": "bun run build && docker build --build-arg VCS_REF=`git rev-parse --short HEAD` --build-arg BUILD_DATE=`date -u +\"%Y-%m-%dT%H:%M:%SZ\"` --build-arg VERSION=latest -t emazzotta/lighthouse-badges .",
|
|
21
21
|
"docker:system-test:run": "docker run emazzotta/lighthouse-badges /bin/sh -c 'lighthouse-badges -rsu https://google.com && cd /home/lighthouse && EXEC_PATH=/home/chrome/reports bun run system-test:verify'",
|
|
@@ -52,14 +52,14 @@
|
|
|
52
52
|
"badge-maker": "^5.0.2",
|
|
53
53
|
"chrome-launcher": "1.2.1",
|
|
54
54
|
"clui": "^0.3.6",
|
|
55
|
-
"lighthouse": "^13.1.0"
|
|
56
|
-
"ramda": "^0.32.0"
|
|
55
|
+
"lighthouse": "^13.1.0"
|
|
57
56
|
},
|
|
58
57
|
"devDependencies": {
|
|
59
58
|
"@eslint/js": "^10.0.1",
|
|
60
|
-
"@types/
|
|
61
|
-
"@
|
|
62
|
-
"@typescript-eslint/
|
|
59
|
+
"@types/argparse": "^2.0.17",
|
|
60
|
+
"@types/node": "^25.6.0",
|
|
61
|
+
"@typescript-eslint/eslint-plugin": "^8.58.1",
|
|
62
|
+
"@typescript-eslint/parser": "^8.58.1",
|
|
63
63
|
"eslint": "^10.2.0",
|
|
64
64
|
"globals": "^17.4.0",
|
|
65
65
|
"husky": "^9.1.7",
|
package/src/argparser.d.ts
CHANGED
package/src/argparser.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"argparser.d.ts","sourceRoot":"","sources":["../../src/argparser.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"argparser.d.ts","sourceRoot":"","sources":["../../src/argparser.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;;wBAmDvB,MAAM,EAAE,KAAG,UAAU;;AAD3C,wBAEE"}
|
package/src/argparser.js
CHANGED
|
@@ -1,68 +1,44 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { fileURLToPath } from 'url';
|
|
4
1
|
import { ArgumentParser } from 'argparse';
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const getPackageVersion = () => {
|
|
8
|
-
const packageJsonPath = path.join(__dirname, '../package.json');
|
|
9
|
-
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
10
|
-
return packageJson.version;
|
|
11
|
-
};
|
|
2
|
+
import packageJson from '../package.json' with { type: 'json' };
|
|
3
|
+
const BADGE_STYLES = ['flat', 'flat-square', 'plastic', 'for-the-badge', 'social'];
|
|
12
4
|
const createParser = () => {
|
|
13
5
|
const parser = new ArgumentParser({
|
|
14
6
|
description: 'Generate gh-badges (shields.io) based on lighthouse performance.',
|
|
15
7
|
add_help: true,
|
|
16
8
|
});
|
|
17
|
-
addVersionArgument(parser);
|
|
18
|
-
addOptionalArguments(parser);
|
|
19
|
-
addRequiredArguments(parser);
|
|
20
|
-
return parser;
|
|
21
|
-
};
|
|
22
|
-
const addVersionArgument = (parser) => {
|
|
23
9
|
parser.add_argument('-v', '--version', {
|
|
24
10
|
action: 'version',
|
|
25
|
-
version:
|
|
11
|
+
version: packageJson.version,
|
|
26
12
|
help: 'Show the version of the tool',
|
|
27
13
|
});
|
|
28
|
-
};
|
|
29
|
-
const addOptionalArguments = (parser) => {
|
|
30
14
|
parser.add_argument('-s', '--single-badge', {
|
|
31
15
|
action: 'store_true',
|
|
32
|
-
|
|
33
|
-
help: 'Output only one single badge averaging all lighthouse categories\' scores',
|
|
16
|
+
help: "Output only one single badge averaging all lighthouse categories' scores",
|
|
34
17
|
});
|
|
35
18
|
parser.add_argument('-b', '--badge-style', {
|
|
36
19
|
action: 'store',
|
|
37
|
-
|
|
38
|
-
choices: ['flat', 'flat-square', 'plastic', 'for-the-badge', 'social'],
|
|
20
|
+
choices: BADGE_STYLES,
|
|
39
21
|
default: 'flat',
|
|
40
22
|
help: 'Define look and feel for the badge',
|
|
41
23
|
});
|
|
42
24
|
parser.add_argument('-o', '--output-path', {
|
|
43
25
|
action: 'store',
|
|
44
|
-
required: false,
|
|
45
26
|
help: 'Define output path for artifacts',
|
|
46
27
|
});
|
|
47
28
|
parser.add_argument('-r', '--save-report', {
|
|
48
29
|
action: 'store_true',
|
|
49
|
-
required: false,
|
|
50
30
|
help: 'Save lighthouse report as html for every supplied url',
|
|
51
31
|
});
|
|
52
|
-
};
|
|
53
|
-
const addRequiredArguments = (parser) => {
|
|
54
32
|
const requiredArgs = parser.add_argument_group({ title: 'Required arguments' });
|
|
55
33
|
requiredArgs.add_argument('-u', '--url', {
|
|
56
34
|
action: 'store',
|
|
57
35
|
required: true,
|
|
58
36
|
help: 'The lighthouse badge(s) will contain the score(s) of the supplied url',
|
|
59
37
|
});
|
|
38
|
+
return parser;
|
|
60
39
|
};
|
|
61
40
|
const parser = createParser();
|
|
62
|
-
|
|
63
|
-
parse_args: (args) =>
|
|
64
|
-
return parser.parse_args(args);
|
|
65
|
-
},
|
|
41
|
+
export default {
|
|
42
|
+
parse_args: (args) => parser.parse_args(args),
|
|
66
43
|
};
|
|
67
|
-
export default typedParser;
|
|
68
44
|
//# sourceMappingURL=argparser.js.map
|
package/src/argparser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"argparser.js","sourceRoot":"","sources":["../../src/argparser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"argparser.js","sourceRoot":"","sources":["../../src/argparser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,WAAW,MAAM,iBAAiB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAGhE,M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MAAM,MAAM,GAAG,YAAY,EAAE,CAAC;AAE9B,eAAe;IACb,UAAU,EAAE,CAAC,IAAe,EAAc,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAA0B;CAC9F,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calculations.d.ts","sourceRoot":"","sources":["../../src/calculations.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"calculations.d.ts","sourceRoot":"","sources":["../../src/calculations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAYpD,eAAO,MAAM,iBAAiB,GAAI,YAAY,MAAM,KAAG,MAC6B,CAAC;AAOrF,eAAO,MAAM,eAAe,GAAI,SAAS,iBAAiB,EAAE,KAAG,iBAO9D,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,SAAS,iBAAiB,EAAE,KAAG,iBAY/D,CAAC"}
|
package/src/calculations.js
CHANGED
|
@@ -1,73 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
AVERAGE: 'yellow',
|
|
14
|
-
BELOW_AVERAGE: 'orange',
|
|
15
|
-
POOR: 'red',
|
|
16
|
-
};
|
|
17
|
-
export const percentageToColor = (percentage) => {
|
|
18
|
-
if (percentage >= PERCENTAGE_THRESHOLDS.EXCELLENT)
|
|
19
|
-
return COLOR_MAP.EXCELLENT;
|
|
20
|
-
if (percentage >= PERCENTAGE_THRESHOLDS.GOOD)
|
|
21
|
-
return COLOR_MAP.GOOD;
|
|
22
|
-
if (percentage >= PERCENTAGE_THRESHOLDS.ABOVE_AVERAGE)
|
|
23
|
-
return COLOR_MAP.ABOVE_AVERAGE;
|
|
24
|
-
if (percentage >= PERCENTAGE_THRESHOLDS.AVERAGE)
|
|
25
|
-
return COLOR_MAP.AVERAGE;
|
|
26
|
-
if (percentage >= PERCENTAGE_THRESHOLDS.BELOW_AVERAGE)
|
|
27
|
-
return COLOR_MAP.BELOW_AVERAGE;
|
|
28
|
-
return COLOR_MAP.POOR;
|
|
29
|
-
};
|
|
30
|
-
const calculateCategoryAverage = (category, metrics) => {
|
|
31
|
-
const categoryScores = R.pluck(category, metrics);
|
|
32
|
-
const sum = R.sum(categoryScores);
|
|
33
|
-
const count = R.length(metrics);
|
|
34
|
-
return Math.round(sum / count);
|
|
1
|
+
const COLOR_THRESHOLDS = [
|
|
2
|
+
[95, 'brightgreen'],
|
|
3
|
+
[90, 'green'],
|
|
4
|
+
[75, 'yellowgreen'],
|
|
5
|
+
[60, 'yellow'],
|
|
6
|
+
[40, 'orange'],
|
|
7
|
+
];
|
|
8
|
+
const POOR_COLOR = 'red';
|
|
9
|
+
export const percentageToColor = (percentage) => COLOR_THRESHOLDS.find(([threshold]) => percentage >= threshold)?.[1] ?? POOR_COLOR;
|
|
10
|
+
const averageByCategory = (category, metrics) => {
|
|
11
|
+
const sum = metrics.reduce((total, metric) => total + (metric[category] ?? 0), 0);
|
|
12
|
+
return Math.round(sum / metrics.length);
|
|
35
13
|
};
|
|
36
14
|
export const getAverageScore = (metrics) => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
const headMetric = R.head(metrics);
|
|
41
|
-
if (!headMetric) {
|
|
15
|
+
const [head] = metrics;
|
|
16
|
+
if (!head)
|
|
42
17
|
return {};
|
|
43
|
-
|
|
44
|
-
const categories = R.keys(headMetric);
|
|
45
|
-
const scoreObjects = categories.map((category) => ({
|
|
46
|
-
[category]: calculateCategoryAverage(category, metrics),
|
|
47
|
-
}));
|
|
48
|
-
return R.mergeAll(scoreObjects);
|
|
49
|
-
};
|
|
50
|
-
const calculateTotalScore = (metrics) => {
|
|
51
|
-
const sumOfAllScores = R.pipe(R.map((metric) => R.sum(R.values(metric))), R.sum)(metrics);
|
|
52
|
-
return sumOfAllScores;
|
|
53
|
-
};
|
|
54
|
-
const calculateTotalCategories = (headMetric) => {
|
|
55
|
-
return R.length(R.keys(headMetric));
|
|
18
|
+
return Object.fromEntries(Object.keys(head).map((category) => [category, averageByCategory(category, metrics)]));
|
|
56
19
|
};
|
|
57
20
|
export const getSquashedScore = (metrics) => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
const headMetric = R.head(metrics);
|
|
62
|
-
if (!headMetric) {
|
|
21
|
+
const [head] = metrics;
|
|
22
|
+
if (!head)
|
|
63
23
|
return { lighthouse: 0 };
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
const averageScore = totalScore / (totalMetrics * totalCategories);
|
|
69
|
-
return {
|
|
70
|
-
lighthouse: Math.round(averageScore),
|
|
71
|
-
};
|
|
24
|
+
const totalScore = metrics.reduce((sum, metric) => sum + Object.values(metric).reduce((a, b) => a + b, 0), 0);
|
|
25
|
+
const totalCategories = Object.keys(head).length;
|
|
26
|
+
const averageScore = totalScore / (metrics.length * totalCategories);
|
|
27
|
+
return { lighthouse: Math.round(averageScore) };
|
|
72
28
|
};
|
|
73
29
|
//# sourceMappingURL=calculations.js.map
|
package/src/calculations.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calculations.js","sourceRoot":"","sources":["../../src/calculations.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"calculations.js","sourceRoot":"","sources":["../../src/calculations.ts"],"names":[],"mappings":"AAEA,MAAM,gBAAgB,GAA6C;IACjE,CAAC,EAAE,EAAE,aAAa,CAAC;IACnB,CAAC,EAAE,EAAE,OAAO,CAAC;IACb,CAAC,EAAE,EAAE,aAAa,CAAC;IACnB,CAAC,EAAE,EAAE,QAAQ,CAAC;IACd,CAAC,EAAE,EAAE,QAAQ,CAAC;CACf,CAAC;AAEF,MAAM,UAAU,GAAG,KAAK,CA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MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,EACvE,CAAC,CACF,CAAC;IACF,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;IACjD,MAAM,YAAY,GAAG,UAAU,GAAG,CAAC,OAAO,CAAC,MAAM,GAAG,eAAe,CAAC,CAAC;IAErE,OAAO,EAAE,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,CAAC;AAClD,CAAC,CAAC"}
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import handleUserInput from './main.js';
|
|
3
3
|
import CLI from 'clui';
|
|
4
|
-
const
|
|
5
|
-
handleUserInput(
|
|
4
|
+
const spinner = new CLI.Spinner('Running Lighthouse, please wait...', ['◜', '◠', '◝', '◞', '◡', '◟']);
|
|
5
|
+
await handleUserInput(spinner);
|
|
6
6
|
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,eAAe,MAAM,WAAW,CAAC;AACxC,OAAO,GAAG,MAAM,MAAM,CAAC;AAEvB,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,eAAe,MAAM,WAAW,CAAC;AACxC,OAAO,GAAG,MAAM,MAAM,CAAC;AAEvB,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,oCAAoC,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AACtG,MAAM,eAAe,CAAC,OAAO,CAAC,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { LighthouseMetrics, LighthouseReport, ProcessedLighthouseResult, LighthouseConfig, LighthouseLHR, ParsedArgs, BadgeStyle } from './types.js';
|
|
2
2
|
export declare const metricsToSvg: (lighthouseMetrics: LighthouseMetrics, badgeStyle: BadgeStyle, outputPath: string) => Promise<void>;
|
|
3
3
|
export declare const htmlReportsToFile: (htmlReports: LighthouseReport[], outputPath: string) => Promise<void>;
|
|
4
|
-
export declare const processRawLighthouseResult: (data: LighthouseLHR, html: string, url: string, shouldSaveReport: boolean) =>
|
|
4
|
+
export declare const processRawLighthouseResult: (data: LighthouseLHR, html: string, url: string, shouldSaveReport: boolean) => ProcessedLighthouseResult;
|
|
5
5
|
type CalculateLighthouseMetricsFn = (url: string, shouldSaveReport: boolean, lighthouseParameters?: LighthouseConfig) => Promise<ProcessedLighthouseResult>;
|
|
6
|
-
export declare const calculateLighthouseMetrics:
|
|
7
|
-
export declare const processParameters: (parserArgs: ParsedArgs,
|
|
6
|
+
export declare const calculateLighthouseMetrics: CalculateLighthouseMetricsFn;
|
|
7
|
+
export declare const processParameters: (parserArgs: ParsedArgs, calculateFn: CalculateLighthouseMetricsFn, lighthouseParameters?: LighthouseConfig) => Promise<void>;
|
|
8
8
|
export {};
|
|
9
9
|
//# sourceMappingURL=lighthouse-badges.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lighthouse-badges.d.ts","sourceRoot":"","sources":["../../src/lighthouse-badges.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"lighthouse-badges.d.ts","sourceRoot":"","sources":["../../src/lighthouse-badges.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,iBAAiB,EACjB,gBAAgB,EAChB,yBAAyB,EACzB,gBAAgB,EAChB,aAAa,EACb,UAAU,EACV,UAAU,EACX,MAAM,YAAY,CAAC;AAkCpB,eAAO,MAAM,YAAY,GACvB,mBAAmB,iBAAiB,EACpC,YAAY,UAAU,EACtB,YAAY,MAAM,KACjB,OAAO,CAAC,IAAI,CAMd,CAAC;AAYF,eAAO,MAAM,iBAAiB,GAC5B,aAAa,gBAAgB,EAAE,EAC/B,YAAY,MAAM,KACjB,OAAO,CAAC,IAAI,CAOd,CAAC;AAUF,eAAO,MAAM,0BAA0B,GACrC,MAAM,aAAa,EACnB,MAAM,MAAM,EACZ,KAAK,MAAM,EACX,kBAAkB,OAAO,KACxB,yBAGD,CAAC;AAEH,KAAK,4BAA4B,GAAG,CAClC,GAAG,EAAE,MAAM,EACX,gBAAgB,EAAE,OAAO,EACzB,oBAAoB,CAAC,EAAE,gBAAgB,KACpC,OAAO,CAAC,yBAAyB,CAAC,CAAC;AAExC,eAAO,MAAM,0BAA0B,EAAE,4BAkBxC,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAC5B,YAAY,UAAU,EACtB,aAAa,4BAA4B,EACzC,uBAAsB,gBAAqB,KAC1C,OAAO,CAAC,IAAI,CAkBd,CAAC"}
|
package/src/lighthouse-badges.js
CHANGED
|
@@ -1,34 +1,9 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
-
import fs from 'fs';
|
|
2
|
+
import fs from 'fs/promises';
|
|
3
3
|
import { makeBadge } from 'badge-maker';
|
|
4
|
-
import * as R from 'ramda';
|
|
5
4
|
import lighthouse from 'lighthouse/core/index.cjs';
|
|
6
|
-
import {
|
|
5
|
+
import { urlEscaper } from './util.js';
|
|
7
6
|
import { getAverageScore, getSquashedScore, percentageToColor } from './calculations.js';
|
|
8
|
-
const writeFileAsync = (filepath, content) => {
|
|
9
|
-
return new Promise((resolve, reject) => {
|
|
10
|
-
fs.writeFile(filepath, content, (error) => {
|
|
11
|
-
if (error) {
|
|
12
|
-
reject(error);
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
resolve();
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
const mkdirAsync = (dirPath) => {
|
|
21
|
-
return new Promise((resolve, reject) => {
|
|
22
|
-
fs.mkdir(dirPath, { recursive: true }, (error) => {
|
|
23
|
-
if (error) {
|
|
24
|
-
reject(error);
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
resolve();
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
7
|
const CHROME_FLAGS = [
|
|
33
8
|
'--headless',
|
|
34
9
|
'--no-sandbox',
|
|
@@ -38,133 +13,61 @@ const CHROME_FLAGS = [
|
|
|
38
13
|
'--no-first-run',
|
|
39
14
|
'--disable-default-apps',
|
|
40
15
|
];
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
label: metricKey,
|
|
49
|
-
message: `${score}%`,
|
|
50
|
-
color,
|
|
51
|
-
style: badgeStyle,
|
|
52
|
-
});
|
|
53
|
-
};
|
|
16
|
+
const badgeFilePath = (outputPath, metricKey) => path.join(outputPath, `${metricKey.replace(/ /g, '_')}.svg`);
|
|
17
|
+
const buildBadgeSvg = (metricKey, score, badgeStyle) => makeBadge({
|
|
18
|
+
label: metricKey,
|
|
19
|
+
message: `${score}%`,
|
|
20
|
+
color: percentageToColor(score),
|
|
21
|
+
style: badgeStyle,
|
|
22
|
+
});
|
|
54
23
|
const saveBadge = async (outputPath, metricKey, score, badgeStyle) => {
|
|
55
|
-
const filepath =
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
await writeFileAsync(filepath, svg);
|
|
59
|
-
statusMessage(`Saved svg to ${filepath}\n`, `Failed to save svg to ${outputPath}`, null);
|
|
60
|
-
}
|
|
61
|
-
catch (error) {
|
|
62
|
-
statusMessage(`Saved svg to ${filepath}\n`, `Failed to save svg to ${outputPath}`, error);
|
|
63
|
-
}
|
|
24
|
+
const filepath = badgeFilePath(outputPath, metricKey);
|
|
25
|
+
await fs.writeFile(filepath, buildBadgeSvg(metricKey, score, badgeStyle));
|
|
26
|
+
process.stdout.write(`Saved svg to ${filepath}\n`);
|
|
64
27
|
};
|
|
65
28
|
export const metricsToSvg = async (lighthouseMetrics, badgeStyle, outputPath) => {
|
|
66
|
-
|
|
67
|
-
await Promise.all(savePromises);
|
|
68
|
-
};
|
|
69
|
-
const extractUrlFromReport = (report) => {
|
|
70
|
-
const urls = R.keys(report);
|
|
71
|
-
return R.head(urls) || null;
|
|
29
|
+
await Promise.all(Object.entries(lighthouseMetrics).map(([metricKey, score]) => saveBadge(outputPath, metricKey, score, badgeStyle)));
|
|
72
30
|
};
|
|
73
31
|
const saveHtmlReport = async (outputPath, url, htmlContent) => {
|
|
74
32
|
const filepath = path.join(outputPath, `${urlEscaper(url)}.html`);
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
statusMessage(`Saved report to ${filepath}\n`, `Failed to save report to ${outputPath}`, null);
|
|
78
|
-
}
|
|
79
|
-
catch (error) {
|
|
80
|
-
statusMessage(`Saved report to ${filepath}\n`, `Failed to save report to ${outputPath}`, error);
|
|
81
|
-
}
|
|
33
|
+
await fs.writeFile(filepath, htmlContent);
|
|
34
|
+
process.stdout.write(`Saved report to ${filepath}\n`);
|
|
82
35
|
};
|
|
83
36
|
export const htmlReportsToFile = async (htmlReports, outputPath) => {
|
|
84
|
-
const savePromises = htmlReports
|
|
85
|
-
.
|
|
86
|
-
|
|
87
|
-
if (!url) {
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
const reportContent = report[url];
|
|
91
|
-
if (typeof reportContent === 'string') {
|
|
92
|
-
return saveHtmlReport(outputPath, url, reportContent);
|
|
93
|
-
}
|
|
94
|
-
return null;
|
|
95
|
-
})
|
|
96
|
-
.filter((promise) => promise !== null);
|
|
37
|
+
const savePromises = htmlReports.flatMap((report) => Object.entries(report)
|
|
38
|
+
.filter((entry) => typeof entry[1] === 'string')
|
|
39
|
+
.map(([url, content]) => saveHtmlReport(outputPath, url, content)));
|
|
97
40
|
await Promise.all(savePromises);
|
|
98
41
|
};
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
[`lighthouse ${category.toLowerCase()}`]: categories[category].score * 100,
|
|
108
|
-
}));
|
|
109
|
-
return Object.assign({}, ...scores);
|
|
110
|
-
};
|
|
111
|
-
export const processRawLighthouseResult = async (data, html, url, shouldSaveReport) => {
|
|
112
|
-
const htmlReport = shouldSaveReport ? html : false;
|
|
113
|
-
const lighthouseMetrics = extractLighthouseMetrics(data.categories);
|
|
114
|
-
return {
|
|
115
|
-
metrics: lighthouseMetrics,
|
|
116
|
-
report: { [url]: htmlReport },
|
|
117
|
-
};
|
|
118
|
-
};
|
|
119
|
-
const launchChrome = async () => {
|
|
120
|
-
const chromeLauncher = await import('chrome-launcher');
|
|
121
|
-
return chromeLauncher.launch({ chromeFlags: [...CHROME_FLAGS] });
|
|
122
|
-
};
|
|
123
|
-
const runLighthouse = async (url, chromePort, lighthouseParameters) => {
|
|
124
|
-
const options = {
|
|
125
|
-
logLevel: 'silent',
|
|
126
|
-
output: 'html',
|
|
127
|
-
port: chromePort,
|
|
128
|
-
};
|
|
129
|
-
return lighthouse(url, options, lighthouseParameters);
|
|
130
|
-
};
|
|
42
|
+
const extractLighthouseMetrics = (categories) => Object.fromEntries(Object.entries(categories).map(([category, { score }]) => [
|
|
43
|
+
`lighthouse ${category.toLowerCase()}`,
|
|
44
|
+
score * 100,
|
|
45
|
+
]));
|
|
46
|
+
export const processRawLighthouseResult = (data, html, url, shouldSaveReport) => ({
|
|
47
|
+
metrics: extractLighthouseMetrics(data.categories),
|
|
48
|
+
report: { [url]: shouldSaveReport ? html : false },
|
|
49
|
+
});
|
|
131
50
|
export const calculateLighthouseMetrics = async (url, shouldSaveReport, lighthouseParameters = {}) => {
|
|
132
|
-
const
|
|
51
|
+
const { launch } = await import('chrome-launcher');
|
|
52
|
+
const chrome = await launch({ chromeFlags: CHROME_FLAGS });
|
|
133
53
|
try {
|
|
134
|
-
const
|
|
135
|
-
return processRawLighthouseResult(
|
|
54
|
+
const { lhr, report } = await lighthouse(url, { logLevel: 'silent', output: 'html', port: chrome.port }, lighthouseParameters);
|
|
55
|
+
return processRawLighthouseResult(lhr, report, url, shouldSaveReport);
|
|
136
56
|
}
|
|
137
57
|
finally {
|
|
138
58
|
await chrome.kill();
|
|
139
59
|
}
|
|
140
60
|
};
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
};
|
|
152
|
-
const calculateMetricsResults = async (metrics, useSingleBadge) => {
|
|
153
|
-
return useSingleBadge ? getSquashedScore(metrics) : getAverageScore(metrics);
|
|
154
|
-
};
|
|
155
|
-
export const processParameters = async (parserArgs, func, lighthouseParameters = {}) => {
|
|
156
|
-
const outputPath = parserArgs.output_path || process.cwd();
|
|
157
|
-
await ensureOutputDirectory(outputPath);
|
|
158
|
-
const results = await Promise.all([
|
|
159
|
-
processUrl(parserArgs.url, parserArgs.save_report, lighthouseParameters, func),
|
|
61
|
+
export const processParameters = async (parserArgs, calculateFn, lighthouseParameters = {}) => {
|
|
62
|
+
const outputPath = parserArgs.output_path ?? process.cwd();
|
|
63
|
+
await fs.mkdir(outputPath, { recursive: true });
|
|
64
|
+
const { metrics, report } = await calculateFn(parserArgs.url, parserArgs.save_report, lighthouseParameters);
|
|
65
|
+
const scoreResults = parserArgs.single_badge
|
|
66
|
+
? getSquashedScore([metrics])
|
|
67
|
+
: getAverageScore([metrics]);
|
|
68
|
+
await Promise.all([
|
|
69
|
+
htmlReportsToFile([report], outputPath),
|
|
70
|
+
metricsToSvg(scoreResults, parserArgs.badge_style, outputPath),
|
|
160
71
|
]);
|
|
161
|
-
const metrics = R.pluck('metrics', results);
|
|
162
|
-
const reports = R.pluck('report', results);
|
|
163
|
-
const metricsResults = await calculateMetricsResults(metrics, parserArgs.single_badge);
|
|
164
|
-
await generateArtifacts({
|
|
165
|
-
reports,
|
|
166
|
-
svg: { results: metricsResults, style: parserArgs.badge_style },
|
|
167
|
-
outputPath,
|
|
168
|
-
});
|
|
169
72
|
};
|
|
170
73
|
//# sourceMappingURL=lighthouse-badges.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lighthouse-badges.js","sourceRoot":"","sources":["../../src/lighthouse-badges.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"lighthouse-badges.js","sourceRoot":"","sources":["../../src/lighthouse-badges.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,UAAU,MAAM,2BAA2B,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAWzF,MAAM,YAAY,GAAG;IACnB,YAAY;IACZ,cAAc;IACd,eAAe;IACf,yBAAyB;IACzB,4BAA4B;IAC5B,gBAAgB;IAChB,wBAAwB;CACzB,CAAC;AAEF,MAAM,aAAa,GAAG,CAAC,UAAkB,EAAE,SAAiB,EAAU,EAAE,CACtE,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;AAE/D,MAAM,aAAa,GAAG,CAAC,SAAiB,EAAE,KAAa,EAAE,UAAsB,EAAU,EAAE,CACzF,SAAS,CAAC;IACR,KAAK,EAAE,SAAS;IAChB,OAAO,EAAE,GAAG,KAAK,GAAG;IACpB,KAAK,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 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/main.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AACvF,OAAO,MAAM,MAAM,gBAAgB,CAAC;AACpC,OAAO,KAAK,EAAE,OAAO,EAAoB,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/main.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AACvF,OAAO,MAAM,MAAM,gBAAgB,CAAC;AACpC,OAAO,KAAK,EAAE,OAAO,EAAoB,MAAM,YAAY,CAAC;AAqB5D,UAAU,YAAY;IACpB,iBAAiB,CAAC,EAAE,OAAO,iBAAiB,CAAC;IAC7C,0BAA0B,CAAC,EAAE,OAAO,0BAA0B,CAAC;IAC/D,SAAS,CAAC,EAAE,OAAO,MAAM,CAAC,UAAU,CAAC;CACtC;AAED,QAAA,MAAM,eAAe,GAAU,SAAS,OAAO,EAAE,OAAM,YAAiB,KAAG,OAAO,CAAC,IAAI,CAmBtF,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
package/src/main.js
CHANGED
|
@@ -1,51 +1,39 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
2
|
import { calculateLighthouseMetrics, processParameters } from './lighthouse-badges.js';
|
|
3
3
|
import parser from './argparser.js';
|
|
4
|
-
const readFileAsync = (filePath) => {
|
|
5
|
-
return new Promise((resolve, reject) => {
|
|
6
|
-
fs.readFile(filePath, 'utf8', (error, data) => {
|
|
7
|
-
if (error) {
|
|
8
|
-
reject(error);
|
|
9
|
-
}
|
|
10
|
-
else {
|
|
11
|
-
resolve(data);
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
4
|
const DEFAULT_LIGHTHOUSE_CONFIG = {
|
|
17
5
|
extends: 'lighthouse:default',
|
|
18
6
|
};
|
|
19
7
|
const loadLighthouseConfig = async () => {
|
|
20
8
|
const configPath = process.env.LIGHTHOUSE_BADGES_CONFIGURATION_PATH;
|
|
21
|
-
if (!configPath)
|
|
9
|
+
if (!configPath)
|
|
22
10
|
return DEFAULT_LIGHTHOUSE_CONFIG;
|
|
23
|
-
}
|
|
24
11
|
process.stdout.write(` LIGHTHOUSE_BADGES_CONFIGURATION_PATH: ${configPath}\n`);
|
|
25
12
|
try {
|
|
26
|
-
const fileContent = await
|
|
13
|
+
const fileContent = await fs.readFile(configPath, 'utf8');
|
|
27
14
|
return JSON.parse(fileContent);
|
|
28
15
|
}
|
|
29
16
|
catch (error) {
|
|
30
|
-
const
|
|
31
|
-
throw new Error(`Failed to load Lighthouse configuration from ${configPath}: ${
|
|
17
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
18
|
+
throw new Error(`Failed to load Lighthouse configuration from ${configPath}: ${message}`, { cause: error });
|
|
32
19
|
}
|
|
33
20
|
};
|
|
34
21
|
const handleUserInput = async (spinner, deps = {}) => {
|
|
35
22
|
const { processParameters: processParametersFn = processParameters, calculateLighthouseMetrics: calculateLighthouseMetricsFn = calculateLighthouseMetrics, parseArgs = parser.parse_args, } = deps;
|
|
23
|
+
spinner.start();
|
|
36
24
|
try {
|
|
37
|
-
spinner.start();
|
|
38
25
|
const parsedArgs = await parseArgs();
|
|
39
26
|
const lighthouseParameters = await loadLighthouseConfig();
|
|
40
27
|
await processParametersFn(parsedArgs, calculateLighthouseMetricsFn, lighthouseParameters);
|
|
41
|
-
spinner.stop();
|
|
42
28
|
}
|
|
43
29
|
catch (err) {
|
|
44
|
-
spinner.stop();
|
|
45
30
|
const error = err instanceof Error ? err : new Error(String(err));
|
|
46
31
|
process.stderr.write(`${error}\n`);
|
|
47
32
|
process.exit(1);
|
|
48
33
|
}
|
|
34
|
+
finally {
|
|
35
|
+
spinner.stop();
|
|
36
|
+
}
|
|
49
37
|
};
|
|
50
38
|
export default handleUserInput;
|
|
51
39
|
//# sourceMappingURL=main.js.map
|