Spaces:
Paused
Paused
| import {execSync, ExecSyncOptions} from 'child_process' | |
| import {als} from './context' | |
| /** | |
| * Executes a shell command using the current context's working directory. | |
| * Thread-safe for Probot. | |
| */ | |
| export const prixExec = ( | |
| command: string, | |
| options: ExecSyncOptions = {} | |
| ): string => { | |
| const context = als.getStore() | |
| const cwd = options.cwd || context?.workingDir || process.cwd() | |
| try { | |
| const result = execSync(command, { | |
| ...options, | |
| cwd, | |
| encoding: 'utf8' | |
| }) | |
| return result ? result.toString() : '' | |
| } catch (err: any) { | |
| const errorMessage = err.stderr ? err.stderr.toString() : err.message | |
| console.error(`prixExec failed: "${command}" in ${cwd}. Error: ${errorMessage}`) | |
| throw err | |
| } | |
| } | |