'use strict' ; import { Reporter } from '../util/Reporter' ; import { IBlockchainQuickPickItem , UserInputUtil } from './UserInputUtil' ; import { PackageTreeItem } from '../explorer/model/PackageTreeItem' ; import { PackageRegistryEntry } from '../registries/PackageRegistryEntry' ; import { VSCodeBlockchainOutputAdapter } from '../logging/VSCodeBlockchainOutputAdapter' ; import { LogType } from 'ibm-blockchain-platform-common' ; export async function viewPackageInformation ( packageTreeItem ? ) { const outputAdapter = VSCodeBlockchainOutputAdapter . instance ( ) ; outputAdapter . log ( LogType . INFO , undefined , 'viewPackageInformation' ) ; try { let packageToView ; if ( packageTreeItem ) { packageToView = packageTreeItem . packageEntry ; } else { const chosenPackage = await UserInputUtil . showSmartContractPackagesQuickPickBox ( 'Choose the smart contract package that you want to view information for' , false ) as IBlockchainQuickPickItem < PackageRegistryEntry > ; if ( ! chosenPackage ) { return ; } packageToView = chosenPackage . data ; } let fileNames ; let packageName = packageToView . name ; if ( packageToView . version ) { packageName = packageName + '@' + packageToView . version ; } try { const { ListFilesInPackage } = await import ( 'ibm-blockchain-platform-environment-v1' ) ; fileNames = await ListFilesInPackage . listFiles ( packageToView . path ) ; outputAdapter . log ( LogType . INFO , undefined , `Found ${ fileNames . length } file(s) in smart contract package ${ packageName }:` ) ; for ( const file of fileNames ) { outputAdapter . log ( LogType . INFO , undefined , `- ${ file }` ) ; } outputAdapter . show ( ) ; } catch ( error ) { throw new Error ( `Unable to extract file list from ${ packageName }: ${ error . message }` ) ; } outputAdapter . log ( LogType . SUCCESS , `Displayed information for smart contract package ${ packageName }.` ) ; Reporter . instance ( ) . sendTelemetryEvent ( 'viewPackageInformationCommand' ) ; } catch ( error ) { outputAdapter . log ( LogType . ERROR , error . message , error . toString ( ) ) ; } }