From 65760181186f858ecc4aa7aa923c1c4eccdff6ec Mon Sep 17 00:00:00 2001 From: itsspriyansh Date: Fri, 6 Sep 2024 02:38:13 +0530 Subject: [PATCH] fixes --- src/commands/android/constants.ts | 4 ++ .../android/subcommands/uninstall/index.ts | 16 ++++---- .../subcommands/uninstall/system-image.ts | 39 ++++++++++++++----- 3 files changed, 42 insertions(+), 17 deletions(-) diff --git a/src/commands/android/constants.ts b/src/commands/android/constants.ts index 662b106..1ecfdc0 100644 --- a/src/commands/android/constants.ts +++ b/src/commands/android/constants.ts @@ -102,6 +102,10 @@ export const AVAILABLE_SUBCOMMANDS: AvailableSubcommands = { usageHelp: 'device_id' } ] + }, + { + name: 'system-image', + description: 'Uninstall a system image' } ] } diff --git a/src/commands/android/subcommands/uninstall/index.ts b/src/commands/android/subcommands/uninstall/index.ts index d302994..d6899b5 100644 --- a/src/commands/android/subcommands/uninstall/index.ts +++ b/src/commands/android/subcommands/uninstall/index.ts @@ -5,6 +5,7 @@ import {Options, Platform} from '../../interfaces'; import {verifyOptions} from '../common'; import {uninstallApp} from './app'; import {deleteAvd} from './avd'; +import {deleteSystemImage} from './system-image'; export async function uninstall(options: Options, sdkRoot: string, platform: Platform): Promise { const optionsVerified = verifyOptions('uninstall', options); @@ -21,6 +22,8 @@ export async function uninstall(options: Options, sdkRoot: string, platform: Pla return await uninstallApp(options, sdkRoot, platform); } else if (subcommandFlag === 'avd') { return await deleteAvd(sdkRoot, platform); + } else if (subcommandFlag === 'system-image') { + return await deleteSystemImage(sdkRoot, platform); } return false; @@ -31,15 +34,14 @@ async function promptForFlag(): Promise { type: 'list', name: 'flag', message: 'Select what you want to uninstall:', - choices: ['Android App', 'Android Virtual Device (AVD)'] + choices: [ + {name: 'Android app', value: 'app'}, + {name: 'Android Virtual Device (AVD)', value: 'avd'}, + {name: 'System image', value: 'system-image'} + ] }); Logger.log(); - const flag = flagAnswer.flag; - if (flag === 'Android App') { - return 'app'; - } - - return 'avd'; + return flagAnswer.flag; } diff --git a/src/commands/android/subcommands/uninstall/system-image.ts b/src/commands/android/subcommands/uninstall/system-image.ts index 95d2a66..f25daff 100644 --- a/src/commands/android/subcommands/uninstall/system-image.ts +++ b/src/commands/android/subcommands/uninstall/system-image.ts @@ -3,8 +3,8 @@ import inquirer from 'inquirer'; import Logger from '../../../../logger'; import {Platform} from '../../interfaces'; -import {execBinarySync} from '../../utils/sdk'; import {getBinaryLocation} from '../../utils/common'; +import {execBinarySync} from '../../utils/sdk'; import {getInstalledSystemImages, showMissingBinaryHelp} from '../common'; export async function deleteSystemImage(sdkRoot: string, platform: Platform): Promise { @@ -15,8 +15,13 @@ export async function deleteSystemImage(sdkRoot: string, platform: Platform): Pr return false; } - const installedImages: string[] = await getInstalledSystemImages(sdkmanagerLocation, platform); - if (!installedImages.length) { + const installedSystemImages = await getInstalledSystemImages(sdkmanagerLocation, platform); + if (!installedSystemImages.result) { + return false; + } + if (!installedSystemImages.systemImages.length) { + Logger.log(colors.yellow('No installed system images were found!\n')); + return false; } @@ -24,7 +29,7 @@ export async function deleteSystemImage(sdkRoot: string, platform: Platform): Pr type: 'list', name: 'systemImage', message: 'Select the system image to uninstall:', - choices: installedImages + choices: installedSystemImages.systemImages }); const systemImage = systemImageAnswer.systemImage; @@ -32,16 +37,19 @@ export async function deleteSystemImage(sdkRoot: string, platform: Platform): Pr Logger.log(`Uninstalling ${colors.cyan(systemImageAnswer.systemImage)}...\n`); const deleteStatus = execBinarySync(sdkmanagerLocation, 'sdkmanager', platform, `--uninstall '${systemImage}'`); - if (!deleteStatus?.includes('100% Fetch remote repository')) { - Logger.log(`${colors.red('Failed to uninstall system image!')} Please try again.`); + if (deleteStatus?.includes('100% Fetch remote repository')) { + Logger.log(colors.green('System image uninstalled successfully!\n')); - return false; + deleteObsoleteAVDs(sdkRoot, platform); + + return true; } - Logger.log(colors.green('System image uninstalled successfully!\n')); - deleteObsoleteAVDs(sdkRoot, platform); + Logger.log(colors.red('\nSomething went wrong while uninstalling system image.\n')); + Logger.log(`To verify if the system image was uninstalled, run: ${colors.cyan('npx @nightwatch/mobile-helper android.sdkmanager --list_installed')}`); + Logger.log('If the system image is found listed, please try uninstalling again.\n'); - return true; + return false; } catch (error) { Logger.log(colors.red('Error occured while uninstalling system image.')); console.error(error); @@ -75,6 +83,17 @@ async function deleteObsoleteAVDs(sdkRoot: string, platform: Platform) { obsoleteAVDNames.forEach((avdName, idx) => { Logger.log(`${idx+1}. ${avdName}`); }); + Logger.log(); + + const deleteAnswer = await inquirer.prompt({ + type: 'confirm', + name: 'delete', + message: 'Do you want to delete these AVDs?' + }); + + if (!deleteAnswer.delete) { + return; + } Logger.log(); Logger.log('Deleting obsolete AVDs...\n');