-
Notifications
You must be signed in to change notification settings - Fork 24
/
install.ps1
65 lines (51 loc) · 1.99 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
#!/usr/bin/env pwsh
$ErrorActionPreference = 'Stop'
# Check if Rush is already installed; if it is, use the old
# path for storing rush.exe
if (Get-Command "rush.exe" -ErrorAction SilentlyContinue) {
$BinDir = (Get-Item (Get-Command "rush.exe").Path).DirectoryName
}
else {
$BinDir = "$Home/.rush/bin"
if (!(Test-Path $BinDir)) {
New-Item $BinDir -ItemType Directory | Out-Null
}
}
$ZipUrl = "https://github.com/shreyashsaitwal/rush-cli/releases/latest/download/rush-win.zip"
# GitHub requires TLS 1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# Download rush-win.zip
Invoke-WebRequest -OutFile "$BinDir/rush-win.zip" $ZipUrl -UseBasicParsing
# Extract it
if (Get-Command Expand-Archive -ErrorAction SilentlyContinue) {
Expand-Archive "$BinDir/rush-win.zip" -DestinationPath "$BinDir" -Force
}
else {
Add-Type -AssemblyName System.IO.Compression.FileSystem
[IO.Compression.ZipFile]::ExtractToDirectory("$BinDir/rush-win.zip", $BinDir)
}
Remove-Item "$BinDir/rush-win.zip"
$AppDataDir = "$env:APPDATA/rush"
# Delete the AppDataDir if it already exists
if (Test-Path $AppDataDir) {
Remove-Item -Recurse $AppDataDir
}
# Then (re-)create it
New-Item -ItemType Directory $AppDataDir | Out-Null
# Delete old exes
Remove-Item "$BinDir/rush.exe" -ErrorAction SilentlyContinue
Remove-Item "$BinDir/swap.exe" -ErrorAction SilentlyContinue
# Move files
Move-Item "$BinDir/exe/win/*.exe" -Destination "$BinDir" -Force
Remove-Item -Recurse "$BinDir/exe"
# Pipe the output of [Get-ChildItem] to [Move-Item]
Get-ChildItem "$BinDir" -Directory | Move-Item -Destination "$AppDataDir" -Force
# Update PATH
$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 "Success! Installed Rush at $BinDir\rush.exe!"
Write-Output "Run 'rush --help' to get started.`n"