PRIX / src /utils.ts
Rachit-Tw's picture
chore: optimize temp storage, caching and file retrieval for HF hosting
e8cbb4a
Raw
History Blame
740 Bytes
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
}
}