initial
This commit is contained in:
59
ts/mod_cargo/classes.cargorunner.ts
Normal file
59
ts/mod_cargo/classes.cargorunner.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
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<boolean> {
|
||||
const result = await this.shell.execSilent('cargo --version');
|
||||
return result.exitCode === 0;
|
||||
}
|
||||
|
||||
public async getCargoVersion(): Promise<string> {
|
||||
const result = await this.shell.execSilent('cargo --version');
|
||||
return result.stdout.trim();
|
||||
}
|
||||
|
||||
public async build(options: { debug?: boolean; clean?: boolean } = {}): Promise<ICargoRunResult> {
|
||||
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<ICargoRunResult> {
|
||||
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,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user