2
2
const _ = require ( 'lodash' ) ;
3
3
const columnify = require ( 'columnify' ) ;
4
4
const yaml = require ( 'js-yaml' ) ;
5
- const logUpdate = require ( 'log-update' ) ;
5
+ const draftlog = require ( 'draftlog' ) ;
6
+
7
+ draftlog . into ( console ) ;
8
+
9
+ let update ;
10
+ const print = ( output ) => {
11
+ if ( update ) {
12
+ update ( output ) ;
13
+ } else {
14
+ update = console . draft ( output ) ;
15
+ }
16
+ } ;
6
17
7
18
//i tried that this function will be dynamic (with the keys). it is also possible to add an array with all the fields if you think it better
8
19
const _printArrayTable = ( data ) => {
@@ -20,7 +31,7 @@ const _printArrayTable = (data) => {
20
31
res . push ( obj ) ;
21
32
} ) ;
22
33
const columns = columnify ( res ) ;
23
- logUpdate ( columns ) ;
34
+ print ( columns ) ;
24
35
} ;
25
36
26
37
const _printSingleTable = ( info ) => {
@@ -32,21 +43,20 @@ const _printSingleTable = (info) => {
32
43
} ) ;
33
44
res . push ( obj ) ;
34
45
const columns = columnify ( res ) ;
35
- logUpdate ( columns ) ;
46
+ print ( columns ) ;
36
47
} ;
37
48
38
49
39
50
const specifyOutputForSingle = ( type , enitity ) => {
40
- logUpdate . clear ( ) ;
41
51
switch ( type ) {
42
52
case 'json' :
43
- logUpdate ( enitity . toJson ( ) ) ;
53
+ print ( enitity . toJson ( ) ) ;
44
54
break ;
45
55
case 'yaml' :
46
- logUpdate ( enitity . toYaml ( ) ) ;
56
+ print ( enitity . toYaml ( ) ) ;
47
57
break ;
48
58
case 'name' :
49
- logUpdate ( enitity . toName ( ) ) ;
59
+ print ( enitity . toName ( ) ) ;
50
60
break ;
51
61
case 'wide' :
52
62
_printSingleTable ( enitity . toWide ( ) ) ;
@@ -58,7 +68,6 @@ const specifyOutputForSingle = (type, enitity) => {
58
68
59
69
60
70
const specifyOutputForArray = ( type , enitities ) => {
61
- logUpdate . clear ( ) ;
62
71
switch ( type ) {
63
72
case 'json' :
64
73
const jsonArray = [ ] ;
@@ -67,9 +76,9 @@ const specifyOutputForArray = (type, enitities) => {
67
76
} ) ;
68
77
69
78
if ( jsonArray . length === 1 ) {
70
- logUpdate ( JSON . stringify ( jsonArray [ 0 ] , null , '\t' ) ) ;
79
+ print ( JSON . stringify ( jsonArray [ 0 ] , null , '\t' ) ) ;
71
80
} else {
72
- logUpdate ( JSON . stringify ( jsonArray , null , '\t' ) ) ;
81
+ print ( JSON . stringify ( jsonArray , null , '\t' ) ) ;
73
82
}
74
83
75
84
break ;
@@ -82,14 +91,14 @@ const specifyOutputForArray = (type, enitities) => {
82
91
} ) ;
83
92
84
93
if ( yamlArray . items . length === 1 ) {
85
- logUpdate ( yaml . safeDump ( yamlArray . items [ 0 ] ) ) ;
94
+ print ( yaml . safeDump ( yamlArray . items [ 0 ] ) ) ;
86
95
} else {
87
- logUpdate ( yaml . safeDump ( yamlArray ) ) ;
96
+ print ( yaml . safeDump ( yamlArray ) ) ;
88
97
}
89
98
break ;
90
99
case 'name' :
91
100
_ . forEach ( enitities , ( entity ) => {
92
- logUpdate ( entity . toName ( ) ) ;
101
+ print ( entity . toName ( ) ) ;
93
102
} ) ;
94
103
break ;
95
104
case 'wide' :
0 commit comments