This repository has been archived by the owner on Sep 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.ps1
76 lines (64 loc) 路 2.32 KB
/
install.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env pwsh
$ErrorActionPreference = 'Stop'
if ($v) {
$Version = "${v}"
}
if ($args.Length -eq 1) {
$Version = $args.Get(0)
}
$DenoInstall = $env:DENO_INSTALL
$BinDir = if ($DenoInstall) {
"$DenoInstall\bin"
} else {
"$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/maximousblk/deno_nightly/releases' -UseBasicParsing
if ($PSVersionTable.PSEdition -eq 'Core') {
$Response.Links |
Where-Object { $_.href -like "/maximousblk/deno_nightly/releases/download/*/deno-nightly-${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:/maximousblk/deno_nightly/releases/download/*/deno-nightly-${Target}.zip" } |
ForEach-Object { $_.href -replace 'about:', 'https://github.com' } |
Select-Object -First 1
}
} else {
"https://github.com/maximousblk/deno_nightly/releases/download/${Version}/deno-nightly-${Target}.zip"
}
if (!(Test-Path $BinDir)) {
New-Item $BinDir -ItemType Directory | Out-Null
}
Invoke-WebRequest $DenoUri -OutFile $DenoZip -UseBasicParsing
if (Get-Command Expand-Archive -ErrorAction SilentlyContinue) {
Expand-Archive $DenoZip -Destination $BinDir -Force
} else {
if (Test-Path $DenoExe) {
Remove-Item $DenoExe
}
Add-Type -AssemblyName System.IO.Compression.FileSystem
[IO.Compression.ZipFile]::ExtractToDirectory($DenoZip, $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"
}
Write-Output "Deno (Nightly) was installed successfully to $DenoExe"
Write-Output "Run 'deno --help' to get started"