Skip to content

Commit

Permalink
fix log filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
electrovir committed Oct 19, 2021
1 parent b501e8e commit faad1a3
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 15 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "virmator",
"version": "1.3.5",
"version": "1.3.6",
"description": "Handle all the stuffs in one package.",
"keywords": [
"automation",
Expand Down
6 changes: 3 additions & 3 deletions src/cli/cli-util/shell-command-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ function outputWrapper(
filter: OutputFilter,
): (input: string | Buffer) => void {
return (input) => {
const stringInput = input.toString();
if (filter(stringInput)) {
callback(stringInput);
const callbackString = filter(input.toString());
if (callbackString) {
callback(callbackString);
}
};
}
Expand Down
5 changes: 1 addition & 4 deletions src/cli/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,7 @@ testGroup((runTest) => {
args: [CliFlagName.NoWriteConfig, CliCommandName.Format, FormatOperation.Check],
description: 'runs format',
expect: {
stdout: `running format...\nAll matched files use Prettier code style!\n\n${getResultMessage(
CliCommandName.Format,
true,
)}`,
stdout: `running format...\n${getResultMessage(CliCommandName.Format, true)}`,
},
cwd: testFormatPaths.validRepo,
});
Expand Down
9 changes: 7 additions & 2 deletions src/cli/commands/implementations/format.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type FormatArgs = Required<
export const defaultFormatArgs: FormatArgs = {
operation: FormatOperation.Write,
prettierFlags: [],
fileExtensions: ['ts', 'json', 'html', 'css', 'md', 'js', 'yml', 'yaml'],
fileExtensions: ['ts', 'tsx', 'json', 'html', 'css', 'md', 'js', 'yml', 'yaml'],
} as const;

export const filesMarkerArg = '--format-files' as const;
Expand Down Expand Up @@ -85,7 +85,12 @@ export async function runFormatCommand(inputs: CommandFunctionInput): Promise<Cl
)} \"./**/*.+(${args.fileExtensions.join('|')})\" ${operationFlag}`;

const results = await runVirmatorShellCommand(prettierCommand, inputs, {
stdoutFilter: (stdout) => stdout.replace('Checking formatting...\n', ''),
stdoutFilter: (stdout) =>
stdout
// only relevant when running the check command
.replace('Checking formatting...\n', '')
// only relevant when running the check command
.replace('All matched files use Prettier code style!\n', ''),
});

return {
Expand Down
6 changes: 5 additions & 1 deletion src/cli/commands/implementations/test.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ export async function runTestCommand(inputs: CommandFunctionInput): Promise<CliC
? interpolationSafeWindowsPath(inputs.rawArgs.join(' '))
: `\"./dist/**/!(*.type).test.js\"`;
const testCommand = `${testVirPath} ${args}`;
const results = await runVirmatorShellCommand(testCommand, inputs);
const results = await runVirmatorShellCommand(testCommand, inputs, {
stdoutFilter: (logString) =>
// weird looking hex codes here are for color codes from test-vir
logString.replace('\x1B[1m\x1B[32mAll tests passed.\x1B[0m\n', ''),
});

return {
success: !results.error,
Expand Down
4 changes: 2 additions & 2 deletions src/cli/commands/run-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ export async function runCommand(
? EmptyOutputCallbacks
: {
stdoutCallback: (input: string) => {
console.info(input.replace(/\n\n$/, '\n'));
console.info(input.replace(/\n$/, ''));
},
stderrCallback: (input: string) => {
console.error(input.replace(/\n\n$/, '\n'));
console.error(input.replace(/\n$/, ''));
},
};

Expand Down

0 comments on commit faad1a3

Please sign in to comment.