@@ -5,6 +5,11 @@ module.exports = {
5
5
'error' ,
6
6
'buffer' ,
7
7
] ,
8
+ KEYS : {
9
+ standard : 'standard' ,
10
+ error : 'error' ,
11
+ buffer : 'buffer' ,
12
+ } ,
8
13
standard : function ( ...args ) {
9
14
return process . emit ( 'output' , 'standard' , ...args )
10
15
} ,
@@ -28,6 +33,18 @@ module.exports = {
28
33
'pause' ,
29
34
'resume' ,
30
35
] ,
36
+ KEYS : {
37
+ notice : 'notice' ,
38
+ error : 'error' ,
39
+ warn : 'warn' ,
40
+ info : 'info' ,
41
+ verbose : 'verbose' ,
42
+ http : 'http' ,
43
+ silly : 'silly' ,
44
+ timing : 'timing' ,
45
+ pause : 'pause' ,
46
+ resume : 'resume' ,
47
+ } ,
31
48
error : function ( ...args ) {
32
49
return process . emit ( 'log' , 'error' , ...args )
33
50
} ,
@@ -52,11 +69,78 @@ module.exports = {
52
69
timing : function ( ...args ) {
53
70
return process . emit ( 'log' , 'timing' , ...args )
54
71
} ,
55
- pause : function ( ...args ) {
56
- return process . emit ( 'log' , 'pause' , ...args )
72
+ pause : function ( ) {
73
+ return process . emit ( 'log' , 'pause' )
74
+ } ,
75
+ resume : function ( ) {
76
+ return process . emit ( 'log' , 'resume' )
77
+ } ,
78
+ } ,
79
+ time : {
80
+ LEVELS : [
81
+ 'start' ,
82
+ 'end' ,
83
+ ] ,
84
+ KEYS : {
85
+ start : 'start' ,
86
+ end : 'end' ,
87
+ } ,
88
+ start : function ( name , fn ) {
89
+ process . emit ( 'time' , 'start' , name )
90
+ function end ( ) {
91
+ return process . emit ( 'time' , 'end' , name )
92
+ }
93
+ if ( typeof fn === 'function' ) {
94
+ const res = fn ( )
95
+ if ( res && res . finally ) {
96
+ return res . finally ( end )
97
+ }
98
+ end ( )
99
+ return res
100
+ }
101
+ return end
102
+ } ,
103
+ end : function ( name ) {
104
+ return process . emit ( 'time' , 'end' , name )
105
+ } ,
106
+ } ,
107
+ input : {
108
+ LEVELS : [
109
+ 'start' ,
110
+ 'end' ,
111
+ 'read' ,
112
+ ] ,
113
+ KEYS : {
114
+ start : 'start' ,
115
+ end : 'end' ,
116
+ read : 'read' ,
117
+ } ,
118
+ start : function ( fn ) {
119
+ process . emit ( 'input' , 'start' )
120
+ function end ( ) {
121
+ return process . emit ( 'input' , 'end' )
122
+ }
123
+ if ( typeof fn === 'function' ) {
124
+ const res = fn ( )
125
+ if ( res && res . finally ) {
126
+ return res . finally ( end )
127
+ }
128
+ end ( )
129
+ return res
130
+ }
131
+ return end
132
+ } ,
133
+ end : function ( ) {
134
+ return process . emit ( 'input' , 'end' )
57
135
} ,
58
- resume : function ( ...args ) {
59
- return process . emit ( 'log' , 'resume' , ...args )
136
+ read : function ( ...args ) {
137
+ let resolve , reject
138
+ const promise = new Promise ( ( _resolve , _reject ) => {
139
+ resolve = _resolve
140
+ reject = _reject
141
+ } )
142
+ process . emit ( 'input' , 'read' , resolve , reject , ...args )
143
+ return promise
60
144
} ,
61
145
} ,
62
146
}
0 commit comments