Skip to content

Commit c32bf28

Browse files
committed
Refactor contdd...
1 parent ecfafb0 commit c32bf28

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/cmd/esim.js

+15-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const SerialCommand = require('./serial');
1010
const FlashCommand = require('./flash');
1111
const path = require('path');
1212
const _ = require('lodash');
13+
const { log } = require('console');
1314

1415
// TODO: Get these from exports
1516
const PROVISIONING_PROGRESS = 1;
@@ -18,7 +19,6 @@ const PROVISIONING_FAILURE = 3;
1819
const CTRL_REQUEST_APP_CUSTOM = 10;
1920
const GET_AT_COMMAND_STATUS = 4;
2021

21-
2222
module.exports = class eSimCommands extends CLICommandBase {
2323
constructor() { // TODO: Bring ui class
2424
super();
@@ -106,6 +106,7 @@ module.exports = class eSimCommands extends CLICommandBase {
106106
if (!flashResp.success) {
107107
return outputMsg();
108108
}
109+
provisionOutputLogs.push(`${os.EOL}Firmware flashed successfully`);
109110

110111
// Get the EID
111112
const eidResp = await this._getEid(port);
@@ -120,6 +121,11 @@ module.exports = class eSimCommands extends CLICommandBase {
120121
const matchingEsim = this.inputJsonData.provisioning_data.find(item => item.esim_id === eid);
121122
const iccidFromJson = matchingEsim.profiles.map((profile) => profile.iccid);
122123
expectedProfilesArray = matchingEsim.profiles;
124+
125+
if (!matchingEsim || iccidFromJson?.length === 0 || expectedProfilesArray?.length === 0) {
126+
provisionOutputLogs.push('No profiles found for the given EID in the input JSON');
127+
return outputMsg();
128+
}
123129

124130
const profileCmdResp = await this._checkForExistingProfiles(port);
125131
provisionOutputLogs.push(...profileCmdResp.output);
@@ -129,6 +135,8 @@ module.exports = class eSimCommands extends CLICommandBase {
129135

130136
const profilesListOnDevice = profileCmdResp.profilesList;
131137
const existingIccids = profilesListOnDevice.map((line) => line.split('[')[1].split(',')[0].trim());
138+
provisionOutputLogs.push(`${os.EOL}profilesListOnDevice: ${profilesListOnDevice}`);
139+
provisionOutputLogs.push(`${os.EOL}existingIccids: ${existingIccids}`);
132140

133141
if (profilesListOnDevice.length > 0) {
134142
// extract the iccids that belong to this EID
@@ -166,7 +174,8 @@ module.exports = class eSimCommands extends CLICommandBase {
166174

167175
// Download each profile and update the JSON output
168176
await this._changeLed(device, PROVISIONING_PROGRESS);
169-
177+
178+
provisionOutputLogs.push(`${os.EOL}Downloading profiles...`);
170179
const downloadResp = await this._doDownload(profiles, port);
171180
const downloadedProfiles = downloadResp.downloadedProfiles;
172181
downloadedProfilesArray = downloadedProfiles.map((profile) => {
@@ -180,6 +189,7 @@ module.exports = class eSimCommands extends CLICommandBase {
180189
provisionOutputLogs.push(...downloadResp.output);
181190

182191
if (!downloadResp.success) {
192+
provisionOutputLogs.push('Profile download failed');
183193
return outputMsg();
184194
}
185195

@@ -257,6 +267,7 @@ module.exports = class eSimCommands extends CLICommandBase {
257267
// Flash the binary
258268
const flashCmdInstance = new FlashCommand();
259269

270+
logAndPush(`${os.EOL}Flashing firmware...`);
260271
await flashCmdInstance.flashLocal({
261272
files: [device.deviceId, fwPath],
262273
applicationOnly: true,
@@ -277,7 +288,7 @@ module.exports = class eSimCommands extends CLICommandBase {
277288
while (Date.now() - start < timeout && !atOkReceived) {
278289
try {
279290
const resp = await usbDevice.sendControlRequest(CTRL_REQUEST_APP_CUSTOM, JSON.stringify(GET_AT_COMMAND_STATUS));
280-
console.log('[dbg] resp: ', resp);
291+
// console.log('[dbg] resp: ', resp);
281292
if (resp?.result === 0 && resp.data?.[0] === '1') {
282293
logAndPush('AT-OK received');
283294
atOkReceived = true;
@@ -397,6 +408,7 @@ module.exports = class eSimCommands extends CLICommandBase {
397408
}
398409
});
399410
};
411+
logAndPush(`${os.EOL}Getting profiles for EID ${eid}...`);
400412
const eidBlock = this.inputJsonData.provisioning_data.find((block) => block.esim_id === eid);
401413

402414
if (!eidBlock || !eidBlock.profiles || eidBlock.profiles.length === 0) {

0 commit comments

Comments
 (0)