periderm-cli 0.1.46 → 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/dist/index.js +34 -32
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -380,6 +380,11 @@ program
|
|
|
380
380
|
console.info(chalk.white(" 3. Log out ") + chalk.hex("#FF4D00")("$ periderm logout"));
|
|
381
381
|
console.info("");
|
|
382
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 */ }
|
|
383
388
|
server.close();
|
|
384
389
|
process.exit(0);
|
|
385
390
|
}
|
|
@@ -473,43 +478,40 @@ program
|
|
|
473
478
|
console.info(chalk.bold.white("Quota : ") + chalk.yellow(`${formatQuota} scans`));
|
|
474
479
|
console.info(chalk.bold.white("API : ") + chalk.cyan(cfg.apiUrl));
|
|
475
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
|
+
}
|
|
476
509
|
program
|
|
477
510
|
.command("register")
|
|
478
511
|
.description("Register the periderm:// URI handler for web dashboard integration (Cross-Platform)")
|
|
479
512
|
.action(async () => {
|
|
480
513
|
try {
|
|
481
|
-
|
|
482
|
-
const desktopFilePath = path.join(os.homedir(), ".local", "share", "applications", "periderm.desktop");
|
|
483
|
-
const desktopFileContent = `[Desktop Entry]\nName=Periderm CLI\nExec=bash -l -c 'periderm "%u"'\nType=Application\nTerminal=true\nMimeType=x-scheme-handler/periderm;\n`;
|
|
484
|
-
await fs.mkdir(path.dirname(desktopFilePath), { recursive: true });
|
|
485
|
-
await fs.writeFile(desktopFilePath, desktopFileContent, { mode: 0o755 });
|
|
486
|
-
execSync("update-desktop-database ~/.local/share/applications", { stdio: "ignore" });
|
|
487
|
-
execSync("xdg-mime default periderm.desktop x-scheme-handler/periderm", { stdio: "ignore" });
|
|
488
|
-
}
|
|
489
|
-
else if (os.platform() === "win32") {
|
|
490
|
-
// Windows Registry
|
|
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
|
-
// macOS app bundle using osacompile
|
|
496
|
-
const appPath = path.join(os.homedir(), "Applications", "PeridermHandler.app");
|
|
497
|
-
// Create AppleScript app
|
|
498
|
-
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}"`);
|
|
499
|
-
// Add URL scheme to Info.plist
|
|
500
|
-
const plistPath = path.join(appPath, "Contents", "Info.plist");
|
|
501
|
-
execSync(`/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes array" "${plistPath}"`);
|
|
502
|
-
execSync(`/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:0 dict" "${plistPath}"`);
|
|
503
|
-
execSync(`/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:0:CFBundleURLName string 'Periderm CLI'" "${plistPath}"`);
|
|
504
|
-
execSync(`/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:0:CFBundleURLSchemes array" "${plistPath}"`);
|
|
505
|
-
execSync(`/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:0:CFBundleURLSchemes:0 string 'periderm'" "${plistPath}"`);
|
|
506
|
-
// Refresh LaunchServices
|
|
507
|
-
execSync(`/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -f "${appPath}"`, { stdio: "ignore" });
|
|
508
|
-
}
|
|
509
|
-
else {
|
|
510
|
-
console.info(chalk.red(`Unsupported platform: ${os.platform()}`));
|
|
511
|
-
process.exit(1);
|
|
512
|
-
}
|
|
514
|
+
await registerUriHandler();
|
|
513
515
|
console.info(chalk.bold.green("✓ Successfully registered the periderm:// URI scheme."));
|
|
514
516
|
console.info(chalk.white("You can now trigger Lighthouse audits directly from the web dashboard."));
|
|
515
517
|
}
|