@spiderjew/lh-report-cli 1.1.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/README.md ADDED
@@ -0,0 +1,46 @@
1
+ <div align="center">
2
+
3
+ # ⚔ LH Report CLI
4
+
5
+ **Lighthouse audits to polished PDF reports**
6
+
7
+ <img src="https://img.shields.io/badge/Pro-%2429-10b981?style=for-the-badge&logo=gumroad" alt="Pro 29" /> <a href="https://harryherzberg.gumroad.com/l/lh-report">Buy Pro</a>
8
+ </div>
9
+
10
+ ## ✨ Features
11
+
12
+ | Feature | Benefit |
13
+ |---------|---------|
14
+ | Full LH Audit | Perf/accessibility |
15
+ | Custom Categories | Select metrics |
16
+ | PDF Export | Branded pro reports |
17
+ | Batch URLs | Site-wide scan |
18
+ | Trends Tracking | Serial runs |
19
+
20
+ ## šŸš€ Quick Start
21
+
22
+ ```bash
23
+ npx lh-report@latest --help
24
+
25
+ # Single
26
+ lh-report https://example.com -f json
27
+
28
+ # Batch
29
+ lh-report @urls.txt -f pdf -l DEMO-PRO
30
+
31
+ # Categories
32
+ lh-report site.com --categories performance,seo -f html -l DEMO-PRO -o reports/
33
+ ```
34
+
35
+
36
+ ## šŸ’Ž Go Pro - Lifetime $29
37
+
38
+ - āœ… Unlimited runs
39
+ - šŸ“„ PDF reports
40
+ - šŸ¢ Commercial use
41
+ - šŸ’¬ Support
42
+
43
+ <img src="https://img.shields.io/badge/Buy_Pro-%2429-FF6B35?style=for-the-badge&logo=gumroad" alt="Buy Pro" /> <a href="https://harryherzberg.gumroad.com/l/lh-report">Buy Now</a>
44
+
45
+ ---
46
+ šŸ‘Øā€šŸ’» [Harry Herzberg](https://github.com/harryherzberg) | šŸ™ [GitHub](https://github.com/harryherzberg/clawd/tree/main/apps/lh-report-cli)
package/index.js ADDED
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { program } = require('commander');
4
+ const lighthouse = require('lighthouse');
5
+ const puppeteer = require('puppeteer');
6
+ const fs = require('fs');
7
+ const path = require('path');
8
+
9
+ program
10
+ .name('lh-report')
11
+ .description('Lighthouse audit CLI: JSON/HTML/PDF reports - Batch mode!')
12
+ .argument('[input...]', 'URL(s) or @urls.txt')
13
+ .option('-f, --format &lt;type&gt;', 'json|html|pdf (default: json)', 'json')
14
+ .option('-l, --license &lt;key&gt;', 'Pro license for HTML/PDF')
15
+ .option('-o, --output &lt;dir&gt;', 'output directory', '.')
16
+ .option('--categories &lt;list&gt;', 'comma sep: performance,accessibility,best-practices,seo (default all)', 'performance,accessibility,best-practices,seo')
17
+ .action(async (inputs, cmd) =&gt; {
18
+ let urls = inputs;
19
+ if (inputs.length === 1 &amp;&amp; inputs[0].startsWith('@')) {
20
+ const filePath = inputs[0].slice(1);
21
+ urls = fs.readFileSync(filePath, 'utf8').split(/\\r?\\n/).map(l =&gt; l.trim()).filter(Boolean);
22
+ }
23
+ if (!urls.length) {
24
+ console.log('No URLs provided.');
25
+ program.help();
26
+ return;
27
+ }
28
+ const format = cmd.format.toLowerCase();
29
+ const license = cmd.license;
30
+ const isValidLicense = license === 'DEMO-PRO' || (license &amp;&amp; license.startsWith('pro-') &amp;&amp; license.length &gt; 10);
31
+ if (['html', 'pdf'].includes(format) &amp;&amp; !isValidLicense) {
32
+ console.error('Pro formats (html/pdf) require license key. Demo: --license DEMO-PRO');
33
+ process.exit(1);
34
+ }
35
+ const outDir = cmd.output;
36
+ if (!fs.existsSync(outDir)) fs.mkdirSync(outDir, {recursive: true});
37
+ const categories = cmd.categories.split(',').map(c =&gt; c.trim());
38
+ const flags = {
39
+ logLevel: 'info',
40
+ output: format === 'html' ? 'html' : 'json',
41
+ onlyCategories: categories,
42
+ };
43
+ for (const url of urls) {
44
+ try {
45
+ console.log(`\\n⚔ Auditing ${url}...`);
46
+ const { lhr, report } = await lighthouse(url, flags, null);
47
+ const safeName = url.replace(/[^a-z0-9]/gi, '-').replace(/-+/g, '-').slice(0,50) + '-lh';
48
+ const outputBase = path.join(outDir, safeName);
49
+ const ext = format;
50
+ const filename = `${outputBase}.${ext}`;
51
+ if (format === 'json') {
52
+ fs.writeFileSync(filename, JSON.stringify(lhr, null, 2));
53
+ console.log(`āœ… JSON: ${filename}`);
54
+ } else if (format === 'html') {
55
+ fs.writeFileSync(filename, report);
56
+ console.log(`āœ… HTML: ${filename}`);
57
+ } else if (format === 'pdf') {
58
+ console.log('šŸ–Øļø PDF...');
59
+ const browser = await puppeteer.launch({ headless: 'new', args: ['--no-sandbox'] });
60
+ const page = await browser.newPage();
61
+ // Prettier: add custom CSS to LH report
62
+ const customCSS = `
63
+ &lt;style&gt;
64
+ body { font-family: -apple-system, sans-serif; margin: 0; }
65
+ .lh-container { max-width: 100%; }
66
+ .lh-metric { border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
67
+ .lh-metric--pass { border-left: 4px solid #28a745; }
68
+ .lh-metric--average { border-left: 4px solid #ffc107; }
69
+ .lh-metric--fail { border-left: 4px solid #dc3545; }
70
+ &lt;/style&gt;`;
71
+ const enhancedReport = report.replace('&lt;/head&gt;', customCSS + '&lt;/head&gt;');
72
+ await page.setContent(enhancedReport, { waitUntil: 'networkidle0' });
73
+ const pdf = await page.pdf({
74
+ format: 'A4',
75
+ printBackground: true,
76
+ margin: { top: '10mm', bottom: '10mm' }
77
+ });
78
+ await browser.close();
79
+ fs.writeFileSync(filename, pdf);
80
+ console.log(`āœ… PDF: ${filename}`);
81
+ }
82
+ } catch (err) {
83
+ console.error(`āŒ ${url}: ${err.message}`);
84
+ }
85
+ }
86
+ });
87
+
88
+ program.parse();
Binary file
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@spiderjew/lh-report-cli",
3
+ "version": "1.1.0",
4
+ "description": "CLI to generate Lighthouse audit reports JSON/HTML/PDF",
5
+ "main": "index.js",
6
+ "bin": {
7
+ "lh-report": "index.js"
8
+ },
9
+ "scripts": {
10
+ "test": "echo \\\"No test specified\\\" &amp;&amp; exit 0"
11
+ },
12
+ "keywords": [
13
+ "lighthouse",
14
+ "performance",
15
+ "seo",
16
+ "audit",
17
+ "cli",
18
+ "pdf"
19
+ ],
20
+ "author": "Harry Herzberg",
21
+ "license": "MIT",
22
+ "type": "commonjs",
23
+ "dependencies": {
24
+ "lighthouse": "^12.2.0",
25
+ "puppeteer": "^23.5.3",
26
+ "commander": "^12.1.0"
27
+ },
28
+ "publishConfig": {
29
+ "access": "public"
30
+ }
31
+ }