Skip to content

Commit ab48d6e

Browse files
XhmikosRFeodorFitsner
authored andcommitted
Update nodejs-utils.psm1. (#2685)
Switch to https and minor formatting tweaks.
1 parent 457de26 commit ab48d6e

File tree

1 file changed

+28
-30
lines changed

1 file changed

+28
-30
lines changed

scripts/nodejs-utils.psm1

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ function Get-Version([string]$str) {
88
number = 0
99
}
1010

11-
if($versionDigits.Length -gt 0) {
11+
if ($versionDigits.Length -gt 0) {
1212
$version.major = [int]$versionDigits[0]
1313
}
14-
if($versionDigits.Length -gt 1) {
14+
if ($versionDigits.Length -gt 1) {
1515
$version.minor = [int]$versionDigits[1]
1616
}
17-
if($versionDigits.Length -gt 2) {
17+
if ($versionDigits.Length -gt 2) {
1818
$version.build = [int]$versionDigits[2]
1919
}
20-
if($versionDigits.Length -gt 3) {
20+
if ($versionDigits.Length -gt 3) {
2121
$version.revision = [int]$versionDigits[3]
2222
}
2323

24-
for($i = 0; $i -lt $versionDigits.Length; $i++) {
24+
for ($i = 0; $i -lt $versionDigits.Length; $i++) {
2525
$version.number += [long]$versionDigits[$i] -shl 16 * (3 - $i)
2626
}
2727

@@ -31,41 +31,41 @@ function Get-Version([string]$str) {
3131
function Get-NodeJsInstallPackage {
3232
param
3333
(
34-
[Parameter(Mandatory=$true)]
34+
[Parameter(Mandatory=$true)]
3535
[string]$version,
3636

3737
[Parameter(Mandatory=$false)]
3838
[string]$bitness = 'x86'
3939
)
4040

4141
$v = Get-Version $version
42-
42+
4343
if ($v.Major -ge 4 -and $bitness -eq 'x86') {
44-
$packageUrl = "http://nodejs.org/dist/v$version/node-v$version-x86.msi"
44+
$packageUrl = "https://nodejs.org/dist/v$version/node-v$version-x86.msi"
4545
} elseif ($v.Major -ge 4 -and $bitness -eq 'x64') {
46-
$packageUrl = "http://nodejs.org/dist/v$version/node-v$version-x64.msi"
46+
$packageUrl = "https://nodejs.org/dist/v$version/node-v$version-x64.msi"
4747
} elseif ($v.Major -eq 0 -and $bitness -eq 'x86') {
48-
$packageUrl = "http://nodejs.org/dist/v$version/node-v$version-x86.msi"
48+
$packageUrl = "https://nodejs.org/dist/v$version/node-v$version-x86.msi"
4949
} elseif ($v.Major -ge 1 -and $bitness -eq 'x86') {
5050
$packageUrl = "https://iojs.org/dist/v$version/iojs-v$version-x86.msi"
5151
} elseif ($v.Major -eq 0) {
52-
$packageUrl = "http://nodejs.org/dist/v$version/x64/node-v$version-x64.msi"
52+
$packageUrl = "https://nodejs.org/dist/v$version/x64/node-v$version-x64.msi"
5353
} elseif ($v.Major -ge 1) {
54-
$packageUrl = "https://iojs.org/dist/v$version/iojs-v$version-x64.msi"
54+
$packageUrl = "httpss://iojs.org/dist/v$version/iojs-v$version-x64.msi"
5555
}
56-
56+
5757
$packageFileName = Join-Path ([IO.Path]::GetTempPath()) $packageUrl.Substring($packageUrl.LastIndexOf('/') + 1)
5858
(New-Object Net.WebClient).DownloadFile($packageUrl, $packageFileName)
5959
return $packageFileName
6060
}
6161

6262
function Get-InstalledNodeJsVersion() {
6363
$nodePath = (cmd /c where node.exe)
64-
if(-not $nodePath) {
65-
$nodePath = (cmd /c where iojs.exe)
64+
if (-not $nodePath) {
65+
$nodePath = (cmd /c where iojs.exe)
6666
}
6767

68-
if($nodePath) {
68+
if ($nodePath) {
6969
$bitness = 'x64'
7070
if ($nodePath.indexOf('(x86)') -ne -1) {
7171
$bitness = 'x86'
@@ -82,7 +82,7 @@ function Get-InstalledNodeJsVersion() {
8282
function Remove-NodeJsInstallation {
8383
param
8484
(
85-
[Parameter(Mandatory=$true)]
85+
[Parameter(Mandatory=$true)]
8686
[string]$version,
8787

8888
[Parameter(Mandatory=$true)]
@@ -97,7 +97,7 @@ function Remove-NodeJsInstallation {
9797
function Start-NodeJsInstallation {
9898
param
9999
(
100-
[Parameter(Mandatory=$true)]
100+
[Parameter(Mandatory=$true)]
101101
[string]$version,
102102

103103
[Parameter(Mandatory=$false)]
@@ -108,7 +108,7 @@ function Start-NodeJsInstallation {
108108
if ($v.Major -eq 0 -or $v.Major -ge 4) {
109109
$features = 'NodeRuntime,NodePerfCtrSupport,NodeEtwSupport,npm'
110110
} else {
111-
$features = 'NodeRuntime,NodeAlias,NodePerfCtrSupport,NodeEtwSupport,npm'
111+
$features = 'NodeRuntime,NodeAlias,NodePerfCtrSupport,NodeEtwSupport,npm'
112112
}
113113

114114
Write-Host "Installing $(ProductName($version)) v$version ($bitness)..."
@@ -119,7 +119,7 @@ function Start-NodeJsInstallation {
119119
function Update-NodeJsInstallation {
120120
param
121121
(
122-
[Parameter(Mandatory=$true)]
122+
[Parameter(Mandatory=$true)]
123123
[string]$version,
124124

125125
[Parameter(Mandatory=$false)]
@@ -128,10 +128,9 @@ function Update-NodeJsInstallation {
128128

129129
$installedVersion = Get-InstalledNodeJsVersion
130130

131-
if($installedVersion -eq $null -or $installedVersion.version -ne $version -or $installedVersion.bitness -ne $bitness)
132-
{
131+
if ($installedVersion -eq $null -or $installedVersion.version -ne $version -or $installedVersion.bitness -ne $bitness) {
133132
Write-Host "Updating $(ProductName($version)) v$version ($bitness)"
134-
if($installedVersion) {
133+
if ($installedVersion) {
135134
Remove-NodeJsInstallation $installedVersion.version $installedVersion.bitness
136135
}
137136
Start-NodeJsInstallation $version $bitness
@@ -142,25 +141,24 @@ function Get-NodeJsLatestBuild([string]$majorVersion) {
142141
# fetch available distros
143142
$v = Get-Version $majorVersion
144143
if ($v.Major -eq 0 -or $v.Major -ge 4) {
145-
$content = (New-Object Net.WebClient).DownloadString('http://nodejs.org/dist/')
144+
$content = (New-Object Net.WebClient).DownloadString('https://nodejs.org/dist/')
146145
} else {
147-
$content = (New-Object Net.WebClient).DownloadString('https://iojs.org/dist/')
146+
$content = (New-Object Net.WebClient).DownloadString('https://iojs.org/dist/')
148147
}
149148

150149
# parse versions and find the latest
151150
$versions = (Select-String '>v(\d*\.\d*\.\d*)/<' -input $content -allmatches `
152151
| % {$_.matches} | % { $_.groups[1].value } `
153152
| Where-Object {"$_.".StartsWith("$majorVersion.") })
154153

155-
if($versions.Count -eq 0) {
154+
if ($versions.Count -eq 0) {
156155
return $null
157-
}
158-
elseif($versions.indexOf('.') -ne -1) {
156+
} elseif ($versions.indexOf('.') -ne -1) {
159157
return $versions
160158
} else {
161159
$maxVersion = $versions[0]
162-
for($i = 0; $i -lt $versions.Count; $i++) {
163-
if((Get-Version $versions[$i]).number -gt (Get-Version $maxVersion).number) {
160+
for ($i = 0; $i -lt $versions.Count; $i++) {
161+
if ((Get-Version $versions[$i]).number -gt (Get-Version $maxVersion).number) {
164162
$maxVersion = $versions[$i]
165163
}
166164
}

0 commit comments

Comments
 (0)