@@ -11,7 +11,6 @@ const FlashCommand = require('./flash');
11
11
const path = require ( 'path' ) ;
12
12
const _ = require ( 'lodash' ) ;
13
13
const chalk = require ( 'chalk' ) ;
14
- const { clear } = require ( 'console' ) ;
15
14
16
15
// TODO: Get these from exports
17
16
const PROVISIONING_PROGRESS = 1 ;
@@ -79,37 +78,29 @@ module.exports = class ESimCommands extends CLICommandBase {
79
78
console . log ( 'Ready to bulk provision. Connect devices to start. Press Ctrl-C to exit.' ) ;
80
79
}
81
80
82
- async enableCommand ( iccid ) {
81
+ async _checkForTachyonDevice ( ) {
83
82
console . log ( chalk . bold ( `Ensure only one device is connected${ os . EOL } ` ) ) ;
84
83
this . verbose = true ;
85
84
const device = await this . serial . whatSerialPortDidYouMean ( ) ;
86
85
if ( device . type !== 'Tachyon' ) {
87
86
throw new Error ( 'Enable command is only for Tachyon devices' ) ;
88
87
}
89
88
this . isTachyon = true ;
89
+ return device ;
90
+ }
91
+
92
+ async enableCommand ( iccid ) {
93
+ await this . _checkForTachyonDevice ( ) ;
90
94
await this . doEnable ( iccid ) ;
91
95
}
92
96
93
- async deleteCommand ( args , iccid ) {
94
- console . log ( chalk . bold ( `Ensure only one device is connected${ os . EOL } ` ) ) ;
95
- this . verbose = true ;
96
- const device = await this . serial . whatSerialPortDidYouMean ( ) ;
97
- if ( device . type !== 'Tachyon' ) {
98
- throw new Error ( 'Delete command is only for Tachyon devices' ) ;
99
- }
100
- this . isTachyon = true ;
101
- this . _validateArgs ( args ) ;
97
+ async deleteCommand ( iccid ) {
98
+ const device = await this . _checkForTachyonDevice ( ) ;
102
99
await this . doDelete ( device , iccid ) ;
103
100
}
104
101
105
102
async listCommand ( ) {
106
- console . log ( chalk . bold ( `Ensure only one device is connected${ os . EOL } ` ) ) ;
107
- this . verbose = true ;
108
- const device = await this . serial . whatSerialPortDidYouMean ( ) ;
109
- if ( device . type !== 'Tachyon' ) {
110
- throw new Error ( 'List command is only for Tachyon devices' ) ;
111
- }
112
- this . isTachyon = true ;
103
+ await this . _checkForTachyonDevice ( ) ;
113
104
await this . doList ( ) ;
114
105
}
115
106
@@ -284,15 +275,15 @@ module.exports = class ESimCommands extends CLICommandBase {
284
275
async doEnable ( iccid ) {
285
276
const TACHYON_QLRIL_WAIT_TIMEOUT = 20000 ;
286
277
let output = '' ;
287
-
278
+
288
279
try {
289
280
this . adbProcess = execa ( 'adb' , [ 'shell' , 'qlril-app' , 'enable' , iccid ] ) ;
290
-
281
+
291
282
await new Promise ( ( resolve , reject ) => {
292
283
const timeout = setTimeout ( ( ) => {
293
284
reject ( new Error ( 'Timeout waiting for qlril app to start' ) ) ;
294
285
} , TACHYON_QLRIL_WAIT_TIMEOUT ) ;
295
-
286
+
296
287
this . adbProcess . stdout . on ( 'data' , ( data ) => {
297
288
output += data . toString ( ) ;
298
289
if ( output . includes ( `ICCID currently active: ${ iccid } ` ) ) {
@@ -301,18 +292,18 @@ module.exports = class ESimCommands extends CLICommandBase {
301
292
resolve ( ) ;
302
293
}
303
294
} ) ;
304
-
295
+
305
296
this . adbProcess . catch ( ( error ) => {
306
297
clearTimeout ( timeout ) ;
307
298
reject ( new Error ( `ADB process error: ${ error . message } ` ) ) ;
308
299
} ) ;
309
-
300
+
310
301
this . adbProcess . then ( ( ) => {
311
302
clearTimeout ( timeout ) ;
312
303
reject ( new Error ( 'ADB process ended early without valid output' ) ) ;
313
304
} ) ;
314
305
} ) ;
315
-
306
+
316
307
console . log ( os . EOL ) ;
317
308
} catch ( error ) {
318
309
console . error ( `Failed to enable profiles: ${ error . message } ` ) ;
@@ -324,7 +315,7 @@ module.exports = class ESimCommands extends CLICommandBase {
324
315
async doDelete ( device , iccid ) {
325
316
try {
326
317
const port = device . port ;
327
-
318
+
328
319
await this . _initializeQlril ( ) ;
329
320
330
321
const iccidsOnDevice = await this . _getIccidOnDevice ( port ) ;
@@ -333,10 +324,10 @@ module.exports = class ESimCommands extends CLICommandBase {
333
324
console . log ( `ICCID ${ iccid } not found on the device or is a test ICCID` ) ;
334
325
return ;
335
326
}
336
-
327
+
337
328
await execa ( this . lpa , [ 'disable' , iccid , `--serial=${ port } ` ] ) ;
338
329
await execa ( this . lpa , [ 'delete' , iccid , `--serial=${ port } ` ] ) ;
339
-
330
+
340
331
console . log ( 'Profile deleted successfully' ) ;
341
332
} catch ( error ) {
342
333
console . error ( `Failed to delete profile: ${ error . message } ` ) ;
@@ -348,59 +339,59 @@ module.exports = class ESimCommands extends CLICommandBase {
348
339
async doList ( ) {
349
340
const TACHYON_QLRIL_WAIT_TIMEOUT = 10000 ;
350
341
let output = '' ;
351
-
342
+
352
343
try {
353
344
this . adbProcess = execa ( 'adb' , [ 'shell' , 'qlril-app' , 'listProfiles' ] ) ;
354
-
345
+
355
346
await new Promise ( ( resolve , reject ) => {
356
347
const timeout = setTimeout ( ( ) => {
357
348
reject ( new Error ( 'Timeout waiting for qlril app to start' ) ) ;
358
349
} , TACHYON_QLRIL_WAIT_TIMEOUT ) ;
359
-
350
+
360
351
this . adbProcess . stdout . on ( 'data' , ( data ) => {
361
352
output += data . toString ( ) ;
362
-
353
+
363
354
const iccids = output
364
355
. trim ( )
365
356
. replace ( / ^ \[ / , '' )
366
357
. replace ( / \] $ / , '' )
367
358
. split ( ',' )
368
359
. map ( iccid => iccid . trim ( ) )
369
360
. filter ( Boolean ) ;
370
-
361
+
371
362
if ( iccids . length > 0 ) {
372
363
console . log ( `Profiles found:${ os . EOL } ` ) ;
373
364
iccids . forEach ( iccid => console . log ( `\t- ${ iccid } ` ) ) ;
374
365
clearTimeout ( timeout ) ;
375
366
resolve ( ) ;
376
367
}
377
368
} ) ;
378
-
369
+
379
370
this . adbProcess . catch ( ( error ) => {
380
371
clearTimeout ( timeout ) ;
381
372
reject ( new Error ( `ADB process error: ${ error . message } ` ) ) ;
382
373
} ) ;
383
-
374
+
384
375
this . adbProcess . then ( ( ) => {
385
376
clearTimeout ( timeout ) ;
386
377
reject ( new Error ( 'ADB process ended early without valid output' ) ) ;
387
378
} ) ;
388
379
} ) ;
389
-
380
+
390
381
console . log ( os . EOL ) ;
391
382
} catch ( error ) {
392
383
console . error ( `Failed to list profiles: ${ error . message } ` ) ;
393
384
} finally {
394
385
this . _exitQlril ( ) ;
395
386
}
396
- }
397
-
387
+ }
388
+
398
389
399
390
_validateArgs ( args ) {
400
391
if ( ! args ?. lpa ) {
401
392
throw new Error ( 'Missing LPA tool path' ) ;
402
393
}
403
-
394
+
404
395
this . inputJson = args ?. input ;
405
396
if ( this . inputJson ) {
406
397
try {
@@ -409,7 +400,7 @@ module.exports = class ESimCommands extends CLICommandBase {
409
400
throw new Error ( `Invalid JSON in input file: ${ error . message } ` ) ;
410
401
}
411
402
}
412
-
403
+
413
404
this . outputFolder = args ?. output || 'esim_loading_logs' ;
414
405
if ( ! fs . existsSync ( this . outputFolder ) ) {
415
406
fs . mkdirSync ( this . outputFolder ) ;
0 commit comments