periderm-cli 0.1.44 → 0.1.47
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/dist/api.js +27 -0
- package/dist/index.js +98 -3
- package/dist/lighthouse.js +44 -0
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ Pre-launch scanner for web and mobile codebases — context-aware checks for JS,
|
|
|
10
10
|
npm install -g periderm-cli
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
Or use the install script from your Periderm dashboard docs (`curl -fsSL
|
|
13
|
+
Or use the install script from your Periderm dashboard docs (`curl -fsSL https://periderm-cli.vercel.app//install.sh | bash`).
|
|
14
14
|
|
|
15
15
|
## Quick start
|
|
16
16
|
|
package/dist/api.js
CHANGED
|
@@ -58,6 +58,33 @@ export async function uploadScan(token, result) {
|
|
|
58
58
|
return { error: e.message || "Network error: failed to reach server" };
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
+
export async function uploadLighthouseScan(token, result) {
|
|
62
|
+
const { apiUrl } = readConfig();
|
|
63
|
+
try {
|
|
64
|
+
const res = await fetch(`${apiUrl}/api/public/lighthouse`, {
|
|
65
|
+
method: "POST",
|
|
66
|
+
headers: {
|
|
67
|
+
"Content-Type": "application/json",
|
|
68
|
+
"x-periderm-token": token,
|
|
69
|
+
},
|
|
70
|
+
body: JSON.stringify({
|
|
71
|
+
url: result.url,
|
|
72
|
+
performance_score: result.performance_score,
|
|
73
|
+
accessibility_score: result.accessibility_score,
|
|
74
|
+
best_practices_score: result.best_practices_score,
|
|
75
|
+
seo_score: result.seo_score,
|
|
76
|
+
metrics: result.metrics
|
|
77
|
+
}),
|
|
78
|
+
});
|
|
79
|
+
if (!res.ok) {
|
|
80
|
+
return { error: `${res.status} ${await res.text()}` };
|
|
81
|
+
}
|
|
82
|
+
return (await res.json());
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
return { error: e.message || "Network error: failed to reach server" };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
61
88
|
export async function fetchCloudPolicies(token) {
|
|
62
89
|
const { apiUrl } = readConfig();
|
|
63
90
|
try {
|
package/dist/index.js
CHANGED
|
@@ -9,13 +9,15 @@ import { runDeepReview } from "./review/deep.js";
|
|
|
9
9
|
import { printTerminal } from "./report/terminal.js";
|
|
10
10
|
import { getAiInstructions } from "./report/ai-instructions.js";
|
|
11
11
|
import { readConfig, writeConfig } from "./config.js";
|
|
12
|
-
import { verifyToken, uploadScan, fetchCloudPolicies } from "./api.js";
|
|
12
|
+
import { verifyToken, uploadScan, uploadLighthouseScan, fetchCloudPolicies } from "./api.js";
|
|
13
13
|
import http from "node:http";
|
|
14
|
+
import { execSync } from "node:child_process";
|
|
14
15
|
import ora from "ora";
|
|
15
16
|
import { PERIDERM_ASCII } from "./constants.js";
|
|
16
17
|
import { PRE_SCAN_MESSAGES, UPLOAD_MESSAGES, startRotatingMessages, finishRotatingMessages } from "./loading-messages.js";
|
|
17
18
|
import { formatScanPath } from "./scanner/progress.js";
|
|
18
19
|
import { reportCliError } from "./error-report.js";
|
|
20
|
+
import { runLocalLighthouse } from "./lighthouse.js";
|
|
19
21
|
function requireAuth() {
|
|
20
22
|
console.info("");
|
|
21
23
|
console.info(chalk.bold.hex("#FF4D00")("▸_ Periderm CLI"));
|
|
@@ -378,6 +380,11 @@ program
|
|
|
378
380
|
console.info(chalk.white(" 3. Log out ") + chalk.hex("#FF4D00")("$ periderm logout"));
|
|
379
381
|
console.info("");
|
|
380
382
|
console.info(chalk.white("Need help? Visit ") + chalk.underline.cyan(`${apiUrl}/docs`) + chalk.white("\n"));
|
|
383
|
+
// Auto-register the URI scheme natively in case postinstall failed
|
|
384
|
+
try {
|
|
385
|
+
await registerUriHandler();
|
|
386
|
+
}
|
|
387
|
+
catch (e) { /* silent fail */ }
|
|
381
388
|
server.close();
|
|
382
389
|
process.exit(0);
|
|
383
390
|
}
|
|
@@ -403,6 +410,47 @@ program
|
|
|
403
410
|
}
|
|
404
411
|
});
|
|
405
412
|
});
|
|
413
|
+
program
|
|
414
|
+
.command("lighthouse")
|
|
415
|
+
.description("Run a local Lighthouse audit using Headless Chrome")
|
|
416
|
+
.argument("<url>", "The URL to scan (e.g. http://localhost:3000)")
|
|
417
|
+
.action(async (url) => {
|
|
418
|
+
try {
|
|
419
|
+
const result = await runLocalLighthouse(url);
|
|
420
|
+
console.info("");
|
|
421
|
+
console.info(chalk.bold.cyan("▸_ Lighthouse Scan Complete"));
|
|
422
|
+
console.info(chalk.white("──────────────────────────────────────────"));
|
|
423
|
+
console.info(chalk.bold.white("Performance : ") + chalk.yellow(`${result.performance_score}/100`));
|
|
424
|
+
console.info(chalk.bold.white("Accessibility : ") + chalk.yellow(`${result.accessibility_score}/100`));
|
|
425
|
+
console.info(chalk.bold.white("Best Practices : ") + chalk.yellow(`${result.best_practices_score}/100`));
|
|
426
|
+
console.info(chalk.bold.white("SEO : ") + chalk.yellow(`${result.seo_score}/100`));
|
|
427
|
+
console.info("");
|
|
428
|
+
console.info(chalk.bold.white("First Contentful Paint : ") + chalk.gray(result.metrics.fcp));
|
|
429
|
+
console.info(chalk.bold.white("Largest Contentful Paint : ") + chalk.gray(result.metrics.lcp));
|
|
430
|
+
console.info(chalk.bold.white("Total Blocking Time : ") + chalk.gray(result.metrics.tbt));
|
|
431
|
+
console.info(chalk.bold.white("Speed Index : ") + chalk.gray(result.metrics.si));
|
|
432
|
+
console.info("");
|
|
433
|
+
const cfg = readConfig();
|
|
434
|
+
if (!cfg.token) {
|
|
435
|
+
console.info(chalk.yellow("no token configured — run `periderm login` first to sync to dashboard."));
|
|
436
|
+
}
|
|
437
|
+
else {
|
|
438
|
+
const uploadSpinner = ora({ text: "Uploading scan...", color: "cyan" }).start();
|
|
439
|
+
const uploadPayload = { ...result, url };
|
|
440
|
+
const res = await uploadLighthouseScan(cfg.token, uploadPayload);
|
|
441
|
+
if (res.error) {
|
|
442
|
+
uploadSpinner.fail(`upload failed: ${res.error}`);
|
|
443
|
+
}
|
|
444
|
+
else {
|
|
445
|
+
uploadSpinner.succeed(`Uploaded! View it at: ${chalk.underline.cyan(`${cfg.apiUrl}/dashboard/lighthouse`)}`);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
catch (e) {
|
|
450
|
+
console.error(chalk.red(e.message));
|
|
451
|
+
process.exit(1);
|
|
452
|
+
}
|
|
453
|
+
});
|
|
406
454
|
program
|
|
407
455
|
.command("whoami")
|
|
408
456
|
.description("Verify the current token.")
|
|
@@ -429,7 +477,48 @@ program
|
|
|
429
477
|
console.info(chalk.bold.white("Plan : ") + chalk.magenta(formatPlan));
|
|
430
478
|
console.info(chalk.bold.white("Quota : ") + chalk.yellow(`${formatQuota} scans`));
|
|
431
479
|
console.info(chalk.bold.white("API : ") + chalk.cyan(cfg.apiUrl));
|
|
432
|
-
|
|
480
|
+
});
|
|
481
|
+
async function registerUriHandler() {
|
|
482
|
+
if (os.platform() === "linux") {
|
|
483
|
+
const desktopFilePath = path.join(os.homedir(), ".local", "share", "applications", "periderm.desktop");
|
|
484
|
+
const desktopFileContent = `[Desktop Entry]\nName=Periderm CLI\nExec=bash -l -c 'periderm "%u"'\nType=Application\nTerminal=true\nMimeType=x-scheme-handler/periderm;\n`;
|
|
485
|
+
await fs.mkdir(path.dirname(desktopFilePath), { recursive: true });
|
|
486
|
+
await fs.writeFile(desktopFilePath, desktopFileContent, { mode: 0o755 });
|
|
487
|
+
execSync("update-desktop-database ~/.local/share/applications", { stdio: "ignore" });
|
|
488
|
+
execSync("xdg-mime default periderm.desktop x-scheme-handler/periderm", { stdio: "ignore" });
|
|
489
|
+
}
|
|
490
|
+
else if (os.platform() === "win32") {
|
|
491
|
+
execSync('reg add "HKCU\\Software\\Classes\\periderm" /v "URL Protocol" /t REG_SZ /d "" /f', { stdio: "ignore" });
|
|
492
|
+
execSync('reg add "HKCU\\Software\\Classes\\periderm\\shell\\open\\command" /ve /t REG_SZ /d "\\"cmd\\" /c periderm \\"%1\\"" /f', { stdio: "ignore" });
|
|
493
|
+
}
|
|
494
|
+
else if (os.platform() === "darwin") {
|
|
495
|
+
const appPath = path.join(os.homedir(), "Applications", "PeridermHandler.app");
|
|
496
|
+
execSync(`osacompile -e 'on open location this_URL' -e 'do shell script "PATH=/usr/local/bin:/opt/homebrew/bin:$PATH periderm " & quoted form of this_URL' -e 'end open location' -o "${appPath}"`);
|
|
497
|
+
const plistPath = path.join(appPath, "Contents", "Info.plist");
|
|
498
|
+
execSync(`/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes array" "${plistPath}"`);
|
|
499
|
+
execSync(`/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:0 dict" "${plistPath}"`);
|
|
500
|
+
execSync(`/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:0:CFBundleURLName string 'Periderm CLI'" "${plistPath}"`);
|
|
501
|
+
execSync(`/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:0:CFBundleURLSchemes array" "${plistPath}"`);
|
|
502
|
+
execSync(`/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:0:CFBundleURLSchemes:0 string 'periderm'" "${plistPath}"`);
|
|
503
|
+
execSync(`/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -f "${appPath}"`, { stdio: "ignore" });
|
|
504
|
+
}
|
|
505
|
+
else {
|
|
506
|
+
throw new Error(`Unsupported platform: ${os.platform()}`);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
program
|
|
510
|
+
.command("register")
|
|
511
|
+
.description("Register the periderm:// URI handler for web dashboard integration (Cross-Platform)")
|
|
512
|
+
.action(async () => {
|
|
513
|
+
try {
|
|
514
|
+
await registerUriHandler();
|
|
515
|
+
console.info(chalk.bold.green("✓ Successfully registered the periderm:// URI scheme."));
|
|
516
|
+
console.info(chalk.white("You can now trigger Lighthouse audits directly from the web dashboard."));
|
|
517
|
+
}
|
|
518
|
+
catch (e) {
|
|
519
|
+
console.error(chalk.red("Failed to register URI scheme: " + e.message));
|
|
520
|
+
process.exit(1);
|
|
521
|
+
}
|
|
433
522
|
});
|
|
434
523
|
program
|
|
435
524
|
.command("logout")
|
|
@@ -457,7 +546,13 @@ if (process.argv.length === 2) {
|
|
|
457
546
|
program.help();
|
|
458
547
|
}
|
|
459
548
|
else {
|
|
460
|
-
|
|
549
|
+
let args = process.argv;
|
|
550
|
+
// Intercept OS-level custom URI scheme triggers
|
|
551
|
+
if (args.length === 3 && args[2].startsWith("periderm://lighthouse?url=")) {
|
|
552
|
+
const url = decodeURIComponent(args[2].split("url=")[1]);
|
|
553
|
+
args = [args[0], args[1], "lighthouse", url];
|
|
554
|
+
}
|
|
555
|
+
mainDone = program.parseAsync(args).catch(async (e) => {
|
|
461
556
|
console.error(e);
|
|
462
557
|
const err = e instanceof Error ? e : new Error(String(e));
|
|
463
558
|
await reportCliError({
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
import * as chromeLauncher from "chrome-launcher";
|
|
3
|
+
import ora from "ora";
|
|
4
|
+
// We use dynamic import for lighthouse because its types and module resolution can be tricky
|
|
5
|
+
export async function runLocalLighthouse(url) {
|
|
6
|
+
const spinner = ora({ text: `Launching Headless Chrome...`, color: "cyan" }).start();
|
|
7
|
+
try {
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
const lighthouse = (await import("lighthouse")).default;
|
|
10
|
+
const chrome = await chromeLauncher.launch({
|
|
11
|
+
chromeFlags: ["--headless", "--no-sandbox", "--disable-gpu"]
|
|
12
|
+
});
|
|
13
|
+
spinner.text = `Running Lighthouse audit on ${url}... This usually takes 10-20 seconds.`;
|
|
14
|
+
const options = {
|
|
15
|
+
logLevel: "error",
|
|
16
|
+
output: "json",
|
|
17
|
+
onlyCategories: ["performance", "accessibility", "best-practices", "seo"],
|
|
18
|
+
port: chrome.port,
|
|
19
|
+
};
|
|
20
|
+
const runnerResult = await lighthouse(url, options);
|
|
21
|
+
await chrome.kill();
|
|
22
|
+
spinner.succeed(`Audit complete for ${url}`);
|
|
23
|
+
if (!runnerResult || !runnerResult.lhr) {
|
|
24
|
+
throw new Error("Lighthouse returned no data.");
|
|
25
|
+
}
|
|
26
|
+
const { categories, audits } = runnerResult.lhr;
|
|
27
|
+
return {
|
|
28
|
+
performance_score: Math.round((categories.performance?.score ?? 0) * 100),
|
|
29
|
+
accessibility_score: Math.round((categories.accessibility?.score ?? 0) * 100),
|
|
30
|
+
best_practices_score: Math.round((categories['best-practices']?.score ?? 0) * 100),
|
|
31
|
+
seo_score: Math.round((categories.seo?.score ?? 0) * 100),
|
|
32
|
+
metrics: {
|
|
33
|
+
fcp: audits['first-contentful-paint'].displayValue,
|
|
34
|
+
si: audits['speed-index'].displayValue,
|
|
35
|
+
lcp: audits['largest-contentful-paint'].displayValue,
|
|
36
|
+
tbt: audits['total-blocking-time'].displayValue,
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
spinner.fail(`Lighthouse audit failed: ${err.message}`);
|
|
42
|
+
throw err;
|
|
43
|
+
}
|
|
44
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "periderm-cli",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.47",
|
|
4
|
+
"description": "Periderm CLI: The Local-First Security & Performance Code Scanner",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"preferGlobal": true,
|
|
7
7
|
"bin": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"pre-launch",
|
|
18
18
|
"security",
|
|
19
19
|
"scanning",
|
|
20
|
-
"javascript",
|
|
20
|
+
"javascript",
|
|
21
21
|
"typescript",
|
|
22
22
|
"jsx",
|
|
23
23
|
"tsx",
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"license": "MIT",
|
|
48
48
|
"scripts": {
|
|
49
49
|
"build": "tsc -p tsconfig.json && chmod +x dist/bin.js",
|
|
50
|
+
"postinstall": "node dist/bin.js register || true",
|
|
50
51
|
"postpublish": "cd ../../ && tsx --env-file=.env scripts/broadcast-update.ts",
|
|
51
52
|
"dev": "tsx src/index.ts",
|
|
52
53
|
"start": "node dist/index.js"
|
|
@@ -56,8 +57,10 @@
|
|
|
56
57
|
"@babel/traverse": "^7.25.0",
|
|
57
58
|
"@babel/types": "^7.25.0",
|
|
58
59
|
"chalk": "^5.3.0",
|
|
60
|
+
"chrome-launcher": "^1.2.1",
|
|
59
61
|
"commander": "^12.1.0",
|
|
60
62
|
"fast-glob": "^3.3.2",
|
|
63
|
+
"lighthouse": "^13.4.0",
|
|
61
64
|
"open": "^10.1.0",
|
|
62
65
|
"ora": "^9.4.1"
|
|
63
66
|
},
|