Skip to content

Commit

Permalink
[DOP-4033]: Work on logic for deploy and ability to pipe output from …
Browse files Browse the repository at this point in the history
…one command to another
  • Loading branch information
branberry committed Oct 3, 2023
1 parent 4b5a432 commit 1a635d1
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions src/commands/src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,31 @@ export interface CliCommandResponse {
outputText: string;
errorText: string;
}

export async function executeAndPipeCommands(cmdFromParams: CliCommandParams, cmdToParams: CliCommandParams) {
const cmdFrom = spawn(cmdFromParams.command, cmdFromParams.args || [], cmdFromParams.options || {});
const cmdTo = spawn(cmdToParams.command, cmdToParams.args || [], cmdToParams.options || {});
return new Promise((resolve, reject) => {
const cmdFrom = spawn(cmdFromParams.command, cmdFromParams.args || [], cmdFromParams.options || {});
const cmdTo = spawn(cmdToParams.command, cmdToParams.args || [], cmdToParams.options || {});

const outputText: string[] = [];

cmdFrom.stdout?.on('data', (data: Buffer) => {
cmdTo.stdin?.write(data);
});

cmdFrom.on('error', (err) => {
reject(new ExecuteCommandError('The first command failed', err));
});

cmdFrom.stdout?.on('data', (data) => {
cmdTo.stdin?.write(data);
cmdTo.stdout?.on('data', (data: Buffer) => {
outputText.push(data.toString());
});

cmdTo.on('error', (err) => {
reject(new ExecuteCommandError('The second command failed', err));
});

cmdTo.on('exit', (code) => {});

Check failure on line 55 in src/commands/src/helpers/index.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected empty arrow function
});
}
export async function executeCliCommand({
Expand All @@ -58,13 +77,12 @@ export async function executeCliCommand({
});

executedCommand.on('error', (err) => {
if (err) {
reject(new ExecuteCommandError('The command failed', err));
}
reject(new ExecuteCommandError('The command failed', err));
});

executedCommand.on('close', (exitCode) => {
if (writeStream) writeStream.end();

if (exitCode !== 0) {
console.error(`ERROR! The command ${command} closed with an exit code other than 0: ${exitCode}.`);
console.error('Arguments provided: ', args);
Expand Down

0 comments on commit 1a635d1

Please sign in to comment.