Last active
February 19, 2020 22:58
-
-
Save jeremygaither/ec992483ead0617d28fb62f3ac12ac35 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $nvmrcVersion = Get-Content .nvmrc | |
| Write-Output "Desired Node version: $nvmrcVersion" | |
| $nvmAvailable = (nvm list available) | |
| $candidateVersionLines = $nvmAvailable | Where-Object -FilterScript { | |
| $_ -like ('* ' + ($nvmrcVersion) + '.*') | |
| } | |
| $candidateVersions = @() | |
| foreach ($line in $candidateVersionLines) { | |
| $versions = $line.Split('|').Trim() | |
| foreach ($version in $versions) { | |
| if ([string]::IsNullOrWhiteSpace($version)) { | |
| continue | |
| } | |
| Write-Output ("testing: $version") | |
| if ($version -like ($nvmrcVersion + '.*')) { | |
| Write-Output ("found: $version") | |
| $candidateVersions += $version | |
| } | |
| } | |
| } | |
| Write-Output "candidateVersions: $candidateVersions" | |
| foreach ($version in $candidateVersions) { | |
| if ((nvm use $version) -like '*not installed*') { | |
| nvm install $version | |
| nvm use $version | |
| } | |
| } | |
| $nodeVersion = (node --version) | |
| if ($nodeVersion -eq $candidateVersions[0]) { | |
| Write-Output "node version good: $nodeVersion" | |
| } else { | |
| Write-Output "Waiting for symlink to update..." | |
| Start-Sleep 5 | |
| $nodeVersion = (node --version) | |
| if ($nodeVersion -ne $candidateVersions[0]) { | |
| Write-Output "There was a problem activating Node $candidateVersions[0]" | |
| exit 1 | |
| } else { | |
| Write-Output "Desired Node version ""$candidateVersions[0]"" active: $nodeVersion" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment