@@ -33,21 +33,10 @@ class AsyncTree {
33
33
}
34
34
35
35
traverse ( ) {
36
- const childNode = AsyncTree . getNextChild ( this . currentNode ) ;
36
+ const childNode = AsyncTree . getNextChildNode ( this . currentNode ) ;
37
37
38
38
if ( childNode ) {
39
- return this . runChildNode ( childNode ) . then ( result => {
40
- let abortOnFailure = false ;
41
- if ( result instanceof Error ) {
42
- abortOnFailure = result . abortOnFailure || Utils . isUndefined ( result . abortOnFailure ) ;
43
- }
44
-
45
- if ( abortOnFailure ) {
46
- return this . done ( result ) ;
47
- }
48
-
49
- return this . traverse ( ) ;
50
- } ) ;
39
+ return this . runChildNode ( childNode ) ;
51
40
}
52
41
53
42
if ( this . currentNode . childNodes . length > 0 && this . currentNode . needsPromise ) {
@@ -62,20 +51,15 @@ class AsyncTree {
62
51
walkUp ( ) {
63
52
if ( this . currentNode . childNodes . length > 0 && ! this . currentNode . done ) {
64
53
// if the current node has childNodes that have not finished yet
65
- return new Promise ( ( resolve , reject ) => {
66
- this . currentNode . result
67
- . then ( _ => resolve ( ) )
68
- . catch ( err => reject ( err ) ) ;
54
+ return this . currentNode . result . catch ( err => {
55
+ console . error ( err ) ;
56
+ throw err ;
69
57
} ) ;
70
58
}
71
59
72
60
if ( ! this . currentNode . done ) {
73
61
// if the current node hasn't finished yet
74
- return new Promise ( ( resolve , reject ) => {
75
- this . currentNode . result
76
- . then ( _ => resolve ( ) )
77
- . catch ( err => reject ( err ) ) ;
78
- } ) . then ( _ => this . walkUp ( ) ) ;
62
+ return this . currentNode . result
79
63
}
80
64
81
65
this . currentNode = this . currentNode . parent ;
@@ -86,17 +70,23 @@ class AsyncTree {
86
70
runChildNode ( node ) {
87
71
this . currentNode = node ;
88
72
this . currentNode . started = true ;
89
- Logger . log ( `\n ${ Logger . colors . green ( '→' ) } Running command: ${ Logger . colors . light_green ( node . name ) } (${ AsyncTree . printArguments ( node ) } )` ) ;
73
+ Logger . log ( `\n ${ Logger . colors . green ( '→' ) } Running command: ${ Logger . colors . light_green ( node . fullName ) } (${ AsyncTree . printArguments ( node ) } )` ) ;
90
74
91
75
return node . run ( )
92
76
. then ( result => {
93
- Logger . log ( `${ Logger . colors . green ( '→' ) } Completed command ${ Logger . colors . light_green ( node . name ) } ` +
77
+ Logger . log ( `${ Logger . colors . green ( '→' ) } Completed command ${ Logger . colors . light_green ( node . fullName ) } ` +
94
78
` (${ AsyncTree . printArguments ( node ) } ) (${ node . elapsedTime } ms)` ) ;
95
79
96
- return result ;
97
- } )
98
- . catch ( err => {
99
- return err ;
80
+ let abortOnFailure = false ;
81
+ if ( result instanceof Error ) {
82
+ abortOnFailure = result . abortOnFailure || Utils . isUndefined ( result . abortOnFailure ) ;
83
+ }
84
+
85
+ if ( abortOnFailure ) {
86
+ return this . done ( result ) ;
87
+ }
88
+
89
+ return this . traverse ( ) ;
100
90
} ) ;
101
91
}
102
92
@@ -124,17 +114,22 @@ class AsyncTree {
124
114
///////////////////////////////////////////////////////////////////////////
125
115
// STATIC
126
116
///////////////////////////////////////////////////////////////////////////
127
- static getNextChild ( node ) {
117
+ static getNextChildNode ( node ) {
118
+ let childNode ;
128
119
for ( let i = 0 ; i < node . childNodes . length ; i ++ ) {
129
120
if ( ! node . childNodes [ i ] . started ) {
130
121
return node . childNodes [ i ] ;
131
122
}
132
123
133
124
if ( node . childNodes [ i ] . childNodes . length > 0 ) {
134
- return AsyncTree . getNextChild ( node . childNodes [ i ] ) ;
125
+ childNode = node . childNodes [ i ] ;
135
126
}
136
127
}
137
128
129
+ if ( childNode ) {
130
+ //return AsyncTree.getNextChildNode(childNode);
131
+ }
132
+
138
133
return false ;
139
134
}
140
135
0 commit comments