MCPcopy Create free account
hub / github.com/Snapchat/Valdi / spawnCliCommand

Function spawnCliCommand

npm_modules/cli/src/utils/cliUtils.ts:22–68  ·  view source on GitHub ↗
(
  command: string,
  cwd: string | undefined,
  stdioMode: StdioOptions,
  quiet: boolean,
  rejectOnFailure: boolean,
)

Source from the content-addressed store, hash-verified

20}
21
22export function spawnCliCommand(
23 command: string,
24 cwd: string | undefined,
25 stdioMode: StdioOptions,
26 quiet: boolean,
27 rejectOnFailure: boolean,
28): Promise<CommandResult> {
29 return new Promise((resolve, reject) => {
30 const child = spawn(command, {
31 stdio: stdioMode,
32 shell: getShell(),
33 cwd: cwd,
34 env: { ...process.env, FORCE_COLOR: '1' },
35 });
36
37 // When using mode = 'inherit', the following output and error capture is a no-op
38
39 let stdout = '';
40 let stderr = '';
41
42 child.stdout?.on('data', (data: Buffer) => {
43 stdout += data.toString();
44 if (!quiet) {
45 process.stdout.write(stdout);
46 }
47 });
48
49 child.stderr?.on('data', (data: Buffer) => {
50 stderr += data.toString();
51 if (!quiet) {
52 process.stderr.write(stderr);
53 }
54 });
55
56 child.on('close', code => {
57 if (code !== 0 && rejectOnFailure) {
58 reject(new Error(stderr.trim()));
59 } else {
60 resolve({ returnCode: code ?? 0, stdout, stderr });
61 }
62 });
63
64 child.on('error', err => {
65 reject(err);
66 });
67 });
68}
69
70export async function getUserChoice<T>(
71 choices: Array<CliChoice<T> | Separator>,

Callers 5

installAndroidApkFunction · 0.90
startAndroidActivityFunction · 0.90
spawnCommandMethod · 0.90
hotreloadResolvedTargetFunction · 0.90
runShellMethod · 0.90

Calls 7

getShellFunction · 0.85
rejectFunction · 0.85
onMethod · 0.65
toStringMethod · 0.65
writeMethod · 0.65
resolveFunction · 0.50
trimMethod · 0.45

Tested by

no test coverage detected