-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
install.ps1
executable file
·91 lines (77 loc) · 2.07 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env pwsh
$ErrorActionPreference = 'Stop'
if ($args.Length -gt 0) {
$Version = $args.Get(0)
}
if ($PSVersionTable.PSEdition -ne 'Core') {
$IsWindows = $true
$IsMacOS = $false
}
$BinDir = if ($IsWindows) {
"$Home\.locize-cli\bin"
} else {
"$Home/.locize-cli/bin"
}
$Zip = if ($IsWindows) {
'zip'
} else {
'gz'
}
$LocizeExe = if ($IsWindows) {
"$BinDir\locize.exe"
} else {
"$BinDir/locize"
}
$OS = if ($IsWindows) {
'win.exe'
} else {
if ($IsMacOS) {
'macos'
} else {
'linux'
}
}
$FILENAME = if ($IsWindows) {
'locize.exe'
} else {
'locize'
}
# GitHub requires TLS 1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$DenoUri = if (!$Version) {
"https://github.com/locize/locize-cli/releases/latest/download/locize-${OS}"
} else {
"https://github.com/locize/locize-cli/releases/download/${Version}/locize-${OS}"
}
if (!$DenoUri) {
Write-Output "failed to find a release on github"
Exit 1
}
if (!(Test-Path $BinDir)) {
New-Item $BinDir -ItemType Directory | Out-Null
}
if ($IsWindows) {
Invoke-WebRequest $DenoUri -OutFile "$BinDir\$FILENAME" -UseBasicParsing
} else {
Invoke-WebRequest $DenoUri -OutFile "$BinDir/$FILENAME" -UseBasicParsing
}
if ($IsWindows) {
$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 "locize-cli (locize) was installed successfully to $LocizeExe"
Write-Output "Run 'locize --help' to get started"
} else {
chmod +x "$BinDir/locize"
Write-Output "locize-cli (locize) was installed successfully to $LocizeExe"
if (Get-Command locize -ErrorAction SilentlyContinue) {
Write-Output "Run 'locize --help' to get started"
} else {
Write-Output "Manually add the directory to your `$HOME/.bash_profile (or similar)"
Write-Output " export PATH=`"${BinDir}:`$PATH`""
Write-Output "Run '$LocizeExe --help' to get started"
}
}