Skip to content

Commit

Permalink
Update execute.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesIves committed May 18, 2024
1 parent 0aab60f commit 4c43fee
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import buffer from 'buffer'
type ExecuteOutput = {
stdout: string
stderr: string
exitCode: number;
}

const output: ExecuteOutput = {stdout: '', stderr: ''}
const output: ExecuteOutput = {stdout: '', stderr: '', exitCode: 0}

/** Wrapper around the GitHub toolkit exec command which returns the output.
* Also allows you to easily toggle the current working directory.
Expand All @@ -26,15 +27,22 @@ export async function execute(
output.stdout = ''
output.stderr = ''

await exec(cmd, [], {
output.exitCode = await exec(cmd, [], {
// Silences the input unless the INPUT_DEBUG flag is set.
silent,
cwd,
listeners: {stdout, stderr},
listeners: {
stdout: (data: Buffer) => {
stdout(data);
},
stderr: (data: Buffer) => {
stderr(data);
}
},
ignoreReturnCode
})

return Promise.resolve(output)
return Promise.resolve(output);
}

export function stdout(data: Buffer | string): void {
Expand All @@ -55,4 +63,4 @@ export function stderr(data: Buffer | string): void {
) {
output.stderr += dataString
}
}
}

0 comments on commit 4c43fee

Please sign in to comment.