import { spawn } from 'node:child_process';
export function runBashScript(command, args = [], options = {}) {
    return new Promise((resolve, reject) => {
        const bashArgs = ['-c', command];
        if (args.length > 0) {
            bashArgs.push('--', ...args);
        }
        const child = spawn('/bin/bash', bashArgs, {
            ...options,
            shell: false
        });
        let stdout = '';
        let stderr = '';
        child.stdout.setEncoding('utf8');
        child.stderr.setEncoding('utf8');
        child.stdout.on('data', chunk => {
            stdout += chunk;
        });
        child.stderr.on('data', chunk => {
            stderr += chunk;
        });
        child.on('error', reject);
        child.on('close', exitCode => {
            resolve({ stdout, stderr, exitCode });
        });
    });
}
