import * as vscode from 'vscode' ; const fs = require ( 'fs' ) ; const translate = require ( '@vitalets/google-translate-api' ) ; const CheckFileType = require ( './internal/checkFileType' ) ; const GetFileContent = require ( './internal/getFileContent' ) ; const WriteFileContent = require ( './internal/writeFileContent' ) ; const Translate = require ( './internal/translate' ) ; export function activate ( context ) { let disposable = vscode . commands . registerCommand ( 'extension.md2urdu' , async ( ) => { const fileTypeResult = new CheckFileType ( vscode ) ; const { checkFileType } = fileTypeResult ; const { isMDFile , filePath } = await checkFileType ( ) ; if ( isMDFile ) { vscode . window . showInformationMessage ( 'Converting MD File To Urdu' ) ; const getFileContentResult = new GetFileContent ( vscode , fs ) ; const { getFileContent } = getFileContentResult ; const { fileData , selectedTexted } = await getFileContent ( filePath ) ; if ( fileData && ! selectedTexted ) { const translateResult = new Translate ( translate , vscode ) ; const { translation } = translateResult ; const fileDataInUrdu = await translation ( fileData ) ; if ( fileDataInUrdu ) { const writeFileContentResult = new WriteFileContent ( vscode , fs ) ; const { writeFileContent } = writeFileContentResult ; const writeData = await writeFileContent ( filePath , fileDataInUrdu ) ; if ( writeData ) { vscode . window . showInformationMessage ( 'Successfully Converted MD File To Urdu' ) ; } else { vscode . window . showInformationMessage ( 'Unable To Write Urdu Data In MD File' ) ; } } else { vscode . window . showInformationMessage ( 'Unable To Translate MD File Data' ) ; } } else if ( fileData && selectedTexted ) { const translateResult = new Translate ( translate , vscode ) ; const { translation } = translateResult ; const selectedTextInUrdu = await translation ( selectedTexted ) ; if ( selectedTextInUrdu ) { const fileDataWithSelectedText = fileData . replace ( selectedTexted , selectedTextInUrdu ) ; const writeFileContentResult = new WriteFileContent ( vscode , fs ) ; const { writeFileContent } = writeFileContentResult ; const writeData = await writeFileContent ( filePath , fileDataWithSelectedText ) ; let showInformationMessage = '' ; if ( writeData ) { showInformationMessage = 'Successfully Converted MD File To Urdu' ; } else { showInformationMessage = 'Unable To Write Urdu Data In MD File' ; } vscode . window . showInformationMessage ( showInformationMessage ) ; } else { vscode . window . showInformationMessage ( 'Unable To Translate MD File Data' ) ; } } else { vscode . window . showInformationMessage ( 'Unable To Get MD File Data' ) ; } } else { vscode . window . showInformationMessage ( 'Current File Is Not MD File' ) ; } } ) ; context . subscriptions . push ( disposable ) ; } export function deactivate ( ) { vscode . window . showInformationMessage ( 'md2urdu is deactivated' ) ; }