import * as vscode from 'vscode' ; import { Reporter } from '../util/Reporter' ; import * as path from 'path' ; import * as fs from 'fs-extra' ; import { FabricDebugConfigurationProvider } from './FabricDebugConfigurationProvider' ; import { ExtensionUtil } from '../util/ExtensionUtil' ; export class FabricNodeDebugConfigurationProvider extends FabricDebugConfigurationProvider { public async provideDebugConfigurations ( folder ) { const debugInfo = { type : 'fabric:node' , request : 'launch' , name : 'Debug Smart Contract' } ; const files = await fs . readdir ( folder . uri . fsPath ) ; if ( files . includes ( 'tsconfig.json' ) ) { debugInfo . preLaunchTask = 'tsc: build - tsconfig.json' ; debugInfo . outFiles = [ '${workspaceFolder}/dist/**/*.js' ] ; } return [ debugInfo ] ; } protected async getChaincodeNameAndVersion ( folder ) { return ExtensionUtil . getContractNameAndVersion ( folder ) ; } protected async resolveDebugConfigurationInner ( folder , config ) { config . type = 'node' ; if ( ! config . request ) { config . request = 'launch' ; } if ( ! config . program ) { if ( process . platform === 'win32' ) { config . program = path . join ( folder . uri . fsPath , 'node_modules' , 'fabric-shim' , 'cli' ) ; } else { config . program = path . join ( folder . uri . fsPath , 'node_modules' , '.bin' , 'fabric-chaincode-node' ) ; } } if ( ! config . cwd ) { config . cwd = folder . uri . fsPath ; } if ( ! config . args ) { config . args = [ ] ; } if ( ! config . args . includes ( 'start' ) ) { config . args . push ( 'start' ) ; } if ( ! config . args . includes ( '--peer.address' ) ) { const peerAddress = await this . getChaincodeAddress ( ) ; if ( ! peerAddress ) { return ; } config . args . push ( '--peer.address' , peerAddress ) ; } Reporter . instance ( ) . sendTelemetryEvent ( 'Smart Contract Debugged' , { language : 'Node' } ) ; return config ; } }