From 21b81ede3ea5f9c5c58fc4aa6c2ba89743df4121 Mon Sep 17 00:00:00 2001 From: William Di Pasquale Date: Fri, 12 Mar 2021 09:47:14 +0000 Subject: [PATCH] fix: Improve output stream Now supports colors --- src/utils.ts | 16 +++------------- tests/example-cli.ts | 4 ++++ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 361b1ca..d76b8b2 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -8,21 +8,11 @@ import consola from 'consola'; * @param command * @param commandArgs */ -export const spawn = async (command: string, commandArgs?: string[], quiet = false): Promise => { +export const spawn = async (command: string, commandArgs: string[] = [], quiet = false): Promise => { return new Promise((resolve, reject) => { - const childProcess = childProcessSpawn(command, commandArgs); + const childProcess = childProcessSpawn(command, commandArgs, { stdio: "inherit" }); - if (!quiet) { - consola.info(`Executing: '${command} ${(commandArgs || []).join(' ')}'`); - - childProcess.stdout.on('data', (data) => { - consola.info(data.toString()); - }); - - childProcess.stderr.on('data', (data) => { - consola.error(data.toString()); - }); - } + consola.info(`Executing: '${command} ${(commandArgs || []).join(' ')}'`); childProcess.on('exit', (code) => { const exitCode = code || 0; diff --git a/tests/example-cli.ts b/tests/example-cli.ts index 23ac03e..17b3008 100644 --- a/tests/example-cli.ts +++ b/tests/example-cli.ts @@ -1,16 +1,20 @@ /* eslint-disable no-console */ import { addDeployArgs, deploy } from '../src/commands/deploy'; import { runner } from '../src/runner'; +import { spawn } from '../src/utils'; const echo = (context: unknown) => { console.log(context); return Promise.resolve(0); }; +const test = () => spawn('yarn', ['test:unit']); + const getArgs = () => addDeployArgs().help().argv; const commands = { deploy, + test, echo, };