mirror of
https://github.com/actions/stale.git
synced 2025-12-27 18:58:16 +00:00
* refactor(logs): replace chalk by ansi-styles * test(logs): fix the failing tests due to ansi styles I was not able to disable or mock ansi-styles so instead I found a way to make the tests pass it's not perfect but it's still nice because the logs will keep their trustful colour when running through the tests * refactor(logs): simplify the syntax to colour the logs * chore(rebase): update files due to rebase * refactor(logger): reduce code duplication
53 lines
1.3 KiB
TypeScript
53 lines
1.3 KiB
TypeScript
import styles, {Modifier, ForegroundColor} from 'ansi-styles';
|
|
|
|
type Message = string | number | boolean;
|
|
|
|
export class LoggerService {
|
|
static whiteBright(message: Readonly<Message>): string {
|
|
return this._format(message, 'whiteBright');
|
|
}
|
|
|
|
static yellowBright(message: Readonly<Message>): string {
|
|
return this._format(message, 'yellowBright');
|
|
}
|
|
|
|
static magenta(message: Readonly<Message>): string {
|
|
return this._format(message, 'magenta');
|
|
}
|
|
|
|
static cyan(message: Readonly<Message>): string {
|
|
return this._format(message, 'cyan');
|
|
}
|
|
|
|
static yellow(message: Readonly<Message>): string {
|
|
return this._format(message, 'yellow');
|
|
}
|
|
|
|
static white(message: Readonly<Message>): string {
|
|
return this._format(message, 'white');
|
|
}
|
|
|
|
static green(message: Readonly<Message>): string {
|
|
return this._format(message, 'green');
|
|
}
|
|
|
|
static red(message: Readonly<Message>): string {
|
|
return this._format(message, 'red');
|
|
}
|
|
|
|
static blue(message: Readonly<Message>): string {
|
|
return this._format(message, 'blue');
|
|
}
|
|
|
|
static bold(message: Readonly<Message>): string {
|
|
return this._format(message, 'bold');
|
|
}
|
|
|
|
private static _format(
|
|
message: Readonly<Message>,
|
|
style: keyof Modifier | keyof ForegroundColor
|
|
): string {
|
|
return `${styles[style].open}${message}${styles[style].close}`;
|
|
}
|
|
}
|