Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
itsspriyansh committed Sep 5, 2024
1 parent c51e1d2 commit 6576018
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 17 deletions.
4 changes: 4 additions & 0 deletions src/commands/android/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ export const AVAILABLE_SUBCOMMANDS: AvailableSubcommands = {
usageHelp: 'device_id'
}
]
},
{
name: 'system-image',
description: 'Uninstall a system image'
}
]
}
Expand Down
16 changes: 9 additions & 7 deletions src/commands/android/subcommands/uninstall/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> {
const optionsVerified = verifyOptions('uninstall', options);
Expand All @@ -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;
Expand All @@ -31,15 +34,14 @@ async function promptForFlag(): Promise<string> {
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;
}

39 changes: 29 additions & 10 deletions src/commands/android/subcommands/uninstall/system-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> {
Expand All @@ -15,33 +15,41 @@ 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;
}

const systemImageAnswer = await inquirer.prompt({
type: 'list',
name: 'systemImage',
message: 'Select the system image to uninstall:',
choices: installedImages
choices: installedSystemImages.systemImages
});
const systemImage = systemImageAnswer.systemImage;

Logger.log();
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);
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit 6576018

Please sign in to comment.