github-pages-deploy-action/src/execute.ts
2020-03-06 22:36:56 -05:00

29 lines
742 B
TypeScript

import {exec} from '@actions/exec'
let output: string
/** Wrapper around the GitHub toolkit exec command which returns the output.
* Also allows you to easily toggle the current working directory.
* @param cmd = The command to execute.
* @param cwd - The current working directory.
* @returns - The output from the command.
*/
export async function execute(cmd: string, cwd: string): Promise<any> {
output = ''
await exec(cmd, [], {
// Silences the input unless the INPUT_DEBUG flag is set.
silent: process.env.DEBUG_DEPLOY_ACTION ? false : true,
cwd,
listeners: {
stdout
}
})
return Promise.resolve(output)
}
export function stdout(data: any): string | void {
output += data.toString().trim()
}