diff --git a/README.md b/README.md index 00dda7f..dd137b1 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,14 @@ brew install protobuf # macOS cargo install deno ``` +## Install Globally + +**With PowerShell:** + +```powershell +$denoGlobalInstall; irm https://deno.land/install.ps1 | iex +``` + ## Install and Manage Multiple Versions **With [asdf](https://asdf-vm.com) and [asdf-deno](https://github.com/asdf-community/asdf-deno):** @@ -178,3 +186,4 @@ During the `install.sh` process, `unzip` or `7z` is used to extract the zip arch **How can this issue be fixed?** You can install unzip via `brew install unzip` on MacOS or `apt-get install unzip -y` on Linux. + diff --git a/install.ps1 b/install.ps1 index e0fbac5..d0e7191 100644 --- a/install.ps1 +++ b/install.ps1 @@ -4,16 +4,17 @@ $ErrorActionPreference = 'Stop' -if ($v) { - $Version = "v${v}" -} if ($Args.Length -eq 1) { - $Version = $Args.Get(0) + $Version = $Args[0] +} elseif ($v) { + $Version = "v${v}" } $DenoInstall = $env:DENO_INSTALL $BinDir = if ($DenoInstall) { "${DenoInstall}\bin" +} elseif (Test-Path variable:\denoGlobalInstall) { + "${Env:ProgramFiles}\deno\bin" } else { "${Home}\.deno\bin" } @@ -38,10 +39,15 @@ tar.exe xf $DenoZip -C $BinDir Remove-Item $DenoZip -$User = [System.EnvironmentVariableTarget]::User -$Path = [System.Environment]::GetEnvironmentVariable('Path', $User) +$EnvTarget = if (Test-Path variable:\denoGlobalInstall) { + [System.EnvironmentVariableTarget]::Machine +} else { + [System.EnvironmentVariableTarget]::User +} + +$Path = [System.Environment]::GetEnvironmentVariable('Path', $EnvTarget) if (!(";${Path};".ToLower() -like "*;${BinDir};*".ToLower())) { - [System.Environment]::SetEnvironmentVariable('Path', "${Path};${BinDir}", $User) + [System.Environment]::SetEnvironmentVariable('Path', "${Path};${BinDir}", $EnvTarget) $Env:Path += ";${BinDir}" }