1
+ var endOfLine = require ( 'os' ) . EOL ;
2
+
3
+ var outputResult = function ( status , results , errors ) {
4
+ process . stdout . write ( status ) ;
5
+ process . stdout . write ( endOfLine ) ;
6
+
7
+ if ( ! results ) {
8
+ process . stdout . write ( "" ) ;
9
+ process . stdout . write ( endOfLine ) ;
10
+ }
11
+ else {
12
+ if ( typeof results === 'string' ) {
13
+ process . stdout . write ( results ) ;
14
+ process . stdout . write ( endOfLine ) ;
15
+ }
16
+ else if ( Array . isArray ( results ) ) {
17
+ for ( var resultIndex = 0 ; resultIndex < results . length ; resultIndex ++ ) {
18
+ var result = results [ resultIndex ] ;
19
+ if ( typeof result !== 'string' ) {
20
+ throw "Unsupported result output" ;
21
+ }
22
+
23
+ process . stdout . write ( result ) ;
24
+ process . stdout . write ( endOfLine ) ;
25
+ }
26
+ }
27
+
28
+ throw "Unsupported result output" ;
29
+ }
30
+
31
+ if ( errors ) {
32
+ if ( typeof errors === 'string' ) {
33
+ process . stdout . write ( errors ) ;
34
+ process . stdout . write ( endOfLine ) ;
35
+ }
36
+ else if ( Array . isArray ( errors ) ) {
37
+ for ( var errorIndex = 0 ; errorIndex < errors . length ; errorIndex ++ ) {
38
+ var error = errors [ errorIndex ] ;
39
+ if ( typeof error !== 'string' ) {
40
+ throw "Unsupported result output" ;
41
+ }
42
+
43
+ process . stdout . write ( error ) ;
44
+ process . stdout . write ( endOfLine ) ;
45
+ }
46
+ }
47
+ else {
48
+ process . stdout . write ( errors ) ;
49
+ process . stdout . write ( endOfLine ) ;
50
+ }
51
+ }
52
+ }
53
+
54
+ var outputSuccess = function ( results ) {
55
+ outputResult ( "success" , results ) ;
56
+ }
57
+
58
+ var outputCustom = function ( status , results ) {
59
+ outputResult ( status , results ) ;
60
+ }
61
+
62
+ var outputError = function ( errors ) {
63
+ outputResult ( "error" , null , errors ) ;
64
+ }
65
+
66
+ module . exports = {
67
+ success : outputSuccess ,
68
+ custom : outputCustom ,
69
+ error : outputError
70
+ } ;
0 commit comments