Skip to content

Commit 1e8eee7

Browse files
committed
fix: do not stylize help text output when it's piped to a file
1 parent fa45cbb commit 1e8eee7

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

bin/crx3.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,20 @@ if (!testVersion(process.version.substring(1), MINIMUM_REQUIRED_NODEJS_VERSION))
1515

1616
if (process.stdin.isTTY && !hasSrcPaths) {
1717
/* eslint-disable prefer-named-capture-group */
18-
console.log(config
19-
.helpText()
18+
const renderForPipe = text => text;
19+
const renderForTTY = text => text
2020
// Drop "-" from list of args
2121
.replace(/\n-\s/g, () => '\n ')
2222
// Stylize shell commands
2323
.replace(/```sh\n+([\w\W]+?)\n+```/g, (_, sh) => `\u001b[1m${sh}\u001b[0m`)
2424
// Embolden Markdown stuff
2525
.replace(/\*\*([^*]+?)\*\*/g, (_, bold) => `\u001b[7;1m${bold}\u001b[0m`)
2626
// Italicize Markdown stuff
27-
.replace(/\*([^*]+?)\*/g, (_, italic) => `\u001b[1m${italic}\u001b[0m`));
27+
.replace(/\*([^*]+?)\*/g, (_, italic) => `\u001b[1m${italic}\u001b[0m`);
2828
/* eslint-enable prefer-named-capture-group */
29+
const render = process.stdout.isTTY ? renderForTTY : renderForPipe;
30+
31+
console.log(render(config.helpText()));
2932
process.exit();
3033
}
3134

0 commit comments

Comments
 (0)