mirror of
https://github.com/danbulant/deno_install
synced 2026-05-19 04:08:42 +00:00
72 lines
2.2 KiB
PowerShell
72 lines
2.2 KiB
PowerShell
#!/usr/bin/env pwsh
|
|
# Copyright 2018 the Deno authors. All rights reserved. MIT license.
|
|
# TODO(everyone): Keep this script simple and easily auditable.
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
|
|
if ($args.Length -gt 0) {
|
|
$Version = $args.Get(0)
|
|
}
|
|
|
|
if ($PSVersionTable.PSEdition -ne 'Core') {
|
|
$IsWindows = $true
|
|
$IsMacOS = $false
|
|
}
|
|
|
|
$DenoInstall = $env:DENO_INSTALL
|
|
$BinDir = if ($DenoInstall) {
|
|
"$DenoInstall\bin"
|
|
} elseif ($IsWindows) {
|
|
"$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) {
|
|
$Response = Invoke-WebRequest 'https://github.com/denoland/deno/releases' -UseBasicParsing
|
|
if ($PSVersionTable.PSEdition -eq 'Core') {
|
|
$Response.Links |
|
|
Where-Object { $_.href -like "/denoland/deno/releases/download/*/deno-${Target}.zip" } |
|
|
ForEach-Object { 'https://github.com' + $_.href } |
|
|
Select-Object -First 1
|
|
} else {
|
|
$HTMLFile = New-Object -Com HTMLFile
|
|
if ($HTMLFile.IHTMLDocument2_write) {
|
|
$HTMLFile.IHTMLDocument2_write($Response.Content)
|
|
} else {
|
|
$ResponseBytes = [Text.Encoding]::Unicode.GetBytes($Response.Content)
|
|
$HTMLFile.write($ResponseBytes)
|
|
}
|
|
$HTMLFile.getElementsByTagName('a') |
|
|
Where-Object { $_.href -like "about:/denoland/deno/releases/download/*/deno-${Target}.zip" } |
|
|
ForEach-Object { $_.href -replace 'about:', 'https://github.com' } |
|
|
Select-Object -First 1
|
|
}
|
|
} else {
|
|
"https://github.com/denoland/deno/releases/download/$Version/deno-${Target}.zip"
|
|
}
|
|
|
|
if (!(Test-Path $BinDir)) {
|
|
New-Item $BinDir -ItemType Directory | Out-Null
|
|
}
|
|
|
|
Invoke-WebRequest $DenoUri -OutFile $DenoZip -UseBasicParsing
|
|
|
|
Expand-Archive $DenoZip -Destination $BinDir -Force
|
|
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"
|
|
}
|
|
Write-Output "Deno was installed successfully to $DenoExe"
|
|
Write-Output "Run 'deno --help' to get started"
|