Skip to content

Commit a7b71f0

Browse files
committed
Lint fix and minor refactor
1 parent 08de643 commit a7b71f0

File tree

2 files changed

+32
-46
lines changed

2 files changed

+32
-46
lines changed

src/cli/esim.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ module.exports = ({ commandProcessor, root }) => {
5353
}
5454
});
5555

56-
commandProcessor.createCommand(esim, 'delete', '(Only for Tachyon) Deletes an ICCID profile on the eSIM', {
56+
commandProcessor.createCommand(esim, 'delete', '(Only for Tachyon) Deletes an eSIM profile', {
5757
options: Object.assign({
5858
'lpa': {
5959
description: 'Provide the LPA tool path'
@@ -69,12 +69,7 @@ module.exports = ({ commandProcessor, root }) => {
6969
}
7070
});
7171

72-
commandProcessor.createCommand(esim, 'list', '(Only for Tachyon) Lists all the eSIM profiles on the device', {
73-
options: Object.assign({
74-
'lpa': {
75-
description: 'Provide the LPA tool path'
76-
},
77-
}),
72+
commandProcessor.createCommand(esim, 'list', '(Only for Tachyon) Lists all the profiles on the eSIM', {
7873
handler: (args) => {
7974
const ESimCommands = require('../cmd/esim');
8075
return new ESimCommands().listCommand(args);

src/cmd/esim.js

Lines changed: 30 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const FlashCommand = require('./flash');
1111
const path = require('path');
1212
const _ = require('lodash');
1313
const chalk = require('chalk');
14-
const { clear } = require('console');
1514

1615
// TODO: Get these from exports
1716
const PROVISIONING_PROGRESS = 1;
@@ -79,37 +78,29 @@ module.exports = class ESimCommands extends CLICommandBase {
7978
console.log('Ready to bulk provision. Connect devices to start. Press Ctrl-C to exit.');
8079
}
8180

82-
async enableCommand(iccid) {
81+
async _checkForTachyonDevice() {
8382
console.log(chalk.bold(`Ensure only one device is connected${os.EOL}`));
8483
this.verbose = true;
8584
const device = await this.serial.whatSerialPortDidYouMean();
8685
if (device.type !== 'Tachyon') {
8786
throw new Error('Enable command is only for Tachyon devices');
8887
}
8988
this.isTachyon = true;
89+
return device;
90+
}
91+
92+
async enableCommand(iccid) {
93+
await this._checkForTachyonDevice();
9094
await this.doEnable(iccid);
9195
}
9296

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();
10299
await this.doDelete(device, iccid);
103100
}
104101

105102
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();
113104
await this.doList();
114105
}
115106

@@ -284,15 +275,15 @@ module.exports = class ESimCommands extends CLICommandBase {
284275
async doEnable(iccid) {
285276
const TACHYON_QLRIL_WAIT_TIMEOUT = 20000;
286277
let output = '';
287-
278+
288279
try {
289280
this.adbProcess = execa('adb', ['shell', 'qlril-app', 'enable', iccid]);
290-
281+
291282
await new Promise((resolve, reject) => {
292283
const timeout = setTimeout(() => {
293284
reject(new Error('Timeout waiting for qlril app to start'));
294285
}, TACHYON_QLRIL_WAIT_TIMEOUT);
295-
286+
296287
this.adbProcess.stdout.on('data', (data) => {
297288
output += data.toString();
298289
if (output.includes(`ICCID currently active: ${iccid}`)) {
@@ -301,18 +292,18 @@ module.exports = class ESimCommands extends CLICommandBase {
301292
resolve();
302293
}
303294
});
304-
295+
305296
this.adbProcess.catch((error) => {
306297
clearTimeout(timeout);
307298
reject(new Error(`ADB process error: ${error.message}`));
308299
});
309-
300+
310301
this.adbProcess.then(() => {
311302
clearTimeout(timeout);
312303
reject(new Error('ADB process ended early without valid output'));
313304
});
314305
});
315-
306+
316307
console.log(os.EOL);
317308
} catch (error) {
318309
console.error(`Failed to enable profiles: ${error.message}`);
@@ -324,7 +315,7 @@ module.exports = class ESimCommands extends CLICommandBase {
324315
async doDelete(device, iccid) {
325316
try {
326317
const port = device.port;
327-
318+
328319
await this._initializeQlril();
329320

330321
const iccidsOnDevice = await this._getIccidOnDevice(port);
@@ -333,10 +324,10 @@ module.exports = class ESimCommands extends CLICommandBase {
333324
console.log(`ICCID ${iccid} not found on the device or is a test ICCID`);
334325
return;
335326
}
336-
327+
337328
await execa(this.lpa, ['disable', iccid, `--serial=${port}`]);
338329
await execa(this.lpa, ['delete', iccid, `--serial=${port}`]);
339-
330+
340331
console.log('Profile deleted successfully');
341332
} catch (error) {
342333
console.error(`Failed to delete profile: ${error.message}`);
@@ -348,59 +339,59 @@ module.exports = class ESimCommands extends CLICommandBase {
348339
async doList() {
349340
const TACHYON_QLRIL_WAIT_TIMEOUT = 10000;
350341
let output = '';
351-
342+
352343
try {
353344
this.adbProcess = execa('adb', ['shell', 'qlril-app', 'listProfiles']);
354-
345+
355346
await new Promise((resolve, reject) => {
356347
const timeout = setTimeout(() => {
357348
reject(new Error('Timeout waiting for qlril app to start'));
358349
}, TACHYON_QLRIL_WAIT_TIMEOUT);
359-
350+
360351
this.adbProcess.stdout.on('data', (data) => {
361352
output += data.toString();
362-
353+
363354
const iccids = output
364355
.trim()
365356
.replace(/^\[/, '')
366357
.replace(/\]$/, '')
367358
.split(',')
368359
.map(iccid => iccid.trim())
369360
.filter(Boolean);
370-
361+
371362
if (iccids.length > 0) {
372363
console.log(`Profiles found:${os.EOL}`);
373364
iccids.forEach(iccid => console.log(`\t- ${iccid}`));
374365
clearTimeout(timeout);
375366
resolve();
376367
}
377368
});
378-
369+
379370
this.adbProcess.catch((error) => {
380371
clearTimeout(timeout);
381372
reject(new Error(`ADB process error: ${error.message}`));
382373
});
383-
374+
384375
this.adbProcess.then(() => {
385376
clearTimeout(timeout);
386377
reject(new Error('ADB process ended early without valid output'));
387378
});
388379
});
389-
380+
390381
console.log(os.EOL);
391382
} catch (error) {
392383
console.error(`Failed to list profiles: ${error.message}`);
393384
} finally {
394385
this._exitQlril();
395386
}
396-
}
397-
387+
}
388+
398389

399390
_validateArgs(args) {
400391
if (!args?.lpa) {
401392
throw new Error('Missing LPA tool path');
402393
}
403-
394+
404395
this.inputJson = args?.input;
405396
if (this.inputJson) {
406397
try {
@@ -409,7 +400,7 @@ module.exports = class ESimCommands extends CLICommandBase {
409400
throw new Error(`Invalid JSON in input file: ${error.message}`);
410401
}
411402
}
412-
403+
413404
this.outputFolder = args?.output || 'esim_loading_logs';
414405
if (!fs.existsSync(this.outputFolder)) {
415406
fs.mkdirSync(this.outputFolder);

0 commit comments

Comments
 (0)