@hidao/lighthouse-badges 1.0.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/LICENSE +21 -0
- package/README.md +236 -0
- package/bin/fetch-lighthouse.d.ts +8 -0
- package/bin/fetch-lighthouse.d.ts.map +1 -0
- package/bin/fetch-lighthouse.js +79 -0
- package/bin/fetch-lighthouse.js.map +1 -0
- package/bin/generate-markdown.d.ts +8 -0
- package/bin/generate-markdown.d.ts.map +1 -0
- package/bin/generate-markdown.js +38 -0
- package/bin/generate-markdown.js.map +1 -0
- package/bin/generate-svg.d.ts +9 -0
- package/bin/generate-svg.d.ts.map +1 -0
- package/bin/generate-svg.js +56 -0
- package/bin/generate-svg.js.map +1 -0
- package/bin/lighthouse-badges.d.ts +3 -0
- package/bin/lighthouse-badges.d.ts.map +1 -0
- package/bin/lighthouse-badges.js +50 -0
- package/bin/lighthouse-badges.js.map +1 -0
- package/bin/parse-mode.d.ts +12 -0
- package/bin/parse-mode.d.ts.map +1 -0
- package/bin/parse-mode.js +36 -0
- package/bin/parse-mode.js.map +1 -0
- package/bin/score-level.d.ts +11 -0
- package/bin/score-level.d.ts.map +1 -0
- package/bin/score-level.js +18 -0
- package/bin/score-level.js.map +1 -0
- package/bin/types.d.ts +8 -0
- package/bin/types.d.ts.map +1 -0
- package/bin/types.js +2 -0
- package/bin/types.js.map +1 -0
- package/package.json +63 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 hidao80
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
# lighthouse-badges
|
|
2
|
+
|
|
3
|
+
[](LICENSE)
|
|
4
|
+

|
|
5
|
+

|
|
6
|
+

|
|
7
|
+
[](https://deepwiki.com/hidao80/lighthouse-badges)
|
|
8
|
+
|
|
9
|
+
A CLI tool to generate Lighthouse score badges, JSON, or SVG using local Chrome and the Lighthouse npm package.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash copy
|
|
14
|
+
bun add -g @hidao/lighthouse-badges
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Or with npm:
|
|
18
|
+
|
|
19
|
+
```bash copy
|
|
20
|
+
npm install -g @hidao/lighthouse-badges
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Requirements
|
|
24
|
+
|
|
25
|
+
- Node.js >= 22.19
|
|
26
|
+
- Google Chrome installed on your system
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
```bash copy
|
|
31
|
+
bunx github:hidao80/lighthouse-badges <URL> [options]
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Or with npx:
|
|
35
|
+
|
|
36
|
+
```bash copy
|
|
37
|
+
npx github:hidao80/lighthouse-badges <URL> [options]
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Options
|
|
41
|
+
|
|
42
|
+
| Option | Description |
|
|
43
|
+
|--------|-------------|
|
|
44
|
+
| *(none)* | Output Markdown badges |
|
|
45
|
+
| `-b`, `--badge` | Output Markdown badges |
|
|
46
|
+
| `-j`, `--json` | Output JSON |
|
|
47
|
+
| `-s`, `--svg` | Output SVG with donut charts |
|
|
48
|
+
|
|
49
|
+
## Examples
|
|
50
|
+
|
|
51
|
+
### Markdown Badges (default)
|
|
52
|
+
|
|
53
|
+
```bash copy
|
|
54
|
+
bunx github:hidao80/lighthouse-badges https://example.com
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Output:
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
   
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Rendered:
|
|
64
|
+
|
|
65
|
+
   
|
|
66
|
+
|
|
67
|
+
### JSON Output
|
|
68
|
+
|
|
69
|
+
```bash copy
|
|
70
|
+
bunx github:hidao80/lighthouse-badges https://example.com -j
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Output:
|
|
74
|
+
|
|
75
|
+
```json
|
|
76
|
+
{
|
|
77
|
+
"performance": 100,
|
|
78
|
+
"accessibility": 100,
|
|
79
|
+
"bestPractices": 93,
|
|
80
|
+
"seo": 72
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### SVG Output
|
|
85
|
+
|
|
86
|
+
```bash copy
|
|
87
|
+
bunx github:hidao80/lighthouse-badges https://example.com -s
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Outputs an SVG string with donut charts for each score.
|
|
91
|
+
|
|
92
|
+
Output:
|
|
93
|
+
|
|
94
|
+
<details>
|
|
95
|
+
<summary>Details</summary>
|
|
96
|
+
|
|
97
|
+
```svg copy
|
|
98
|
+
<svg width="480" height="120" viewBox="0 0 480 120" xmlns="http://www.w3.org/2000/svg">
|
|
99
|
+
|
|
100
|
+
<g transform="translate(0, 0)">
|
|
101
|
+
<circle cx="60" cy="60" r="16" fill="none" stroke="#e0e0e0" stroke-width="8" transform="rotate(-90 60 60)" />
|
|
102
|
+
<circle cx="60" cy="60" r="16" fill="none" stroke="#0cce6b" stroke-width="8"
|
|
103
|
+
stroke-dasharray="100.53096491487338" stroke-dashoffset="6.031857894892408"
|
|
104
|
+
stroke-linecap="round" transform="rotate(-90 60 60)" />
|
|
105
|
+
<text x="60" y="70" text-anchor="middle" font-size="22" font-family="Arial" fill="#0cce6b">
|
|
106
|
+
94
|
|
107
|
+
</text>
|
|
108
|
+
</g>
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
<g transform="translate(120, 0)">
|
|
112
|
+
<circle cx="60" cy="60" r="16" fill="none" stroke="#e0e0e0" stroke-width="8" transform="rotate(-90 60 60)" />
|
|
113
|
+
<circle cx="60" cy="60" r="16" fill="none" stroke="#0cce6b" stroke-width="8"
|
|
114
|
+
stroke-dasharray="100.53096491487338" stroke-dashoffset="0"
|
|
115
|
+
stroke-linecap="round" transform="rotate(-90 60 60)" />
|
|
116
|
+
<text x="60" y="70" text-anchor="middle" font-size="22" font-family="Arial" fill="#0cce6b">
|
|
117
|
+
100
|
|
118
|
+
</text>
|
|
119
|
+
</g>
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
<g transform="translate(240, 0)">
|
|
123
|
+
<circle cx="60" cy="60" r="16" fill="none" stroke="#e0e0e0" stroke-width="8" transform="rotate(-90 60 60)" />
|
|
124
|
+
<circle cx="60" cy="60" r="16" fill="none" stroke="#0cce6b" stroke-width="8"
|
|
125
|
+
stroke-dasharray="100.53096491487338" stroke-dashoffset="10.053096491487336"
|
|
126
|
+
stroke-linecap="round" transform="rotate(-90 60 60)" />
|
|
127
|
+
<text x="60" y="70" text-anchor="middle" font-size="22" font-family="Arial" fill="#0cce6b">
|
|
128
|
+
90
|
|
129
|
+
</text>
|
|
130
|
+
</g>
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
<g transform="translate(360, 0)">
|
|
134
|
+
<circle cx="60" cy="60" r="16" fill="none" stroke="#e0e0e0" stroke-width="8" transform="rotate(-90 60 60)" />
|
|
135
|
+
<circle cx="60" cy="60" r="16" fill="none" stroke="#0cce6b" stroke-width="8"
|
|
136
|
+
stroke-dasharray="100.53096491487338" stroke-dashoffset="10.053096491487336"
|
|
137
|
+
stroke-linecap="round" transform="rotate(-90 60 60)" />
|
|
138
|
+
<text x="60" y="70" text-anchor="middle" font-size="22" font-family="Arial" fill="#0cce6b">
|
|
139
|
+
72
|
|
140
|
+
</text>
|
|
141
|
+
</g>
|
|
142
|
+
|
|
143
|
+
</svg>
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
</details>
|
|
147
|
+
|
|
148
|
+
Rendered:
|
|
149
|
+
|
|
150
|
+
<svg width="480" height="120" viewBox="0 0 480 120" xmlns="http://www.w3.org/2000/svg">
|
|
151
|
+
<g transform="translate(0, 0)">
|
|
152
|
+
<circle cx="60" cy="60" r="16" fill="none" stroke="#e0e0e0" stroke-width="8" transform="rotate(-90 60 60)" />
|
|
153
|
+
<circle cx="60" cy="60" r="16" fill="none" stroke="#0cce6b" stroke-width="8"
|
|
154
|
+
stroke-dasharray="100.53096491487338" stroke-dashoffset="6.031857894892408"
|
|
155
|
+
stroke-linecap="round" transform="rotate(-90 60 60)" />
|
|
156
|
+
<text x="60" y="70" text-anchor="middle" font-size="22" font-family="Arial" fill="#0cce6b">
|
|
157
|
+
94
|
|
158
|
+
</text>
|
|
159
|
+
</g>
|
|
160
|
+
<g transform="translate(120, 0)">
|
|
161
|
+
<circle cx="60" cy="60" r="16" fill="none" stroke="#e0e0e0" stroke-width="8" transform="rotate(-90 60 60)" />
|
|
162
|
+
<circle cx="60" cy="60" r="16" fill="none" stroke="#0cce6b" stroke-width="8"
|
|
163
|
+
stroke-dasharray="100.53096491487338" stroke-dashoffset="0"
|
|
164
|
+
stroke-linecap="round" transform="rotate(-90 60 60)" />
|
|
165
|
+
<text x="60" y="70" text-anchor="middle" font-size="22" font-family="Arial" fill="#0cce6b">
|
|
166
|
+
100
|
|
167
|
+
</text>
|
|
168
|
+
</g>
|
|
169
|
+
<g transform="translate(240, 0)">
|
|
170
|
+
<circle cx="60" cy="60" r="16" fill="none" stroke="#e0e0e0" stroke-width="8" transform="rotate(-90 60 60)" />
|
|
171
|
+
<circle cx="60" cy="60" r="16" fill="none" stroke="#0cce6b" stroke-width="8"
|
|
172
|
+
stroke-dasharray="100.53096491487338" stroke-dashoffset="10.053096491487336"
|
|
173
|
+
stroke-linecap="round" transform="rotate(-90 60 60)" />
|
|
174
|
+
<text x="60" y="70" text-anchor="middle" font-size="22" font-family="Arial" fill="#0cce6b">
|
|
175
|
+
90
|
|
176
|
+
</text>
|
|
177
|
+
</g>
|
|
178
|
+
<g transform="translate(360, 0)">
|
|
179
|
+
<circle cx="60" cy="60" r="16" fill="none" stroke="#e0e0e0" stroke-width="8" transform="rotate(-90 60 60)" />
|
|
180
|
+
<circle cx="60" cy="60" r="16" fill="none" stroke="#ffa400" stroke-width="8"
|
|
181
|
+
stroke-dasharray="100.53096491487338" stroke-dashoffset="10.053096491487336"
|
|
182
|
+
stroke-linecap="round" transform="rotate(-90 60 60)" />
|
|
183
|
+
<text x="60" y="70" text-anchor="middle" font-size="22" font-family="Arial" fill="#ffa400">
|
|
184
|
+
72
|
|
185
|
+
</text>
|
|
186
|
+
</g>
|
|
187
|
+
</svg>
|
|
188
|
+
|
|
189
|
+
## Badge Colors
|
|
190
|
+
|
|
191
|
+
| Score | Color |
|
|
192
|
+
|-------|-------|
|
|
193
|
+
| 90-100 | Green |
|
|
194
|
+
| 50-89 | Yellow |
|
|
195
|
+
| 0-49 | Red |
|
|
196
|
+
|
|
197
|
+
## Quick Start
|
|
198
|
+
|
|
199
|
+
### Run with Docker
|
|
200
|
+
|
|
201
|
+
```bash copy
|
|
202
|
+
# Production build
|
|
203
|
+
docker build -t lighthouse-badges .
|
|
204
|
+
docker run lighthouse-badges https://example.com
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### Run directly
|
|
208
|
+
|
|
209
|
+
```bash copy
|
|
210
|
+
bunx github:hidao80/lighthouse-badges https://example.com
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Or with npx:
|
|
214
|
+
|
|
215
|
+
```bash copy
|
|
216
|
+
npx github:hidao80/lighthouse-badges https://example.com
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Development
|
|
220
|
+
|
|
221
|
+
```bash copy
|
|
222
|
+
bun install
|
|
223
|
+
bun run build # tsc -> bin/
|
|
224
|
+
bun run dev # tsc --watch
|
|
225
|
+
bun run lint # biome check src/ tests/
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
`bin/` is the compiled CLI and is committed to git, so `npx`/`bunx github:...`
|
|
229
|
+
runs it directly with no install-time build step. After changing `src/`, run
|
|
230
|
+
`bun run build` and commit the resulting `bin/` diff. See
|
|
231
|
+
[AGENTS.md](AGENTS.md) for the full contributor guide and
|
|
232
|
+
[docs/ADR.md](docs/ADR.md) for the reasoning behind these choices.
|
|
233
|
+
|
|
234
|
+
## License
|
|
235
|
+
|
|
236
|
+
MIT
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { LighthouseScores } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Launch headless Chrome and run Lighthouse against the given URL.
|
|
4
|
+
* @param url - The URL to audit.
|
|
5
|
+
* @returns Rounded 0-100 scores for performance, accessibility, best practices, and SEO.
|
|
6
|
+
*/
|
|
7
|
+
export declare function fetchLighthouseScores(url: string): Promise<LighthouseScores>;
|
|
8
|
+
//# sourceMappingURL=fetch-lighthouse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-lighthouse.d.ts","sourceRoot":"","sources":["../src/fetch-lighthouse.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAkBnD;;;;GAIG;AACH,wBAAsB,qBAAqB,CACzC,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,gBAAgB,CAAC,CA8D3B"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { existsSync, mkdtempSync, rmSync } from 'node:fs';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import * as chromeLauncher from 'chrome-launcher';
|
|
5
|
+
import lighthouse from 'lighthouse';
|
|
6
|
+
// Chrome's own sandbox needs privileges that most container runtimes deny;
|
|
7
|
+
// only drop it when we detect we're actually inside a container.
|
|
8
|
+
function isRunningInContainer() {
|
|
9
|
+
return existsSync('/.dockerenv') || process.env.container !== undefined;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Round a Lighthouse category's 0-1 score to a 0-100 integer, preserving
|
|
13
|
+
* `null` for a category that wasn't evaluated instead of coercing it to 0.
|
|
14
|
+
* @param score - Raw category score (0-1), or null/undefined if unevaluated.
|
|
15
|
+
* @returns Rounded 0-100 score, or null if the category has no score.
|
|
16
|
+
*/
|
|
17
|
+
function roundScore(score) {
|
|
18
|
+
return score == null ? null : Math.round(score * 100);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Launch headless Chrome and run Lighthouse against the given URL.
|
|
22
|
+
* @param url - The URL to audit.
|
|
23
|
+
* @returns Rounded 0-100 scores for performance, accessibility, best practices, and SEO.
|
|
24
|
+
*/
|
|
25
|
+
export async function fetchLighthouseScores(url) {
|
|
26
|
+
const userDataDir = mkdtempSync(join(tmpdir(), '.lighthouse-'));
|
|
27
|
+
let chrome;
|
|
28
|
+
try {
|
|
29
|
+
chrome = await chromeLauncher.launch({
|
|
30
|
+
chromeFlags: [
|
|
31
|
+
'--headless',
|
|
32
|
+
'--disable-gpu',
|
|
33
|
+
...(isRunningInContainer() ? ['--no-sandbox'] : []),
|
|
34
|
+
`--user-data-dir=${userDataDir}`,
|
|
35
|
+
],
|
|
36
|
+
userDataDir: userDataDir,
|
|
37
|
+
});
|
|
38
|
+
const result = await lighthouse(url, {
|
|
39
|
+
port: chrome.port,
|
|
40
|
+
output: 'json',
|
|
41
|
+
logLevel: 'silent',
|
|
42
|
+
onlyCategories: [
|
|
43
|
+
'performance',
|
|
44
|
+
'accessibility',
|
|
45
|
+
'best-practices',
|
|
46
|
+
'seo',
|
|
47
|
+
],
|
|
48
|
+
}, undefined);
|
|
49
|
+
if (!result) {
|
|
50
|
+
throw new Error('Lighthouse failed to run');
|
|
51
|
+
}
|
|
52
|
+
const categories = result.lhr.categories;
|
|
53
|
+
return {
|
|
54
|
+
performance: roundScore(categories.performance?.score),
|
|
55
|
+
accessibility: roundScore(categories.accessibility?.score),
|
|
56
|
+
bestPractices: roundScore(categories['best-practices']?.score),
|
|
57
|
+
seo: roundScore(categories.seo?.score),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
if (chrome) {
|
|
62
|
+
try {
|
|
63
|
+
await chrome.kill();
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
// Chrome may already be gone; the temp dir still needs removing below.
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// Chrome may briefly keep the folder locked after kill(); retry instead
|
|
70
|
+
// of always paying a fixed delay.
|
|
71
|
+
rmSync(userDataDir, {
|
|
72
|
+
recursive: true,
|
|
73
|
+
force: true,
|
|
74
|
+
maxRetries: 3,
|
|
75
|
+
retryDelay: 200,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=fetch-lighthouse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-lighthouse.js","sourceRoot":"","sources":["../src/fetch-lighthouse.ts"],"names":[],"mappings":"AAA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BACf,gBAAgB;gBAChB,KAAK;aACN;SACF,EACD,SAAS,CACV,CAAC;QAEF,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;QAC9C,CAAC;QAED,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC;QAEzC,OAAO;YACL,WAAW,EAAE,UAAU,CAAC,UAAU,CAAC,WAAW,EAAE,KAAK,CAAC;YACtD,aAAa,EAAE,UAAU,CAAC,UAAU,CAAC,aAAa,EAAE,KAAK,CAAC;YAC1D,aAAa,EAAE,UAAU,CAAC,UAAU,CAAC,gBAAgB,CAAC,EAAE,KAAK,CAAC;YAC9D,GAAG,EAAE,UAAU,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC;SACvC,CAAC;IACJ,CAAC;YAAS,CAAC;QACT,IAAI,MAAM,EAAE,CAAC;YACX,IAAI,CAAC;gBACH,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;YACtB,CAAC;YAAC,MAAM,CAAC;gBACP,uEAAuE;YACzE,CAAC;QACH,CAAC;QAED,wEAAwE;QACxE,kCAAkC;QAClC,MAAM,CAAC,WAAW,EAAE;YAClB,SAAS,EAAE,IAAI;YACf,KAAK,EAAE,IAAI;YACX,UAAU,EAAE,CAAC;YACb,UAAU,EAAE,GAAG;SAChB,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { LighthouseScores } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Render Lighthouse scores as a row of Markdown shields.io badges.
|
|
4
|
+
* @param scores - Lighthouse scores to render.
|
|
5
|
+
* @returns Markdown string with one badge per category, separated by ` `.
|
|
6
|
+
*/
|
|
7
|
+
export declare function generateMarkdown(scores: LighthouseScores): string;
|
|
8
|
+
//# sourceMappingURL=generate-markdown.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-markdown.d.ts","sourceRoot":"","sources":["../src/generate-markdown.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AA4BnD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAOjE"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { getScoreLevel } from './score-level.js';
|
|
2
|
+
const BADGE_COLORS = {
|
|
3
|
+
good: 'brightgreen',
|
|
4
|
+
average: 'yellow',
|
|
5
|
+
poor: 'red',
|
|
6
|
+
unknown: 'lightgrey',
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Map a 0-100 score (or null) to a shields.io badge color name.
|
|
10
|
+
* @param score - Lighthouse score (0-100), or null if unevaluated.
|
|
11
|
+
* @returns shields.io color name.
|
|
12
|
+
*/
|
|
13
|
+
function getColor(score) {
|
|
14
|
+
return BADGE_COLORS[getScoreLevel(score)];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Render a score as badge message text, using a URL-encoded "N/A" for a
|
|
18
|
+
* category Lighthouse couldn't evaluate so it survives shields.io's URL path.
|
|
19
|
+
* @param score - Lighthouse score (0-100), or null if unevaluated.
|
|
20
|
+
* @returns The score as a string, or `N%2FA`.
|
|
21
|
+
*/
|
|
22
|
+
function formatScore(score) {
|
|
23
|
+
return score === null ? 'N%2FA' : String(score);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Render Lighthouse scores as a row of Markdown shields.io badges.
|
|
27
|
+
* @param scores - Lighthouse scores to render.
|
|
28
|
+
* @returns Markdown string with one badge per category, separated by ` `.
|
|
29
|
+
*/
|
|
30
|
+
export function generateMarkdown(scores) {
|
|
31
|
+
return [
|
|
32
|
+
`}-${getColor(scores.accessibility)}?style=flat-square)`,
|
|
33
|
+
`}-${getColor(scores.bestPractices)}?style=flat-square)`,
|
|
34
|
+
`}-${getColor(scores.performance)}?style=flat-square)`,
|
|
35
|
+
`}-${getColor(scores.seo)}?style=flat-square)`,
|
|
36
|
+
].join(' ');
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=generate-markdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-markdown.js","sourceRoot":"","sources":["../src/generate-markdown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAmB,MAAM,kBAAkB,CAAC;AAGlE,MAAM,YAAY,GAA+B;IAC/C,IAAI,EAAE,aAAa;IACnB,OAAO,EAAE,QAAQ;IACjB,IAAI,EAAE,KAAK;IACX,OAAO,EAAE,WAAW;CACrB,CAAC;AAEF;;;;GAIG;AACH,SAAS,QAAQ,CAAC,KAAoB;IACpC,OAAO,YAAY,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;AAC5C,CAAC;AAED;;;;;GAKG;AACH,SAAS,WAAW,CAAC,KAAoB;IACvC,OAAO,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAClD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAwB;IACvD,OAAO;QACL,+DAA+D,WAAW,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC,qBAAqB;QACvJ,iEAAiE,WAAW,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC,qBAAqB;QACzJ,2DAA2D,WAAW,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,WAAW,CAAC,qBAAqB;QAC/I,2CAA2C,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,qBAAqB;KAChH,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { LighthouseScores } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Render Lighthouse scores as an SVG containing one donut chart per category.
|
|
4
|
+
* @param scores - Lighthouse scores to render.
|
|
5
|
+
* @returns Standalone SVG markup, 480x120, with donuts for accessibility,
|
|
6
|
+
* best practices, performance, and SEO in that order.
|
|
7
|
+
*/
|
|
8
|
+
export declare function generateSvg(scores: LighthouseScores): string;
|
|
9
|
+
//# sourceMappingURL=generate-svg.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-svg.d.ts","sourceRoot":"","sources":["../src/generate-svg.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AA6CnD;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAS5D"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { getScoreLevel } from './score-level.js';
|
|
2
|
+
const DONUT_COLORS = {
|
|
3
|
+
good: '#0cce6b',
|
|
4
|
+
average: '#ffa400',
|
|
5
|
+
poor: '#ff4e42',
|
|
6
|
+
unknown: '#9e9e9e',
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Map a 0-100 score (or null) to a donut-chart stroke color.
|
|
10
|
+
* @param score - Lighthouse score (0-100), or null if unevaluated.
|
|
11
|
+
* @returns Hex color: green (>=90), amber (>=50), red, or grey (unevaluated).
|
|
12
|
+
*/
|
|
13
|
+
function getSvgColor(score) {
|
|
14
|
+
return DONUT_COLORS[getScoreLevel(score)];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Build a single donut-chart SVG fragment for one score.
|
|
18
|
+
* @param score - Lighthouse score (0-100), or null if unevaluated.
|
|
19
|
+
* @param color - Stroke color for the filled arc and label text.
|
|
20
|
+
* @param x - Horizontal translate offset for this donut within the parent SVG.
|
|
21
|
+
* @returns SVG `<g>` markup for the donut and its centered score/`N/A` label.
|
|
22
|
+
*/
|
|
23
|
+
function createDonut(score, color, x) {
|
|
24
|
+
const radius = 16;
|
|
25
|
+
const circumference = 2 * Math.PI * radius;
|
|
26
|
+
const offset = score === null ? circumference : circumference * (1 - score / 100);
|
|
27
|
+
const label = score === null ? 'N/A' : score;
|
|
28
|
+
return `
|
|
29
|
+
<g transform="translate(${x}, 0)">
|
|
30
|
+
<circle cx="60" cy="60" r="${radius}" fill="none" stroke="#e0e0e0" stroke-width="8" transform="rotate(-90 60 60)" />
|
|
31
|
+
<circle cx="60" cy="60" r="${radius}" fill="none" stroke="${color}" stroke-width="8"
|
|
32
|
+
stroke-dasharray="${circumference}" stroke-dashoffset="${offset}"
|
|
33
|
+
stroke-linecap="round" transform="rotate(-90 60 60)" />
|
|
34
|
+
<text x="60" y="70" text-anchor="middle" font-size="22" font-family="Arial" fill="${color}">
|
|
35
|
+
${label}
|
|
36
|
+
</text>
|
|
37
|
+
</g>
|
|
38
|
+
`;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Render Lighthouse scores as an SVG containing one donut chart per category.
|
|
42
|
+
* @param scores - Lighthouse scores to render.
|
|
43
|
+
* @returns Standalone SVG markup, 480x120, with donuts for accessibility,
|
|
44
|
+
* best practices, performance, and SEO in that order.
|
|
45
|
+
*/
|
|
46
|
+
export function generateSvg(scores) {
|
|
47
|
+
return `
|
|
48
|
+
<svg width="480" height="120" viewBox="0 0 480 120" xmlns="http://www.w3.org/2000/svg">
|
|
49
|
+
${createDonut(scores.accessibility, getSvgColor(scores.accessibility), 0)}
|
|
50
|
+
${createDonut(scores.bestPractices, getSvgColor(scores.bestPractices), 120)}
|
|
51
|
+
${createDonut(scores.performance, getSvgColor(scores.performance), 240)}
|
|
52
|
+
${createDonut(scores.seo, getSvgColor(scores.seo), 360)}
|
|
53
|
+
</svg>
|
|
54
|
+
`.trim();
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=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,GAAG,CAAC;IACzE,WAAW,CAAC,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,GAAG,CAAC;IACrE,WAAW,CAAC,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC;;GAEtD,CAAC,IAAI,EAAE,CAAC;AACX,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lighthouse-badges.d.ts","sourceRoot":"","sources":["../src/lighthouse-badges.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { fetchLighthouseScores } from './fetch-lighthouse.js';
|
|
3
|
+
import { generateMarkdown } from './generate-markdown.js';
|
|
4
|
+
import { generateSvg } from './generate-svg.js';
|
|
5
|
+
import { parseMode } from './parse-mode.js';
|
|
6
|
+
const args = process.argv.slice(2);
|
|
7
|
+
const url = args[0];
|
|
8
|
+
if (!url || url.startsWith('-')) {
|
|
9
|
+
console.error('Usage: lighthouse-badges <URL> [--markdown|--json|--svg]');
|
|
10
|
+
process.exit(1);
|
|
11
|
+
}
|
|
12
|
+
const isHttpUrl = (() => {
|
|
13
|
+
try {
|
|
14
|
+
return ['http:', 'https:'].includes(new URL(url).protocol);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
})();
|
|
20
|
+
if (!isHttpUrl) {
|
|
21
|
+
console.error('Error: URL must use the http or https scheme');
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
let mode;
|
|
25
|
+
try {
|
|
26
|
+
mode = parseMode(args);
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
console.error('Error:', error instanceof Error ? error.message : error);
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
(async () => {
|
|
33
|
+
try {
|
|
34
|
+
const scores = await fetchLighthouseScores(url);
|
|
35
|
+
if (mode === 'json') {
|
|
36
|
+
console.log(JSON.stringify(scores, null, 2));
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (mode === 'svg') {
|
|
40
|
+
console.log(generateSvg(scores));
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
console.log(generateMarkdown(scores));
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
console.error('Error:', error instanceof Error ? error.message : error);
|
|
47
|
+
process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
})();
|
|
50
|
+
//# sourceMappingURL=lighthouse-badges.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lighthouse-badges.js","sourceRoot":"","sources":["../src/lighthouse-badges.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACnC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;AAEpB,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;IAChC,OAAO,CAAC,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAC1E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,MAAM,SAAS,GAAG,CAAC,GAAG,EAAE;IACtB,IAAI,CAAC;QACH,OAAO,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC;IAC7D,CAAC;IA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,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAC,EAAE,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { OutputMode } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Determine the output mode from CLI args. `-j`/`--json` takes priority
|
|
4
|
+
* over `-s`/`--svg`; `-b`/`--badge`/`--markdown` are explicit aliases for
|
|
5
|
+
* the (also default) markdown mode. `args[0]` is expected to be the URL,
|
|
6
|
+
* not a flag, so only `-`-prefixed entries are checked against the known
|
|
7
|
+
* flag set.
|
|
8
|
+
* @param args - CLI arguments, URL first followed by any flags.
|
|
9
|
+
* @throws {Error} If an argument starts with `-` but isn't a known flag.
|
|
10
|
+
*/
|
|
11
|
+
export declare function parseMode(args: string[]): OutputMode;
|
|
12
|
+
//# sourceMappingURL=parse-mode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-mode.d.ts","sourceRoot":"","sources":["../src/parse-mode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAY7C;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,UAAU,CAgBpD"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const KNOWN_FLAGS = {
|
|
2
|
+
'-j': 'json',
|
|
3
|
+
'--json': 'json',
|
|
4
|
+
'-s': 'svg',
|
|
5
|
+
'--svg': 'svg',
|
|
6
|
+
'-b': 'markdown',
|
|
7
|
+
'--badge': 'markdown',
|
|
8
|
+
'--markdown': 'markdown',
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Determine the output mode from CLI args. `-j`/`--json` takes priority
|
|
12
|
+
* over `-s`/`--svg`; `-b`/`--badge`/`--markdown` are explicit aliases for
|
|
13
|
+
* the (also default) markdown mode. `args[0]` is expected to be the URL,
|
|
14
|
+
* not a flag, so only `-`-prefixed entries are checked against the known
|
|
15
|
+
* flag set.
|
|
16
|
+
* @param args - CLI arguments, URL first followed by any flags.
|
|
17
|
+
* @throws {Error} If an argument starts with `-` but isn't a known flag.
|
|
18
|
+
*/
|
|
19
|
+
export function parseMode(args) {
|
|
20
|
+
const modes = new Set();
|
|
21
|
+
for (const arg of args) {
|
|
22
|
+
if (!arg.startsWith('-'))
|
|
23
|
+
continue;
|
|
24
|
+
const mode = KNOWN_FLAGS[arg];
|
|
25
|
+
if (!mode) {
|
|
26
|
+
throw new Error(`Unknown option: ${arg}`);
|
|
27
|
+
}
|
|
28
|
+
modes.add(mode);
|
|
29
|
+
}
|
|
30
|
+
if (modes.has('json'))
|
|
31
|
+
return 'json';
|
|
32
|
+
if (modes.has('svg'))
|
|
33
|
+
return 'svg';
|
|
34
|
+
return 'markdown';
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=parse-mode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-mode.js","sourceRoot":"","sources":["../src/parse-mode.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,GAA+B;IAC9C,IAAI,EAAE,MAAM;IACZ,QAAQ,EAAE,MAAM;IAChB,IAAI,EAAE,KAAK;IACX,OAAO,EAAE,KAAK;IACd,IAAI,EAAE,UAAU;IAChB,SAAS,EAAE,UAAU;IACrB,YAAY,EAAE,UAAU;CACzB,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,UAAU,SAAS,CAAC,IAAc;IACtC,MAAM,KAAK,GAAG,IAAI,GAAG,EAAc,CAAC;IAEpC,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC;YAAE,SAAS;QAEnC,MAAM,IAAI,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;QAC9B,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,mBAAmB,GAAG,EAAE,CAAC,CAAC;QAC5C,CAAC;QACD,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAClB,CAAC;IAED,IAAI,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAC;IACrC,IAAI,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACnC,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type ScoreLevel = 'good' | 'average' | 'poor' | 'unknown';
|
|
2
|
+
/**
|
|
3
|
+
* Classify a 0-100 Lighthouse score into the shared good/average/poor tiers
|
|
4
|
+
* (thresholds fixed by ADR-0003), or 'unknown' for a category Lighthouse
|
|
5
|
+
* couldn't evaluate (`null`). Markdown and SVG renderers each map this to
|
|
6
|
+
* their own color representation instead of duplicating the 90/50 checks.
|
|
7
|
+
* @param score - Lighthouse score (0-100), or null if unevaluated.
|
|
8
|
+
* @returns 'good' (>=90), 'average' (>=50), 'poor', or 'unknown' (null).
|
|
9
|
+
*/
|
|
10
|
+
export declare function getScoreLevel(score: number | null): ScoreLevel;
|
|
11
|
+
//# sourceMappingURL=score-level.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"score-level.d.ts","sourceRoot":"","sources":["../src/score-level.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAAC;AAEjE;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,UAAU,CAK9D"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Classify a 0-100 Lighthouse score into the shared good/average/poor tiers
|
|
3
|
+
* (thresholds fixed by ADR-0003), or 'unknown' for a category Lighthouse
|
|
4
|
+
* couldn't evaluate (`null`). Markdown and SVG renderers each map this to
|
|
5
|
+
* their own color representation instead of duplicating the 90/50 checks.
|
|
6
|
+
* @param score - Lighthouse score (0-100), or null if unevaluated.
|
|
7
|
+
* @returns 'good' (>=90), 'average' (>=50), 'poor', or 'unknown' (null).
|
|
8
|
+
*/
|
|
9
|
+
export function getScoreLevel(score) {
|
|
10
|
+
if (score === null)
|
|
11
|
+
return 'unknown';
|
|
12
|
+
if (score >= 90)
|
|
13
|
+
return 'good';
|
|
14
|
+
if (score >= 50)
|
|
15
|
+
return 'average';
|
|
16
|
+
return 'poor';
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=score-level.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"score-level.js","sourceRoot":"","sources":["../src/score-level.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAC,KAAoB;IAChD,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,SAAS,CAAC;IACrC,IAAI,KAAK,IAAI,EAAE;QAAE,OAAO,MAAM,CAAC;IAC/B,IAAI,KAAK,IAAI,EAAE;QAAE,OAAO,SAAS,CAAC;IAClC,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/bin/types.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CACpB;AAED,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,MAAM,GAAG,KAAK,CAAC"}
|
package/bin/types.js
ADDED
package/bin/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hidao/lighthouse-badges",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Generate Lighthouse score badges, JSON, or SVG using local Lighthouse",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"lighthouse-badges": "./bin/lighthouse-badges.js"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/hidao80/lighthouse-badges.git"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/hidao80/lighthouse-badges#readme",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/hidao80/lighthouse-badges/issues"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc",
|
|
19
|
+
"dev": "tsc --watch",
|
|
20
|
+
"lint": "biome check src/ tests/",
|
|
21
|
+
"test": "vitest",
|
|
22
|
+
"test:coverage": "vitest run --coverage",
|
|
23
|
+
"start": "node ./bin/lighthouse-badges.js",
|
|
24
|
+
"prepublishOnly": "bun run build",
|
|
25
|
+
"act": "act -l",
|
|
26
|
+
"act:audit": "act -j audit",
|
|
27
|
+
"act:build": "act -j build",
|
|
28
|
+
"act:lint": "act -j lint",
|
|
29
|
+
"act:test": "act -j test"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"lighthouse",
|
|
33
|
+
"badges",
|
|
34
|
+
"pagespeed",
|
|
35
|
+
"performance",
|
|
36
|
+
"accessibility",
|
|
37
|
+
"seo"
|
|
38
|
+
],
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
},
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=22.19"
|
|
45
|
+
},
|
|
46
|
+
"files": [
|
|
47
|
+
"bin"
|
|
48
|
+
],
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"chrome-launcher": "^1.2.1",
|
|
51
|
+
"lighthouse": "^13.5.0"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@biomejs/biome": "^2.5.14",
|
|
55
|
+
"@types/node": "^26.6.3",
|
|
56
|
+
"@vitest/coverage-v8": "^5.0.2",
|
|
57
|
+
"typescript": "^7.0.2",
|
|
58
|
+
"vitest": "^5.0.2"
|
|
59
|
+
},
|
|
60
|
+
"overrides": {
|
|
61
|
+
"@opentelemetry/core": ">=2.8.0"
|
|
62
|
+
}
|
|
63
|
+
}
|