Debian Codegraph @

cli/tools-cli/src/scripts/settings.ts

raw symbols SCIP
1 import { execFileSync } from "node:child_process";
2
3 export function commandStatus(command: string, args: string[]): boolean {
4 try {
5 execFileSync(command, args);
6 return true;
7 } catch {
8 return false;
9 }
10 }
11
12 let IS_FIG_INSTALLED: boolean | undefined;
13 export function isFigInstalled(): boolean {
14 if (IS_FIG_INSTALLED === undefined) {
15 IS_FIG_INSTALLED = commandStatus("fig", ["--version"]);
16 }
17 return IS_FIG_INSTALLED;
18 }
19
20 let IS_CW_INSTALLED: boolean | undefined;
21 export function isCwInstalled(): boolean {
22 if (IS_CW_INSTALLED === undefined) {
23 IS_CW_INSTALLED = commandStatus("cw", ["--version"]);
24 }
25 return IS_CW_INSTALLED;
26 }
27
28 let IS_Q_INSTALLED: boolean | undefined;
29 export function isQInstalled(): boolean {
30 if (IS_Q_INSTALLED === undefined) {
31 IS_Q_INSTALLED = commandStatus("q", ["--version"]);
32 }
33 return IS_Q_INSTALLED;
34 }
35
36 export function setSetting(key: string, value: unknown) {
37 if (isQInstalled()) {
38 commandStatus("q", ["settings", key, JSON.stringify(value)]);
39 } else if (isCwInstalled()) {
40 commandStatus("cw", ["settings", key, JSON.stringify(value)]);
41 } else if (isFigInstalled()) {
42 commandStatus("fig", ["settings", key, JSON.stringify(value)]);
43 }
44 }