2021-09-17 06:44:13 +08:00
|
|
|
/* eslint-disable require-atomic-updates */
|
2021-09-18 21:13:23 +08:00
|
|
|
import execa from "execa"
|
2021-09-17 04:08:54 +08:00
|
|
|
import { existsSync } from "fs"
|
2021-09-17 06:44:13 +08:00
|
|
|
import { dirname } from "path"
|
2021-09-15 05:01:08 +08:00
|
|
|
import which from "which"
|
2021-09-17 02:47:12 +08:00
|
|
|
import { InstallationInfo } from "../utils/setup/setupBin"
|
2021-09-15 05:01:08 +08:00
|
|
|
|
2021-09-17 02:47:12 +08:00
|
|
|
let binDir: string | undefined
|
|
|
|
|
2021-09-18 02:44:24 +08:00
|
|
|
export function setupChocolatey(
|
2021-09-17 02:47:12 +08:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
_version: string,
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
_setupCppDir: string,
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
_arch: string
|
2021-09-18 02:44:24 +08:00
|
|
|
): InstallationInfo | undefined {
|
2021-09-15 13:37:37 +08:00
|
|
|
if (process.platform !== "win32") {
|
2021-09-17 02:47:12 +08:00
|
|
|
return undefined
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof binDir === "string") {
|
|
|
|
return { binDir }
|
2021-09-15 13:37:37 +08:00
|
|
|
}
|
|
|
|
|
2021-09-17 02:47:12 +08:00
|
|
|
const maybeBinDir = which.sync("choco", { nothrow: true })
|
|
|
|
if (maybeBinDir !== null) {
|
2021-09-17 18:15:52 +08:00
|
|
|
binDir = dirname(maybeBinDir)
|
2021-09-17 02:47:12 +08:00
|
|
|
return { binDir }
|
2021-09-15 05:01:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// https://docs.chocolatey.org/en-us/choco/setup#install-with-cmd.exe
|
2021-09-18 21:13:23 +08:00
|
|
|
execa.commandSync(
|
|
|
|
`@"%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "[System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\\chocolatey\\bin"`
|
|
|
|
)
|
2021-09-17 02:47:12 +08:00
|
|
|
|
2021-09-17 06:44:13 +08:00
|
|
|
const maybeChoco = which.sync("choco", { nothrow: true })
|
|
|
|
if (maybeChoco !== null) {
|
|
|
|
binDir = dirname(maybeChoco)
|
|
|
|
} else {
|
2021-09-17 07:26:57 +08:00
|
|
|
binDir = "C:/ProgramData/Chocolatey/bin/"
|
2021-09-17 06:44:13 +08:00
|
|
|
}
|
2021-09-17 04:08:54 +08:00
|
|
|
|
|
|
|
if (existsSync(binDir)) {
|
|
|
|
return { binDir }
|
|
|
|
}
|
|
|
|
return undefined
|
2021-09-15 05:01:08 +08:00
|
|
|
}
|