import * as plugins from '../plugins.js'; export interface ICargoRunResult { success: boolean; exitCode: number; stdout: string; } export class CargoRunner { private shell: plugins.smartshell.Smartshell; private rustDir: string; constructor(rustDir: string) { this.rustDir = rustDir; this.shell = new plugins.smartshell.Smartshell({ executor: 'bash', }); } public async checkCargoInstalled(): Promise { const result = await this.shell.execSilent('cargo --version'); return result.exitCode === 0; } public async getCargoVersion(): Promise { const result = await this.shell.execSilent('cargo --version'); return result.stdout.trim(); } public async build(options: { debug?: boolean; clean?: boolean } = {}): Promise { if (options.clean) { console.log('Cleaning previous build...'); await this.clean(); } const profile = options.debug ? '' : ' --release'; const command = `cd ${this.rustDir} && cargo build${profile}`; console.log(`Running: cargo build${profile}`); const result = await this.shell.exec(command); return { success: result.exitCode === 0, exitCode: result.exitCode, stdout: result.stdout, }; } public async clean(): Promise { const command = `cd ${this.rustDir} && cargo clean`; const result = await this.shell.exec(command); return { success: result.exitCode === 0, exitCode: result.exitCode, stdout: result.stdout, }; } }