forked from pullfrog/pullfrog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.ts
More file actions
31 lines (28 loc) · 790 Bytes
/
Copy pathcli.ts
File metadata and controls
31 lines (28 loc) · 790 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* CLI utilities
*/
import { spawnSync } from "node:child_process";
import { existsSync } from "node:fs";
// re-export logging utilities for backward compatibility
export {
formatIndentedField,
formatJsonValue,
formatUsageSummary,
log,
writeSummary,
} from "./log.ts";
/**
* Finds a CLI executable path by checking if it's installed globally
* @param name The name of the CLI executable to find
* @returns The path to the CLI executable, or null if not found
*/
export function findCliPath(name: string): string | null {
const result = spawnSync("which", [name], { encoding: "utf-8" });
if (result.status === 0 && result.stdout) {
const cliPath = result.stdout.trim();
if (cliPath && existsSync(cliPath)) {
return cliPath;
}
}
return null;
}