Skip to content

Commit

Permalink
Move goOs & goArch logic into functions
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Jan 5, 2021
1 parent 2a153e3 commit 61d1a85
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions src/languageServerInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export class LanguageServerInstaller {
const destination = `${installDir}/terraform-ls_v${release.version}.zip`;
fs.mkdirSync(installDir, { recursive: true }); // create install directory if missing

let os = this.goOs();
let arch = this.goArch();
let os = goOs();
let arch = goArch();
const build = release.getBuild(os, arch);
if (!build) {
throw new Error(`Install error: no matching terraform-ls binary for ${os}/${arch}`);
Expand All @@ -78,34 +78,6 @@ export class LanguageServerInstaller {
});
}

goOs(): string {
let platform = process.platform.toString();
if (platform === 'win32') {
return 'windows';
}
if (platform === 'sunos') {
return 'solaris';
}
return platform;
}

goArch(): string {
let arch = process.arch;

if (arch === 'ia32') {
return '386';
}
if (arch === 'x64') {
return 'amd64';
}
if (arch === 'arm64' && process.platform.toString() === 'darwin') {
// On Apple Silicon, install the amd64 version and rely on Rosetta2
// until a native build is available.
return 'amd64';
}
return arch;
}

removeOldBinary(directory: string, goOs: string): void {
if (goOs === "windows") {
fs.unlinkSync(`${directory}/terraform-ls.exe`);
Expand All @@ -118,3 +90,31 @@ export class LanguageServerInstaller {
return del(`${directory}/terraform-ls*.zip`, { force: true });
}
}

function goOs(): string {
let platform = process.platform.toString();
if (platform === 'win32') {
return 'windows';
}
if (platform === 'sunos') {
return 'solaris';
}
return platform;
}

function goArch(): string {
let arch = process.arch;

if (arch === 'ia32') {
return '386';
}
if (arch === 'x64') {
return 'amd64';
}
if (arch === 'arm64' && process.platform.toString() === 'darwin') {
// On Apple Silicon, install the amd64 version and rely on Rosetta2
// until a native build is available.
return 'amd64';
}
return arch;
}

0 comments on commit 61d1a85

Please sign in to comment.