@@ -25,105 +25,105 @@ function logTasks(tree, opts, getTask) {
25
25
} ;
26
26
27
27
printTaskTree ( tree , treeOpts ) ;
28
- }
29
-
30
- function printTaskTree ( tree , opts ) {
31
- var lines = [ ] ;
32
- lines . push ( { label : tree . label } ) ;
33
- var maxLabelWidth = 0 ;
34
-
35
- tree . nodes . forEach ( function ( node , idx , arr ) {
36
- var isLast = idx === arr . length - 1 ;
37
- var w = createTreeLines ( node , lines , opts , 1 , '' , isLast ) ;
38
- maxLabelWidth = Math . max ( maxLabelWidth , w || 0 ) ;
39
- } ) ;
40
-
41
- lines . forEach ( function ( line ) {
42
- var s = line . label ;
43
- if ( line . desc ) {
44
- var spaces = ' ' . repeat ( maxLabelWidth - line . label . length ) + ' ' ;
45
- s += spaces + line . desc ;
46
- }
47
- log . info ( s ) ;
48
- } ) ;
49
- }
50
-
51
- function createTreeLines ( node , lines , opts , depth , bars , isLast ) {
52
- var task = { label : node . label , bars : bars , depth : depth } ;
53
- if ( depth === 1 ) {
54
- var t = opts . getTask ( node . label ) ;
55
- task . desc = t . description ;
56
- task . flags = t . flags ;
57
- }
58
-
59
- var isLeaf = isLeafNode ( node , depth , opts ) ;
60
28
61
- var maxLabelWidth = addTaskToLines ( task , lines , isLast , isLeaf ) ;
29
+ function printTaskTree ( tree , opts ) {
30
+ var lines = [ ] ;
31
+ lines . push ( { label : tree . label } ) ;
32
+ var maxLabelWidth = 0 ;
62
33
63
- if ( ! isLeaf ) {
64
- bars += ( isLast ? ' ' : '│ ' ) ;
65
- node . nodes . forEach ( function ( node , idx , arr ) {
34
+ tree . nodes . forEach ( function ( node , idx , arr ) {
66
35
var isLast = idx === arr . length - 1 ;
67
- createTreeLines ( node , lines , opts , depth + 1 , bars , isLast ) ;
36
+ var w = createTreeLines ( node , lines , opts , 1 , '' , isLast ) ;
37
+ maxLabelWidth = Math . max ( maxLabelWidth , w || 0 ) ;
68
38
} ) ;
69
- }
70
-
71
- return maxLabelWidth ;
72
- }
73
39
74
- function addTaskToLines ( task , lines , isLast , isLeaf ) {
75
- var taskBars = task . bars + ( isLast ? '└' : '├' ) + '─' ;
76
- if ( isLeaf ) {
77
- taskBars += '─ ' ;
78
- } else {
79
- taskBars += '┬ ' ;
40
+ lines . forEach ( function ( line ) {
41
+ var s = line . label ;
42
+ if ( line . desc ) {
43
+ var spaces = ' ' . repeat ( maxLabelWidth - line . label . length ) + ' ' ;
44
+ s += spaces + line . desc ;
45
+ }
46
+ log . info ( s ) ;
47
+ } ) ;
80
48
}
81
49
82
- var line = { } ;
83
- if ( task . depth === 1 ) {
84
- line . label = chalk . white ( taskBars ) + chalk . white ( task . label ) ;
85
- } else {
86
- line . label = chalk . white ( taskBars ) + chalk . cyan ( task . label ) ;
87
- }
88
- if ( typeof task . desc === 'string' && task . desc ) {
89
- line . desc = chalk . white ( task . desc ) ;
90
- }
91
- lines . push ( line ) ;
50
+ function createTreeLines ( node , lines , opts , depth , bars , isLast ) {
51
+ var task = { label : node . label , bars : bars , depth : depth } ;
52
+ if ( depth === 1 ) {
53
+ var t = opts . getTask ( node . label ) ;
54
+ task . desc = t . description ;
55
+ task . flags = t . flags ;
56
+ }
92
57
93
- var maxLabelWidth = line . label . length
58
+ var isLeaf = isLeafNode ( node , depth , opts ) ;
94
59
95
- if ( ! isObject ( task . flags ) ) {
96
- return maxLabelWidth ;
97
- }
60
+ var maxLabelWidth = addTaskToLines ( task , lines , isLast , isLeaf ) ;
98
61
99
- var flagBars = task . bars ;
100
- if ( isLast ) {
101
- flagBars += ' ' ;
102
- } else {
103
- flagBars += '│ ' ;
104
- }
62
+ if ( ! isLeaf ) {
63
+ bars += ( isLast ? ' ' : '│ ' ) ;
64
+ node . nodes . forEach ( function ( node , idx , arr ) {
65
+ var isLast = idx === arr . length - 1 ;
66
+ createTreeLines ( node , lines , opts , depth + 1 , bars , isLast ) ;
67
+ } ) ;
68
+ }
105
69
106
- if ( isLeaf ) {
107
- flagBars += ' ' ;
108
- } else {
109
- flagBars += '│ ' ;
70
+ return maxLabelWidth ;
110
71
}
111
72
112
- Object . entries ( task . flags ) . sort ( flagSorter ) . forEach ( addFlagsToLines ) ;
73
+ function addTaskToLines ( task , lines , isLast , isLeaf ) {
74
+ var taskBars = task . bars + ( isLast ? '└' : '├' ) + '─' ;
75
+ if ( isLeaf ) {
76
+ taskBars += '─ ' ;
77
+ } else {
78
+ taskBars += '┬ ' ;
79
+ }
113
80
114
- function addFlagsToLines ( ent ) {
115
- if ( typeof ent [ 0 ] !== 'string' || ! ent [ 0 ] ) return ;
116
81
var line = { } ;
82
+ if ( task . depth === 1 ) {
83
+ line . label = chalk . white ( taskBars ) + chalk . white ( task . label ) ;
84
+ } else {
85
+ line . label = chalk . white ( taskBars ) + chalk . cyan ( task . label ) ;
86
+ }
87
+ if ( typeof task . desc === 'string' && task . desc ) {
88
+ line . desc = chalk . white ( task . desc ) ;
89
+ }
117
90
lines . push ( line ) ;
118
- line . label = chalk . white ( flagBars ) + chalk . magenta ( ent [ 0 ] ) ;
119
91
120
- maxLabelWidth = Math . max ( maxLabelWidth , line . label . length ) ;
92
+ var maxLabelWidth = line . label . length
121
93
122
- if ( typeof ent [ 1 ] !== 'string' || ! ent [ 1 ] ) return ;
123
- line . desc = chalk . white ( '…' + ent [ 1 ] ) ;
124
- }
94
+ if ( ! isObject ( task . flags ) ) {
95
+ return maxLabelWidth ;
96
+ }
97
+
98
+ var flagBars = task . bars ;
99
+ if ( isLast ) {
100
+ flagBars += ' ' ;
101
+ } else {
102
+ flagBars += '│ ' ;
103
+ }
125
104
126
- return maxLabelWidth ;
105
+ if ( isLeaf ) {
106
+ flagBars += ' ' ;
107
+ } else {
108
+ flagBars += '│ ' ;
109
+ }
110
+
111
+ Object . entries ( task . flags ) . sort ( flagSorter ) . forEach ( addFlagsToLines ) ;
112
+
113
+ function addFlagsToLines ( ent ) {
114
+ if ( typeof ent [ 0 ] !== 'string' || ! ent [ 0 ] ) return ;
115
+ var line = { } ;
116
+ lines . push ( line ) ;
117
+ line . label = chalk . white ( flagBars ) + chalk . magenta ( ent [ 0 ] ) ;
118
+
119
+ maxLabelWidth = Math . max ( maxLabelWidth , line . label . length ) ;
120
+
121
+ if ( typeof ent [ 1 ] !== 'string' || ! ent [ 1 ] ) return ;
122
+ line . desc = chalk . white ( '…' + ent [ 1 ] ) ;
123
+ }
124
+
125
+ return maxLabelWidth ;
126
+ }
127
127
}
128
128
129
129
function isLeafNode ( node , depth , opts ) {
0 commit comments