'use strict' ; import * as vscode from 'vscode' ; import { Reporter } from '../util/Reporter' ; import { IBlockchainQuickPickItem , UserInputUtil } from './UserInputUtil' ; import { PackageTreeItem } from '../explorer/model/PackageTreeItem' ; import { PackageRegistryEntry } from '../registries/PackageRegistryEntry' ; import * as fs from 'fs-extra' ; import * as os from 'os' ; import * as path from 'path' ; import { VSCodeBlockchainOutputAdapter } from '../logging/VSCodeBlockchainOutputAdapter' ; import { LogType } from 'ibm-blockchain-platform-common' ; export async function exportSmartContractPackage ( packageTreeItem ? ) { const outputAdapter = VSCodeBlockchainOutputAdapter . instance ( ) ; outputAdapter . log ( LogType . INFO , undefined , 'exportSmartContractPackage' ) ; try { let packageToExport ; let packageName ; if ( packageTreeItem ) { packageName = `${ packageTreeItem . name }${ packageTreeItem . extension }` ; packageToExport = packageTreeItem . packageEntry ; } else { const chosenPackage = await UserInputUtil . showSmartContractPackagesQuickPickBox ( 'Choose the smart contract package that you want to export' , false ) as IBlockchainQuickPickItem < PackageRegistryEntry > ; if ( ! chosenPackage ) { return ; } packageToExport = chosenPackage . data ; packageName = chosenPackage . label ; } const defaultPath = path . join ( os . homedir ( ) , packageName ) ; const packageUri = await vscode . window . showSaveDialog ( { defaultUri : vscode . Uri . file ( defaultPath ) , saveLabel : 'Export' } ) ; if ( ! packageUri ) { return ; } await fs . copy ( packageToExport . path , packageUri . fsPath , { overwrite : true } ) ; outputAdapter . log ( LogType . SUCCESS , `Exported smart contract package ${ packageName } to ${ packageUri . fsPath }.` ) ; Reporter . instance ( ) . sendTelemetryEvent ( 'exportSmartContractPackageCommand' ) ; } catch ( error ) { outputAdapter . log ( LogType . ERROR , error . message , error . toString ( ) ) ; } }