diff --git a/install.ps1 b/install.ps1 index 5ba8af5..e6bfeb7 100644 --- a/install.ps1 +++ b/install.ps1 @@ -8,7 +8,7 @@ if ($args.Length -gt 0) { $Version = $args.Get(0) } -if ($PSVersionTable.PSVersion.Major -lt 6) { +if ($PSVersionTable.PSEdition -ne 'Core') { $IsWindows = $true $IsMacOS = $false } @@ -47,27 +47,28 @@ $OS = if ($IsWindows) { } } -if (!$Version) { - if ($PSVersionTable.PSVersion.Major -lt 6) { - $Response = Invoke-WebRequest 'https://github.com/denoland/deno/releases' +$DenoUri = if (!$Version) { + $Response = Invoke-WebRequest 'https://github.com/denoland/deno/releases' + if ($PSVersionTable.PSEdition -eq 'Core') { + $Response.Links | + Where-Object { $_.href -like "/denoland/deno/releases/download/*/deno_${OS}_x64.$Zip" } | + 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 { - $HTMLFile.write([System.Text.Encoding]::Unicode.GetBytes($Response.Content)) + $ResponseBytes = [Text.Encoding]::Unicode.GetBytes($Response.Content) + $HTMLFile.write($ResponseBytes) } - $DenoUri = $HTMLFile.getElementsByTagName('a') | + $HTMLFile.getElementsByTagName('a') | Where-Object { $_.href -like "about:/denoland/deno/releases/download/*/deno_${OS}_x64.$Zip" } | ForEach-Object { $_.href -replace 'about:', 'https://github.com' } | Select-Object -First 1 - } else { - $DenoUri = (Invoke-WebRequest 'https://github.com/denoland/deno/releases').Links | - Where-Object { $_.href -like "/denoland/deno/releases/download/*/deno_${OS}_x64.$Zip" } | - ForEach-Object { 'https://github.com' + $_.href } | - Select-Object -First 1 } } else { - $DenoUri = "https://github.com/denoland/deno/releases/download/$Version/deno_${OS}_x64.$Zip" + "https://github.com/denoland/deno/releases/download/$Version/deno_${OS}_x64.$Zip" } if (!(Test-Path $BinDir)) { @@ -100,6 +101,6 @@ if ($IsWindows) { } else { Write-Output "Manually add the directory to your `$HOME/.bash_profile (or similar)" Write-Output " export PATH=`"${BinDir}:`$PATH`"" - Write-Output "Run '~/.deno/bin/deno --help' to get started" + Write-Output "Run '$DenoExe --help' to get started" } } diff --git a/install.sh b/install.sh index a780de0..ad92097 100755 --- a/install.sh +++ b/install.sh @@ -32,9 +32,9 @@ chmod +x "$exe" echo "Deno was installed successfully to $exe" if command -v deno >/dev/null; then - echo "Run 'deno --help' to get started." + echo "Run 'deno --help' to get started" else echo "Manually add the directory to your \$HOME/.bash_profile (or similar)" echo " export PATH=\"$bin_dir:\$PATH\"" - echo "Run '$exe --help' to get started." + echo "Run '$exe --help' to get started" fi diff --git a/install_test.ps1 b/install_test.ps1 index 053ba3c..d8276ae 100644 --- a/install_test.ps1 +++ b/install_test.ps1 @@ -2,6 +2,10 @@ $ErrorActionPreference = 'Stop' +if ($PSVersionTable.PSEdition -ne 'Core') { + $IsWindows = $true +} + if (!(Get-PSRepository)) { Register-PSRepository -Default } @@ -10,32 +14,32 @@ if (!(Get-Module PSScriptAnalyzer -ListAvailable)) { Install-Module PSScriptAnalyzer -Scope CurrentUser -Force } +# Lint. Invoke-ScriptAnalyzer *.ps1 -EnableExit -Exclude PSAvoidAssignmentToAutomaticVariable -if ($PSVersionTable.PSVersion.Major -lt 6) { - $IsWindows = $true +$BinDir = if ($IsWindows) { + "$Home\.deno\bin" +} else { + "$Home/.deno/bin" } +# Test we can install a specific version. +Remove-Item $BinDir -Recurse -Force -ErrorAction SilentlyContinue .\install.ps1 v0.2.0 $DenoVersion = if ($IsWindows) { deno --version } else { ~/.deno/bin/deno --version } -if (!($DenoVersion[0] -eq 'deno: 0.2.0')) { +if (!($DenoVersion -like '*0.2.0*')) { throw $DenoVersion -} else { - Write-Output $DenoVersion } +# Test we can install the latest version. +Remove-Item $BinDir -Recurse -Force -ErrorAction SilentlyContinue .\install.ps1 -$DenoVersion = if ($IsWindows) { +if ($IsWindows) { deno --version } else { ~/.deno/bin/deno --version } -if (!($DenoVersion[0] -match 'deno: \d+\.\d+\.\d+')) { - throw $DenoVersion -} else { - Write-Output $DenoVersion -} diff --git a/install_test.sh b/install_test.sh index dd75325..77797f5 100755 --- a/install_test.sh +++ b/install_test.sh @@ -1,6 +1,6 @@ #!/bin/sh -set -ev +set -e # Lint. shellcheck -s sh ./*.sh @@ -9,9 +9,9 @@ shfmt -d . # Test we can install a specific version. rm -rf ~/.deno ./install.sh v0.2.0 -~/.deno/bin/deno -v | grep -e 0.2.0 +~/.deno/bin/deno -v | grep 0.2.0 -# Test we can get the latest version. +# Test we can install the latest version. rm -rf ~/.deno sh ./install.sh ~/.deno/bin/deno -v