Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
keeramis committed Nov 19, 2024
1 parent 8b8c013 commit 0fa1e52
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/cmd/esim.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ module.exports = class eSimCommands extends CLICommandBase {

const profiles = eidBlock?.profiles;

console.log(`${os.EOL}Provisioning the following profiles: `);
console.log(`${os.EOL}Provisioning the following profiles to EID ${eid}:`);
profiles.forEach((profile, index) => {
const rspUrl = `1\$${profile.smdp}\$${profile.matching_id}`;
console.log(`\t${index + 1}. ${profile.provider} (${rspUrl})`);
Expand All @@ -66,11 +66,12 @@ module.exports = class eSimCommands extends CLICommandBase {
console.log(`${os.EOL}${index + 1}. Downloading ${profile.provider} profile from ${rspUrl}`);

const start = Date.now();
let timeTaken = 0;
let iccid = null;

try {
const res = await execa(this.lpa, ['download', rspUrl, `--serial=${port}`]);
const timeTaken = ((Date.now() - start) / 1000).toFixed(2);
timeTaken = ((Date.now() - start) / 1000).toFixed(2);

const output = res.stdout;
if (output.includes('Profile successfully downloaded')) {
Expand All @@ -93,8 +94,17 @@ module.exports = class eSimCommands extends CLICommandBase {

this._addToJson(this.outputJson, outputData);
} catch (err) {
console.error(`${os.EOL}\tFailed to download profile: ${err.message}`);
const outputData = {
EID: eid,
provider: profile.provider,
iccid,
time: timeTaken,
output: err.message,
};
this._addToJson(this.outputJson, outputData);
throw new Error('Failed to download profile');
}

}

console.log(`${os.EOL}Provisioning complete`);
Expand Down Expand Up @@ -239,7 +249,6 @@ module.exports = class eSimCommands extends CLICommandBase {

// Write updated JSON back to the file with indentation
fs.writeFileSync(jsonFile, JSON.stringify(existingJson, null, 4));
console.log('Data appended successfully');
} catch (error) {
console.error(`Failed to append data to JSON file: ${error.message}`);
}
Expand Down

0 comments on commit 0fa1e52

Please sign in to comment.