Skip to content

Commit e987f7c

Browse files
add logger types
1 parent 6f30453 commit e987f7c

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/cli/logger.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,27 @@ type Color =
1212
| 'gray'
1313
| 'grey';
1414

15-
const logger = {
15+
const logFns = {
1616
// eslint-disable-next-line no-console
1717
writeLn: console.log,
1818
write: (msg: string) => process.stdout.write(msg.toString())
1919
};
2020

2121
const log = (msg: string, color: Color | null, newLine: boolean) =>
22-
logger[newLine ? 'writeLn' : 'write'](color ? colors[color](msg) : msg);
22+
logFns[newLine ? 'writeLn' : 'write'](color ? colors[color](msg) : msg);
2323

24-
export default {
24+
export interface Logger {
25+
err: (msg: string, noNewLine?: boolean) => void;
26+
log: (msg: string, noNewLine?: boolean) => void;
27+
ok: (msg: string, noNewLine?: boolean) => void;
28+
warn: (msg: string, noNewLine?: boolean) => void;
29+
}
30+
31+
const logger: Logger = {
2532
err: (msg: string, noNewLine?: boolean) => log(msg, 'red', !noNewLine),
2633
log: (msg: string, noNewLine?: boolean) => log(msg, null, !noNewLine),
2734
ok: (msg: string, noNewLine?: boolean) => log(msg, 'green', !noNewLine),
2835
warn: (msg: string, noNewLine?: boolean) => log(msg, 'yellow', !noNewLine)
2936
};
37+
38+
export default logger;

0 commit comments

Comments
 (0)