@tacone/prosey 0.2.3 → 0.2.6

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/src/pager.ts ADDED
@@ -0,0 +1,23 @@
1
+ import { execSync } from "node:child_process";
2
+
3
+ export function hasCommand(cmd: string): boolean {
4
+ try {
5
+ execSync(`command -v ${cmd} 2>/dev/null`, { stdio: "ignore" });
6
+ return true;
7
+ } catch {
8
+ return false;
9
+ }
10
+ }
11
+
12
+ export function detectPager(cfgPager?: string): string | null {
13
+ const env = process.env.PROSEY_PAGER;
14
+ if (env !== undefined && env !== "" && env !== "auto") return env;
15
+
16
+ if (cfgPager !== undefined && cfgPager !== "" && cfgPager !== "auto") return cfgPager;
17
+
18
+ if (hasCommand("bat")) return "bat -lmd --style plain";
19
+ if (hasCommand("glow")) return "glow -p";
20
+ if (hasCommand("mdcat")) return "mdcat -l -p";
21
+ if (hasCommand("less")) return "less";
22
+ return null;
23
+ }
@@ -0,0 +1,32 @@
1
+ import { debug } from "./debug";
2
+ import pkg from "../package.json";
3
+
4
+ const TIMEOUT_MS = 3000;
5
+
6
+ const registryUrl = `https://registry.npmjs.org/${pkg.name}/latest`;
7
+
8
+ export async function checkVersion(): Promise<string | null> {
9
+ try {
10
+ const controller = new AbortController();
11
+ const timer = setTimeout(() => controller.abort(), TIMEOUT_MS);
12
+
13
+ const res = await fetch(registryUrl, { signal: controller.signal });
14
+ clearTimeout(timer);
15
+
16
+ if (!res.ok) {
17
+ debug("Version check failed: HTTP", res.status);
18
+ return null;
19
+ }
20
+
21
+ const data = (await res.json()) as { version?: string };
22
+ if (!data.version) {
23
+ debug("Version check: no version field in response");
24
+ return null;
25
+ }
26
+
27
+ return data.version;
28
+ } catch (err) {
29
+ debug("Version check error:", err instanceof Error ? err.message : String(err));
30
+ return null;
31
+ }
32
+ }