'use strict' ; import * as vscode from 'vscode' ; import { IBlockchainQuickPickItem , UserInputUtil } from './UserInputUtil' ; import { PackageTreeItem } from '../explorer/model/PackageTreeItem' ; import { PackageRegistry } from '../registries/PackageRegistry' ; import { PackageRegistryEntry } from '../registries/PackageRegistryEntry' ; import { VSCodeBlockchainOutputAdapter } from '../logging/VSCodeBlockchainOutputAdapter' ; import { LogType } from 'ibm-blockchain-platform-common' ; import { ExtensionCommands } from '../../ExtensionCommands' ; import { DeployView } from '../webview/DeployView' ; export async function deleteSmartContractPackage ( packageTreeItem ) { const outputAdapter = VSCodeBlockchainOutputAdapter . instance ( ) ; outputAdapter . log ( LogType . INFO , undefined , `deleteSmartContractPackage` ) ; let packagesToDelete ; if ( packageTreeItem ) { packagesToDelete = [ packageTreeItem . packageEntry ] ; } else { const chosenPackages = await UserInputUtil . showSmartContractPackagesQuickPickBox ( 'Choose the smart contract package(s) that you want to delete' , true ) as IBlockchainQuickPickItem < PackageRegistryEntry > [ ] ; if ( ! chosenPackages || chosenPackages . length === 0 ) { return ; } packagesToDelete = chosenPackages . map ( ( _package ) => { return _package . data ; } ) ; } const areYouSure = await UserInputUtil . showConfirmationWarningMessage ( `This will delete the selected package(s) from your file system. Do you want to continue?` ) ; if ( areYouSure ) { const packageRegistry = PackageRegistry . instance ( ) ; for ( const _package of packagesToDelete ) { await packageRegistry . delete ( _package ) ; } await vscode . commands . executeCommand ( ExtensionCommands . REFRESH_PACKAGES ) ; if ( packagesToDelete . length > 1 ) { outputAdapter . log ( LogType . SUCCESS , `Successfully deleted packages` ) ; } else { outputAdapter . log ( LogType . SUCCESS , `Successfully deleted ${ packagesToDelete [ 0 ] . name } package` ) ; } const panel = DeployView . panel ; if ( panel ) { await DeployView . updatePackages ( ) ; } } }