Skip to content

Commit

Permalink
chore: misc powershell refactorings (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkTiedemann authored Aug 13, 2022
1 parent 1ce537f commit 281488a
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions install.ps1
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
#!/usr/bin/env pwsh
# Copyright 2018 the Deno authors. All rights reserved. MIT license.
# Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
# TODO(everyone): Keep this script simple and easily auditable.

$ErrorActionPreference = 'Stop'

if ($v) {
$Version = "v${v}"
}
if ($args.Length -eq 1) {
$Version = $args.Get(0)
if ($Args.Length -eq 1) {
$Version = $Args.Get(0)
}

$DenoInstall = $env:DENO_INSTALL
$BinDir = if ($DenoInstall) {
"$DenoInstall\bin"
"${DenoInstall}\bin"
} else {
"$Home\.deno\bin"
"${Home}\.deno\bin"
}

$DenoZip = "$BinDir\deno.zip"
$DenoExe = "$BinDir\deno.exe"
$Target = 'x86_64-pc-windows-msvc'

# GitHub requires TLS 1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

$DenoUri = if (!$Version) {
$DownloadUrl = if (!$Version) {
"https://github.com/denoland/deno/releases/latest/download/deno-${Target}.zip"
} else {
"https://github.com/denoland/deno/releases/download/${Version}/deno-${Target}.zip"
Expand All @@ -35,18 +32,18 @@ if (!(Test-Path $BinDir)) {
New-Item $BinDir -ItemType Directory | Out-Null
}

curl.exe -Lo $DenoZip $DenoUri
curl.exe -Lo $DenoZip $DownloadUrl

tar.exe xf $DenoZip -C $BinDir

Remove-Item $DenoZip

$User = [EnvironmentVariableTarget]::User
$Path = [Environment]::GetEnvironmentVariable('Path', $User)
if (!(";$Path;".ToLower() -like "*;$BinDir;*".ToLower())) {
[Environment]::SetEnvironmentVariable('Path', "$Path;$BinDir", $User)
$Env:Path += ";$BinDir"
$User = [System.EnvironmentVariableTarget]::User
$Path = [System.Environment]::GetEnvironmentVariable('Path', $User)
if (!(";${Path};".ToLower() -like "*;${BinDir};*".ToLower())) {
[System.Environment]::SetEnvironmentVariable('Path', "${Path};${BinDir}", $User)
$Env:Path += ";${BinDir}"
}

Write-Output "Deno was installed successfully to $DenoExe"
Write-Output "Deno was installed successfully to ${DenoExe}"
Write-Output "Run 'deno --help' to get started"

0 comments on commit 281488a

Please sign in to comment.