Last active
December 24, 2022 02:37
-
-
Save devinrhode2/e1e36fdf7f9465ed3037eac581cc07a5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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