@@ -2,10 +2,10 @@ const execa = require('execa');
2
2
const utilities = require ( '../lib/utilities' ) ;
3
3
const path = require ( 'path' ) ;
4
4
const fs = require ( 'fs-extra' ) ;
5
- const os = require ( 'os' ) ;
6
5
const util = require ( 'util' ) ;
7
6
const temp = require ( 'temp' ) . track ( ) ;
8
7
const mkdirTemp = util . promisify ( temp . mkdir ) ;
8
+ const os = require ( 'os' ) ;
9
9
10
10
const TACHYON_STORAGE_TYPE = 'ufs' ;
11
11
@@ -42,18 +42,25 @@ class QdlFlasher {
42
42
stdio : 'pipe'
43
43
} ) ;
44
44
45
- const handleStream = ( stream ) => {
46
- stream . on ( 'data' , chunk => {
47
- chunk . toString ( ) . split ( '\n' ) . map ( line => line . trim ( ) ) . filter ( Boolean ) . forEach ( line => {
48
- this . processLogLine ( line , qdlProcess ) ;
45
+ await new Promise ( ( resolve , reject ) => {
46
+ const handleStream = ( stream ) => {
47
+ stream . on ( 'data' , chunk => {
48
+ chunk . toString ( ) . split ( '\n' ) . map ( line => line . trim ( ) ) . filter ( Boolean ) . forEach ( this . processLogLine . bind ( this ) ) ;
49
49
} ) ;
50
- } ) ;
51
- } ;
50
+ } ;
52
51
53
- handleStream ( qdlProcess . stdout ) ;
54
- handleStream ( qdlProcess . stderr ) ;
52
+ handleStream ( qdlProcess . stdout ) ;
53
+ handleStream ( qdlProcess . stderr ) ;
55
54
56
- await qdlProcess ;
55
+ qdlProcess . on ( 'close' , ( output ) => {
56
+ if ( output !== 0 ) {
57
+ return reject ( new Error ( 'Unable to complete device flashing. See logs for further details.' ) ) ;
58
+ } else {
59
+ return resolve ( ) ;
60
+ }
61
+ } ) ;
62
+ qdlProcess . on ( 'error' , reject ) ;
63
+ } ) ;
57
64
} finally {
58
65
if ( this . progressBarInitialized ) {
59
66
this . progressBar . stop ( ) ;
@@ -89,25 +96,12 @@ class QdlFlasher {
89
96
] ;
90
97
}
91
98
92
- processLogLine ( line , process ) {
99
+ processLogLine ( line ) {
93
100
fs . appendFileSync ( this . outputLogFile , `${ line } \n` ) ;
94
-
95
101
if ( line . includes ( 'Waiting for EDL device' ) ) {
96
- this . handleError ( process , `Ensure your device is connected and in EDL mode${ os . EOL } ` ) ;
97
- } else if ( line . includes ( '[ERROR]' ) ) {
98
- this . handleError ( process , `${ os . EOL } Error detected: ${ line } ${ os . EOL } ` ) ;
99
- } else {
100
- this . processFlashingLogs ( line ) ;
101
- }
102
- }
103
-
104
- handleError ( process , message ) {
105
- this . ui . stdout . write ( message ) ;
106
- process . kill ( ) ;
107
- }
108
-
109
- processFlashingLogs ( line ) {
110
- if ( line . includes ( 'status=getProgramInfo' ) ) {
102
+ const message = `Tachyon not found. Disconnect and reconnect the device, and ensure it is in EDL mode ${ os . EOL } ` ;
103
+ this . ui . stdout . write ( this . ui . chalk . bold ( this . ui . chalk . yellow ( message ) ) ) ;
104
+ } else if ( line . includes ( 'status=getProgramInfo' ) ) {
111
105
this . handleProgramInfo ( line ) ;
112
106
} else if ( line . includes ( 'status=Start flashing module' ) ) {
113
107
this . handleModuleStart ( line ) ;
0 commit comments