'use strict' ; import * as chai from 'chai' ; import * as sinonChai from 'sinon-chai' ; import * as chaiAsPromised from 'chai-as-promised' ; import * as fs from 'fs-extra' ; import * as path from 'path' ; import { SampleView } from '../../extension/webview/SampleView' ; import { CommandUtil } from '../../extension/util/CommandUtil' ; import { VSCodeBlockchainOutputAdapter } from '../../extension/logging/VSCodeBlockchainOutputAdapter' ; import { FileConfigurations } from 'ibm-blockchain-platform-common' ; chai . use ( sinonChai ) ; chai . use ( chaiAsPromised ) ; module . exports = function ( ) : any { /**
     * Given
     */ this . Given ( /I have cloned the repository '(.*?)' and I have opened the '(.*?)' '(.*?)' (contract|application) called '(.*?)' with namespace '(.*?)'/ , this . timeout , async ( repositoryName , language , sampleName , _contractApplication , contractName , namespace ) => { const tmpRepo = path . join ( this . cucumberDir , 'tmp' , FileConfigurations . REPOSITORIES ) ; const pathToCheck = path . join ( tmpRepo , repositoryName ) ; const exists = await fs . pathExists ( pathToCheck ) ; let webview ; if ( ! exists ) { await fs . ensureDir ( pathToCheck ) ; webview = await this . sampleHelper . cloneSample ( repositoryName , namespace ) ; } else { webview = new SampleView ( null , repositoryName , namespace ) ; } await this . sampleHelper . openContract ( webview , namespace . toLowerCase ( ) , language . toLowerCase ( ) , contractName ) ; this . contractDirectory = path . join ( pathToCheck , 'chaincode' , namespace . toLowerCase ( ) , language . toLowerCase ( ) ) ; if ( language === 'JavaScript' ) { const fileContents = await fs . readJson ( path . join ( pathToCheck , 'chaincode' , namespace . toLowerCase ( ) , language . toLowerCase ( ) , 'package.json' ) ) ; fileContents . name = sampleName . toLowerCase ( ) ; await fs . writeJson ( path . join ( pathToCheck , 'chaincode' , namespace . toLowerCase ( ) , language . toLowerCase ( ) , 'package.json' ) , fileContents ) ; } else if ( language === 'TypeScript' ) { const fileContents = await fs . readJson ( path . join ( pathToCheck , 'chaincode' , namespace . toLowerCase ( ) , language . toLowerCase ( ) , 'package.json' ) ) ; fileContents . name = sampleName . toLowerCase ( ) ; await fs . writeJson ( path . join ( pathToCheck , 'chaincode' , namespace . toLowerCase ( ) , language . toLowerCase ( ) , 'package.json' ) , fileContents ) ; const sampleDirectory = path . join ( pathToCheck , 'chaincode' , namespace . toLowerCase ( ) , language . toLowerCase ( ) ) ; await CommandUtil . sendCommandWithOutput ( 'npm' , [ 'install' ] , sampleDirectory , undefined , VSCodeBlockchainOutputAdapter . instance ( ) , false ) ; } else if ( language === 'Go' ) { const srcFolder = path . join ( pathToCheck , 'chaincode' , namespace . toLowerCase ( ) , 'src' ) ; await fs . mkdir ( srcFolder ) ; const oldPath = path . join ( pathToCheck , 'chaincode' , namespace . toLowerCase ( ) , language . toLowerCase ( ) ) ; const newPath = path . join ( pathToCheck , 'chaincode' , namespace . toLowerCase ( ) , 'src' , sampleName . toLowerCase ( ) ) ; await fs . rename ( oldPath , newPath ) ; this . contractDirectory = path . join ( pathToCheck , 'chaincode' , namespace . toLowerCase ( ) , 'src' , sampleName . toLowerCase ( ) ) ; process . env . GOPATH = path . join ( pathToCheck , 'chaincode' , namespace . toLowerCase ( ) ) ; } this . contractDefinitionName = sampleName . toLowerCase ( ) ; this . namespace = namespace ; this . contractDefinitionVersion = '1.0.0' ; this . contractLanguage = language ; } ) ; } ;