@k1ssh/qbot
Version:
QBot SDK is a set of APIs for creating and managing microservices, and Kubernetes deployments. This is the core package for QBot AI.
23 lines (22 loc) • 767 B
JavaScript
import { exec } from 'child_process';
import { promisify } from 'util';
export const execAsync = promisify(exec);
/**
* Execute a shell command asynchronously without context of the current directory
* @param command command to execute
* @returns
*/
export async function executeCommand(command) {
const { stdout, stderr } = await execAsync(command);
if (stderr) {
log(`Error executing ${command}: ${stderr}`);
throw new Error(stderr);
}
log(`Command '${command}' executed successfully - stdout: ${stdout}`);
return !stdout ? {} : stdout;
}
export function log(message, ...optionalParams) {
if (process.env.NODE_ENV === 'development' && process.env.DEBUG === 'true') {
console.log(message, optionalParams);
}
}