CoolFace
Apppublic

delqhi/sin-github-issues

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
command.ts25 linesDownload Raw Back to src
1import { execFile } from 'node:child_process';2import { promisify } from 'node:util';3 4const execFileAsync = promisify(execFile);5 6export async function runCommand(command: string, args: string[], cwd?: string) {7  try {8    const result = await execFileAsync(command, args, {9      cwd,10      maxBuffer: 1024 * 1024 * 8,11      env: process.env,12    });13    return { stdout: result.stdout.trim(), stderr: result.stderr.trim() };14  } catch (error) {15    const failure = error as { stdout?: string; stderr?: string; message?: string };16    const details = (failure.stderr || failure.stdout || failure.message || 'command_failed').trim();17    throw new Error(`${command}_failed:${details}`);18  }19}20 21export async function runJsonCommand<T>(command: string, args: string[], cwd?: string): Promise<T> {22  const result = await runCommand(command, args, cwd);23  return JSON.parse(result.stdout) as T;24}25