-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Priyansh Garg <[email protected]>
- Loading branch information
1 parent
8234c7c
commit d7d9a81
Showing
4 changed files
with
84 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import colors from 'ansi-colors'; | ||
import inquirer from 'inquirer'; | ||
|
||
import Logger from '../../../../logger'; | ||
import {Platform} from '../../interfaces'; | ||
import {getBinaryLocation} from '../../utils/common'; | ||
import {execBinarySync, execBinaryAsync} from '../../utils/sdk'; | ||
import {showMissingBinaryHelp} from '../common'; | ||
|
||
export async function deleteAvd(sdkRoot: string, platform: Platform): Promise<boolean> { | ||
try { | ||
const avdmanagerLocation = getBinaryLocation(sdkRoot, platform, 'avdmanager', true); | ||
if (!avdmanagerLocation) { | ||
showMissingBinaryHelp('avdmanager'); | ||
|
||
return false; | ||
} | ||
|
||
const installedAvds = execBinarySync(avdmanagerLocation, 'avdmanager', platform, 'list avd -c'); | ||
if (installedAvds === null) { | ||
Logger.log(`${colors.red('\nFailed to fetch installed AVDs.')} Please try again.\n`); | ||
|
||
return false; | ||
} else if (installedAvds === '') { | ||
Logger.log(`${colors.yellow('No installed AVD found.')}\n`); | ||
Logger.log('To see the list of installed AVDs, run the following command:'); | ||
Logger.log(colors.cyan(' npx @nightwatch/mobile-helper android list --avd\n')); | ||
|
||
return false; | ||
} | ||
|
||
const avdAnswer = await inquirer.prompt({ | ||
type: 'list', | ||
name: 'avdName', | ||
message: 'Select the AVD to delete:', | ||
choices: installedAvds.split('\n').filter(avd => avd !== '') | ||
}); | ||
const avdName = avdAnswer.avdName; | ||
|
||
Logger.log(); | ||
Logger.log(`Deleting ${colors.cyan(avdName)}...\n`); | ||
|
||
const deleteStatus = await execBinaryAsync(avdmanagerLocation, 'avdmanager', platform, `delete avd --name '${avdName}'`); | ||
|
||
if (deleteStatus?.includes('deleted')) { | ||
Logger.log(colors.green('AVD deleted successfully!\n')); | ||
|
||
return true; | ||
} | ||
|
||
Logger.log(colors.red('Something went wrong while deleting AVD.')); | ||
Logger.log('Command output:', deleteStatus); | ||
Logger.log(`To verify if the AVD was deleted, run: ${colors.cyan('npx @nightwatch/mobile-helper android list --avd')}`); | ||
Logger.log('If the AVD is still present, try deleting it again.\n'); | ||
|
||
return false; | ||
} catch (error) { | ||
Logger.log(colors.red('\nError occurred while deleting AVD.')); | ||
console.error(error); | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {Options, Platform} from '../../interfaces'; | ||
import {deleteAvd} from './avd'; | ||
|
||
export async function uninstall(options: Options, sdkRoot: string, platform: Platform): Promise<boolean> { | ||
if (options.avd) { | ||
return await deleteAvd(sdkRoot, platform); | ||
} | ||
|
||
return false; | ||
} | ||
|