@@ -11,17 +11,6 @@ const logSymbols = require('log-symbols');
11
11
const step = ' ' ;
12
12
let padding = ' ' ;
13
13
14
- // Color -> status mappings
15
- const colors = {
16
- skip : 'yellow' ,
17
- force : 'yellow' ,
18
- create : 'green' ,
19
- invoke : 'bold' ,
20
- conflict : 'red' ,
21
- identical : 'cyan' ,
22
- info : 'gray'
23
- } ;
24
-
25
14
function pad ( status ) {
26
15
const max = 'identical' . length ;
27
16
const delta = max - status . length ;
@@ -44,7 +33,24 @@ function formatter(msg, ctx) {
44
33
return msg ;
45
34
}
46
35
47
- module . exports = ( ) => {
36
+ const getDefaultColors = ( ) => ( {
37
+ skip : 'yellow' ,
38
+ force : 'yellow' ,
39
+ create : 'green' ,
40
+ invoke : 'bold' ,
41
+ conflict : 'red' ,
42
+ identical : 'cyan' ,
43
+ info : 'gray'
44
+ } ) ;
45
+
46
+ const initParams = params => {
47
+ params = params || { } ;
48
+ return Object . assign (
49
+ { } , params , {
50
+ colors : Object . assign ( getDefaultColors ( ) , params . colors || { } ) } ) ;
51
+ } ;
52
+
53
+ module . exports = params => {
48
54
// `this.log` is a [logref](https://github.com/mikeal/logref)
49
55
// compatible logger, with an enhanced API.
50
56
//
@@ -61,6 +67,9 @@ module.exports = () => {
61
67
// - msg - The message to show up
62
68
// - context - The optional context to escape the message against
63
69
//
70
+ // @param {Object } params
71
+ // @param {Object } params.colors status mappings
72
+ //
64
73
// Returns the logger
65
74
function log ( msg , ctx ) {
66
75
msg = msg || '' ;
@@ -76,6 +85,8 @@ module.exports = () => {
76
85
77
86
_ . extend ( log , EventEmitter . prototype ) ;
78
87
88
+ params = initParams ( params ) ;
89
+
79
90
// A simple write method, with formatted message.
80
91
//
81
92
// Returns the logger
@@ -114,7 +125,7 @@ module.exports = () => {
114
125
115
126
/* eslint-disable no-loop-func */
116
127
// TODO: Fix this ESLint warning
117
- for ( const status of Object . keys ( colors ) ) {
128
+ for ( const status of Object . keys ( params . colors ) ) {
118
129
// Each predefined status has its logging method utility, handling
119
130
// status color and padding before the usual `.write()`
120
131
//
@@ -128,7 +139,7 @@ module.exports = () => {
128
139
// .write()
129
140
// .ok('This is ok');
130
141
//
131
- // The list of status and mapping colors
142
+ // The list of default status and mapping colors
132
143
//
133
144
// skip yellow
134
145
// force yellow
@@ -140,7 +151,7 @@ module.exports = () => {
140
151
//
141
152
// Returns the logger
142
153
log [ status ] = function ( ) {
143
- const color = colors [ status ] ;
154
+ const color = params . colors [ status ] ;
144
155
this . write ( chalk [ color ] ( pad ( status ) ) ) . write ( padding ) ;
145
156
this . write ( util . format . apply ( util , arguments ) + '\n' ) ;
146
157
return this ;
0 commit comments