fix(core): Fix interactive shell execution and update dependencies
This commit is contained in:
@ -1,8 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
* autocreated commitinfo by @push.rocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartshell',
|
||||
version: '3.0.5',
|
||||
version: '3.0.6',
|
||||
description: 'A library for executing shell commands using promises.'
|
||||
}
|
||||
|
@ -39,39 +39,51 @@ export class Smartshell {
|
||||
interactive?: boolean;
|
||||
}): Promise<IExecResult | IExecResultStreaming | void> {
|
||||
if (options.interactive) {
|
||||
if (process.env.CI) {
|
||||
return;
|
||||
}
|
||||
return await this._execInteractive(options);
|
||||
}
|
||||
|
||||
const done = plugins.smartpromise.defer();
|
||||
|
||||
// Notice that stdio is set to 'inherit'
|
||||
const shell = cp.spawn(options.commandString, {
|
||||
stdio: 'inherit',
|
||||
shell: true,
|
||||
detached: true
|
||||
});
|
||||
|
||||
this.smartexit.addProcess(shell);
|
||||
|
||||
shell.on('close', (code) => {
|
||||
console.log(`interactive shell terminated with code ${code}`);
|
||||
this.smartexit.removeProcess(shell);
|
||||
done.resolve();
|
||||
});
|
||||
|
||||
await done.promise;
|
||||
return await this._execCommand(options);
|
||||
}
|
||||
|
||||
private async _execInteractive(options: {
|
||||
commandString: string;
|
||||
interactive?: boolean;
|
||||
}): Promise<void> {
|
||||
if (process.env.CI) {
|
||||
return;
|
||||
}
|
||||
|
||||
const done = plugins.smartpromise.defer();
|
||||
|
||||
const shell = cp.spawn(options.commandString, {
|
||||
stdio: 'inherit',
|
||||
shell: true,
|
||||
detached: true
|
||||
});
|
||||
|
||||
this.smartexit.addProcess(shell);
|
||||
|
||||
shell.on('close', (code) => {
|
||||
console.log(`interactive shell terminated with code ${code}`);
|
||||
this.smartexit.removeProcess(shell);
|
||||
done.resolve();
|
||||
});
|
||||
|
||||
await done.promise;
|
||||
}
|
||||
|
||||
private async _execCommand(options: {
|
||||
commandString: string;
|
||||
silent?: boolean;
|
||||
strict?: boolean;
|
||||
streaming?: boolean;
|
||||
}): Promise<IExecResult | IExecResultStreaming> {
|
||||
const done = plugins.smartpromise.defer<IExecResult | IExecResultStreaming>();
|
||||
const childProcessEnded = plugins.smartpromise.defer<IExecResult>();
|
||||
|
||||
let commandToExecute = options.commandString;
|
||||
commandToExecute = this.shellEnv.createEnvExecString(options.commandString);
|
||||
const commandToExecute = this.shellEnv.createEnvExecString(options.commandString);
|
||||
|
||||
const spawnlogInstance = new ShellLog();
|
||||
const shellLogInstance = new ShellLog();
|
||||
const execChildProcess = cp.spawn(commandToExecute, [], {
|
||||
shell: true,
|
||||
cwd: process.cwd(),
|
||||
@ -83,16 +95,16 @@ export class Smartshell {
|
||||
|
||||
execChildProcess.stdout.on('data', (data) => {
|
||||
if (!options.silent) {
|
||||
spawnlogInstance.writeToConsole(data);
|
||||
shellLogInstance.writeToConsole(data);
|
||||
}
|
||||
spawnlogInstance.addToBuffer(data);
|
||||
shellLogInstance.addToBuffer(data);
|
||||
});
|
||||
|
||||
execChildProcess.stderr.on('data', (data) => {
|
||||
if (!options.silent) {
|
||||
spawnlogInstance.writeToConsole(data);
|
||||
shellLogInstance.writeToConsole(data);
|
||||
}
|
||||
spawnlogInstance.addToBuffer(data);
|
||||
shellLogInstance.addToBuffer(data);
|
||||
});
|
||||
|
||||
execChildProcess.on('exit', (code, signal) => {
|
||||
@ -103,7 +115,7 @@ export class Smartshell {
|
||||
|
||||
const execResult = {
|
||||
exitCode: code,
|
||||
stdout: spawnlogInstance.logStore.toString(),
|
||||
stdout: shellLogInstance.logStore.toString(),
|
||||
};
|
||||
|
||||
if (!options.streaming) {
|
||||
@ -191,4 +203,4 @@ export class Smartshell {
|
||||
public async execAndWaitForLineSilent(commandString: string, regexArg: RegExp) {
|
||||
return this.execAndWaitForLine(commandString, regexArg, true);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user