Skip to content

Commit

Permalink
chore: add colors to remirror-cli's output (#1803)
Browse files Browse the repository at this point in the history
  • Loading branch information
ocavue committed Jul 29, 2022
1 parent 4ac8661 commit 4ce191b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
10 changes: 6 additions & 4 deletions packages/remirror__cli/src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* eslint-disable no-console */

const prefix = '[remirror-cli]';
import { colors } from './utils/colors';

const prefix = colors.magenta('remirror-cli');

export const logger = {
debug: (...args: any[]) => {
Expand All @@ -14,13 +16,13 @@ export const logger = {
return logger.info(...args);
},
info: (...args: any[]) => {
console.log(prefix, 'INFO', ...args);
console.log(prefix, colors.green('INFO'), ...args);
},
warn: (...args: any[]) => {
console.warn(prefix, 'WARN', ...args);
console.warn(prefix, colors.yellow('WARN'), ...args);
},
error: (...args: any[]) => {
console.error(prefix, 'ERROR', ...args);
console.error(prefix, colors.red('ERROR'), ...args);
},
assert: (condition: unknown, message = '') => {
if (!condition) {
Expand Down
40 changes: 40 additions & 0 deletions packages/remirror__cli/src/utils/colors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const codes = {
Reset: '\u001B[0m',
Bright: '\u001B[1m',
Dim: '\u001B[2m',
Underscore: '\u001B[4m',
Blink: '\u001B[5m',
Reverse: '\u001B[7m',
Hidden: '\u001B[8m',

FgBlack: '\u001B[30m',
FgRed: '\u001B[31m',
FgGreen: '\u001B[32m',
FgYellow: '\u001B[33m',
FgBlue: '\u001B[34m',
FgMagenta: '\u001B[35m',
FgCyan: '\u001B[36m',
FgWhite: '\u001B[37m',

BgBlack: '\u001B[40m',
BgRed: '\u001B[41m',
BgGreen: '\u001B[42m',
BgYellow: '\u001B[43m',
BgBlue: '\u001B[44m',
BgMagenta: '\u001B[45m',
BgCyan: '\u001B[46m',
BgWhite: '\u001B[47m',
};

function createColorWrapper(color: string) {
return process.env.CI
? (text: string) => text
: (text: string) => `${color}${text}${codes.Reset}`;
}

export const colors = {
magenta: createColorWrapper(codes.FgMagenta),
green: createColorWrapper(codes.FgGreen),
yellow: createColorWrapper(codes.FgYellow),
red: createColorWrapper(codes.FgRed),
};
2 changes: 1 addition & 1 deletion support/actions/pr/pr-utils.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getParameters } from 'codesandbox/lib/api/define';
import { getParameters } from 'codesandbox/lib/api/define.js';
import got from 'got';
import { default as semver } from 'semver';

Expand Down

1 comment on commit 4ce191b

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.