forked from locize/locize-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.ps1
executable file
·104 lines (91 loc) · 2.76 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
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/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) {
$Response = Invoke-WebRequest 'https://github.com/locize/locize-cli/releases' -UseBasicParsing
if ($PSVersionTable.PSEdition -eq 'Core') {
$Response.Links |
Where-Object { $_.href -like "/locize/locize-cli/releases/download/*/locize-${OS}" } |
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:/locize/locize-cli/releases/download/*/locize-${OS}" } |
ForEach-Object { $_.href -replace 'about:', 'https://github.com' } |
Select-Object -First 1
}
} else {
"https://github.com/locize/locize-cli/releases/download/$Version/locize-${OS}"
}
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"
}
}