1+ # ---------------------------------------------------------------------------------------------
2+ # Copyright (c) Microsoft Corporation. All rights reserved.
3+ # Licensed under the MIT License. See License in the project root for license information.
4+ # ---------------------------------------------------------------------------------------------
5+
6+ New-Item - ItemType Directory - Force - Path .\devproxy - ErrorAction Stop | Out-Null
7+ Set-Location .\devproxy | Out-Null
8+
9+ # Get the full path of the current directory
10+ $full_path = Resolve-Path .
11+
12+ # Get the latest Dev Proxy version
13+ Write-Host " Getting latest Dev Proxy version..."
14+ $response = Invoke-RestMethod - Uri " https://api.github.com/repos/microsoft/dev-proxy/releases/latest" - ErrorAction Stop
15+ $version = $response.tag_name
16+ Write-Host " Latest version is $version "
17+
18+ # Download Dev Proxy
19+ Write-Host " Downloading Dev Proxy $version ..."
20+ $base_url = " https://github.com/microsoft/dev-proxy/releases/download/$version /dev-proxy"
21+
22+ # Check system architecture
23+ $os = $PSVersionTable.OS
24+ $arch = [System.Runtime.InteropServices.RuntimeInformation ]::OSArchitecture
25+
26+ if ($os -match " Windows" ) {
27+ if ($arch -eq " X64" ) {
28+ $url = " $base_url -win-x64-$version .zip"
29+ } elseif ($arch -eq " X86" ) {
30+ $url = " $base_url -win-x86-$version .zip"
31+ } else {
32+ Write-Host " Unsupported architecture $arch . Aborting"
33+ exit 1
34+ }
35+ } elseif ($os -match " Linux" ) {
36+ if ($arch -eq " X64" ) {
37+ $url = " $base_url -linux-x64-$version .zip"
38+ } else {
39+ Write-Host " Unsupported architecture $arch . Aborting"
40+ exit 1
41+ }
42+ } elseif ($os -match " Darwin" ) {
43+ if ($arch -eq " X64" ) {
44+ $url = " $base_url -osx-x64-$version .zip"
45+ } else {
46+ Write-Host " Unsupported architecture $arch . Aborting"
47+ exit 1
48+ }
49+ } else {
50+ Write-Host " Unsupported OS $os . Aborting"
51+ exit 1
52+ }
53+
54+ Invoke-WebRequest - Uri $url - OutFile devproxy.zip - ErrorAction Stop
55+ Add-Type - AssemblyName System.IO.Compression.FileSystem
56+ Expand-Archive - Path devproxy.zip - DestinationPath . - Force - ErrorAction Stop
57+ Remove-Item devproxy.zip
58+
59+ if (! (Test-Path $PROFILE )) {
60+ New-Item - ItemType File - Force - Path $PROFILE
61+ }
62+
63+ if (! (Select-String - Path $PROFILE - Pattern " devproxy" )) {
64+ Add-Content - Path $PROFILE - Value " $ ( [Environment ]::NewLine) `$ env:PATH += `" $ ( [IO.Path ]::PathSeparator) $full_path `" "
65+ }
66+
67+ Write-Host " Dev Proxy $version installed!"
68+ Write-Host
69+ Write-Host " To get started, run:"
70+ Write-Host " . $PROFILE "
71+ Write-Host " devproxy --help"
0 commit comments