@@ -5,6 +5,11 @@ module.exports = {
55 'error' ,
66 'buffer' ,
77 ] ,
8+ KEYS : {
9+ standard : 'standard' ,
10+ error : 'error' ,
11+ buffer : 'buffer' ,
12+ } ,
813 standard : function ( ...args ) {
914 return process . emit ( 'output' , 'standard' , ...args )
1015 } ,
@@ -28,6 +33,18 @@ module.exports = {
2833 'pause' ,
2934 'resume' ,
3035 ] ,
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+ } ,
3148 error : function ( ...args ) {
3249 return process . emit ( 'log' , 'error' , ...args )
3350 } ,
@@ -52,11 +69,78 @@ module.exports = {
5269 timing : function ( ...args ) {
5370 return process . emit ( 'log' , 'timing' , ...args )
5471 } ,
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' )
57135 } ,
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
60144 } ,
61145 } ,
62146}
0 commit comments