Skip to content

Commit

Permalink
fix: Improve output stream
Browse files Browse the repository at this point in the history
Now supports colors
  • Loading branch information
dipasqualew committed Mar 12, 2021
1 parent 16cde39 commit 21b81ed
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
16 changes: 3 additions & 13 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,11 @@ import consola from 'consola';
* @param command
* @param commandArgs
*/
export const spawn = async (command: string, commandArgs?: string[], quiet = false): Promise<number> => {
export const spawn = async (command: string, commandArgs: string[] = [], quiet = false): Promise<number> => {
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;
Expand Down
4 changes: 4 additions & 0 deletions tests/example-cli.ts
Original file line number Diff line number Diff line change
@@ -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,
};

Expand Down

0 comments on commit 21b81ed

Please sign in to comment.