import { Release } from '@hashicorp/js-releases' ; import * as path from 'path' ; import * as vscode from 'vscode' ; import TelemetryReporter from 'vscode-extension-telemetry' ; import { pathExists } from './detector' ; export async function installTerraformLS ( installPath , release , extensionVersion , vscodeVersion , reporter ) { reporter . sendTelemetryEvent ( 'installingLs' , { terraformLsVersion : release . version } ) ; const zipfile = path . resolve ( installPath , `terraform-ls_v${ release . version }.zip` ) ; const userAgent = `Terraform-VSCode/${ extensionVersion } VSCode/${ vscodeVersion }` ; const os = getPlatform ( ) ; const arch = getArch ( ) ; const build = release . getBuild ( os , arch ) ; if ( ! build ) { throw new Error ( `Install error: no matching terraform-ls binary for ${ os }/${ arch }` ) ; } if ( ( await pathExists ( installPath ) ) === false ) { await vscode . workspace . fs . createDirectory ( vscode . Uri . file ( installPath ) ) ; } return vscode . window . withProgress ( { cancellable : false , location : vscode . ProgressLocation . Window , title : 'Installing terraform-ls' , } , async ( progress ) => { progress . report ( { increment : 30 } ) ; await release . download ( build . url , zipfile , userAgent ) ; progress . report ( { increment : 30 } ) ; await release . verify ( zipfile , build . filename ) ; progress . report ( { increment : 20 } ) ; await release . unpack ( installPath , zipfile ) ; progress . report ( { increment : 10 } ) ; return vscode . workspace . fs . delete ( vscode . Uri . file ( zipfile ) ) ; } ) ; } function getPlatform ( ) { const platform = process . platform . toString ( ) ; if ( platform === 'win32' ) { return 'windows' ; } if ( platform === 'sunos' ) { return 'solaris' ; } return platform ; } function getArch ( ) { const arch = process . arch ; if ( arch === 'ia32' ) { return '386' ; } if ( arch === 'x64' ) { return 'amd64' ; } return arch ; }