Skip to content

Instantly share code, notes, and snippets.

@devinrhode2
Last active December 24, 2022 02:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devinrhode2/e1e36fdf7f9465ed3037eac581cc07a5 to your computer and use it in GitHub Desktop.
Save devinrhode2/e1e36fdf7f9465ed3037eac581cc07a5 to your computer and use it in GitHub Desktop.
import { execaCommandSync } from 'execa'
/** @type {(cmdString: string, debug?: 'debug') => [string | undefined, string | unknown]} */
export const exec = (cmdString, debug) => {
let exception
let result
try {
result = execaCommandSync(cmdString, {
env: {
// @ts-expect-error - not application code
...process.env,
FORCE_COLOR: 'true',
},
})
} catch (e) {
exception = e
}
if (debug === 'debug') {
console.log(result)
console.log(exception)
}
return [
result?.stdout,
// If falsey, provide exception. If no exception, give falsey value.
result?.stderr || exception || result?.stderr,
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment