Skip to content

Commit 05e41ee

Browse files
committed
feat(utils): add runCommandAsync function
1 parent 535e908 commit 05e41ee

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

src/utils/extras.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,28 @@ export function successMessage(
185185
export function errorMessage(error: Error | unknown, context: string): void {
186186
throw new Error(`[error]: ${context} failed: \n${error}`);
187187
}
188+
189+
/**
190+
* @description Run a command with its arguments and inherit stdio
191+
* @param command The command to run
192+
* @param args The arguments to pass to the command
193+
* @param interactiveMode Whether to run the command in interactive mode (inherit stdio)
194+
* @param shellMode Whether to run the command in shell mode
195+
*/
196+
export async function runCommandAsync(
197+
command: string,
198+
args: string[],
199+
interactiveMode: boolean,
200+
shellMode: boolean,
201+
): Promise<void> {
202+
await execa(command, args, {
203+
stdio: interactiveMode ? "inherit" : ["pipe", "inherit", "inherit"],
204+
input: interactiveMode ? undefined : process.stdin, // Inherit input if in interactive mode
205+
shell: shellMode, // Use shell mode if specified
206+
env: process.env, // Inherit environment variables
207+
cleanup: true, // Cleanup resources after execution
208+
preferLocal: false, // Prefer global installation of task-master
209+
windowsHide: false, // Hide the console window on MS Windows
210+
buffer: false, // Disable output buffering
211+
});
212+
}

0 commit comments

Comments
 (0)