-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdateChocolateyInstall.ps1
More file actions
35 lines (25 loc) · 1.37 KB
/
updateChocolateyInstall.ps1
File metadata and controls
35 lines (25 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
param (
[Parameter(Mandatory = $true)]
[string]$NewVersion
)
# Define the path to the chocolateyInstall.ps1 file
$scriptPath = ".\packages\nx-chocolatey\tools\chocolateyInstall.ps1"
# Read the content of the chocolateyInstall.ps1 file
$scriptContent = Get-Content -Path $scriptPath -Raw
# Update the $version variable in the script
$scriptContent = $scriptContent -replace '(?<=\$version\s+=\s+[''"])(\d+\.\d+\.\d+)(?=[''"])', $NewVersion
# Define the package name and construct the URL for the tarball
$packageName = 'nx'
$tgzUrl = "https://registry.npmjs.org/$packageName/-/$packageName-$NewVersion.tgz"
# Download the tarball to a temporary location
$tempTgzFile = Join-Path -Path $env:TEMP -ChildPath "$packageName-$NewVersion.tgz"
Invoke-WebRequest -Uri $tgzUrl -OutFile $tempTgzFile
# Compute the SHA256 checksum of the downloaded tarball
$checksum = (Get-FileHash -Path $tempTgzFile -Algorithm SHA256 | Select-Object -ExpandProperty Hash).ToLower()
# Update the $checksum variable in the script
$scriptContent = $scriptContent -replace '(?<=\$checksum\s+=\s+[''"])[a-fA-F0-9]+(?=[''"])', $checksum
# Save the updated content back to the chocolateyInstall.ps1 file
Set-Content -Path $scriptPath -Value $scriptContent
# Clean up the temporary tarball file
Remove-Item -Path $tempTgzFile -Force
Write-Host "Updated chocolateyInstall.ps1 to version $NewVersion with checksum $checksum."