Spaces:
Paused
Paused
Download src/command.ts from delqhi/sin-github-issues: direct link, hf CLI and curl.
- Browser
- Download file 895 Bytes
-
https://huggingface.co/spaces/delqhi/sin-github-issues/resolve/main/src/command.ts
- Command line
-
hf download hf://spaces/delqhi/sin-github-issues/src/command.ts
-
curl -L -o command.ts https://huggingface.co/spaces/delqhi/sin-github-issues/resolve/main/src/command.ts
895 Bytes
| import { execFile } from 'node:child_process'; | |
| import { promisify } from 'node:util'; | |
| const execFileAsync = promisify(execFile); | |
| export async function runCommand(command: string, args: string[], cwd?: string) { | |
| try { | |
| const result = await execFileAsync(command, args, { | |
| cwd, | |
| maxBuffer: 1024 * 1024 * 8, | |
| env: process.env, | |
| }); | |
| return { stdout: result.stdout.trim(), stderr: result.stderr.trim() }; | |
| } catch (error) { | |
| const failure = error as { stdout?: string; stderr?: string; message?: string }; | |
| const details = (failure.stderr || failure.stdout || failure.message || 'command_failed').trim(); | |
| throw new Error(`${command}_failed:${details}`); | |
| } | |
| } | |
| export async function runJsonCommand<T>(command: string, args: string[], cwd?: string): Promise<T> { | |
| const result = await runCommand(command, args, cwd); | |
| return JSON.parse(result.stdout) as T; | |
| } | |