DanGough / Nevergreen

This module is an alternative to Evergreen, and allows you to find the latest version and download URL for various Windows apps. Evergreen uses API queries to obtain its data whereas this module is more focussed on web scraping. This is more prone to breaking when websites are changed, hence the name.
The Unlicense
71 stars 16 forks source link

[New App Request] NodeJS (On Proposals list) #89

Open AScott-WWF opened 2 days ago

AScott-WWF commented 2 days ago

This will return "Maintenance", "LTS" and "Current" Channels

Script:

# Get-NodeJS.ps1

# Define AppName
$AppName = "NodeJS"

$ReleaseUrl = "https://github.com/nodejs/Release?tab=readme-ov-file"

Write-Verbose "Obtaining $($AppName) Release Versions from $($ReleaseUrl)...`n"

# Main script to fetch and process links
$Releases = @(
    @{Channel = 'Maintenance'; ReleasePattern = '(?s)rel="nofollow">(\d+\.x)</a></td>.?<td align="center"><strong>Maintenance</strong></td>'}
    @{Channel = 'LTS'; ReleasePattern = '(?s)rel="nofollow">(\d+\.x)</a></td>.?<td align="center"><strong>LTS</strong></td>'}
    @{Channel = 'Current'; ReleasePattern = '(?s)rel="nofollow">(\d+\.x)</a></td>.?<td\ align="center"><strong>Current</strong></td>'}
)

$AppVersions = @(
    @{AppName = $($AppName); Platform = 'win'; Architecture = 'x64'; Type = 'msi'; URLPattern = 'node-v\d+\.\d+\.\d+-x64\.msi'}
    @{AppName = $($AppName); Platform = 'win'; Architecture = 'x64'; Type = 'zip'; URLPattern = 'node-v\d+\.\d+\.\d+-win-x64\.zip'}
    @{AppName = $($AppName); Platform = 'win'; Architecture = 'x64'; Type = '7z'; URLPattern = 'node-v\d+\.\d+\.\d+-win-x64\.7z'}
    @{AppName = $($AppName); Platform = 'win'; Architecture = 'x86'; Type = 'msi'; URLPattern = 'node-v\d+\.\d+\.\d+-x86\.msi'}
    @{AppName = $($AppName); Platform = 'win'; Architecture = 'x86'; Type = 'zip'; URLPattern = 'node-v\d+\.\d+\.\d+-win-x86\.zip'}
    @{AppName = $($AppName); Platform = 'win'; Architecture = 'x86'; Type = '7z'; URLPattern = 'node-v\d+\.\d+\.\d+-win-x86\.7z'}
    @{AppName = $($AppName); Platform = 'win'; Architecture = 'arm64'; Type = 'msi'; URLPattern = 'node-v\d+\.\d+\.\d+-arm64\.msi'}
    @{AppName = $($AppName); Platform = 'win'; Architecture = 'arm64'; Type = 'zip'; URLPattern = 'node-v\d+\.\d+\.\d+-win-arm64\.zip'}
    @{AppName = $($AppName); Platform = 'win'; Architecture = 'arm64'; Type = '7z'; URLPattern = 'node-v\d+\.\d+\.\d+-win-arm64\.7z'}
)

foreach ($Release in $Releases) {
    $ChannelURL = (Get-Link -Uri $($ReleaseUrl) -MatchProperty outerHTML -Pattern (Get-Version -Uri $($ReleaseUrl) -Pattern $($Release.ReleasePattern)))

    if ($ChannelURL) {
        foreach ($AppVersion in $AppVersions) {
            $SearchCount = 1 # This may need increasing as future versions are released

            #Build each link with File Type specific versions
            # Check if Link to file download exists (arm64 is not available for earlier versions)
            if (Get-Link -Uri $($ChannelUrl) -MatchProperty href -Pattern $($AppVersion.URLPattern)) {
                $URL = (Resolve-Uri -Uri (Set-UriPrefix -Uri (Get-Link -Uri $($ChannelUrl) -MatchProperty href -Pattern $($AppVersion.URLPattern)) -Prefix $($ChannelURL))).Uri
                [version]$Version = Get-Version -String $URL

                $InstallInstructionsUrl = "https://nodejs.org/en/learn/getting-started/how-to-install-nodejs"
                $ReleaseNotesUrl = "https://github.com/nodejs/node/blob/main/doc/changelogs/CHANGELOG_V$($Version.Major).md"

                do {
                    if ($URL) {
                        New-NevergreenApp -Name $($AppVersion.AppName) -Version $($Version) -Uri $($URL) -Architecture $($AppVersion.Architecture) -Type $($AppVersion.Type) -Channel $($Release.Channel)
                        break
                    }

                    $SearchCount--
                } until ($SearchCount -eq 0)
            } else {
                $SearchCount--
            }

            if ($SearchCount -eq 0) {
                Write-Verbose "`nWARNING: Could not find $($AppVersion.Architecture) release for $($AppName) v$($Version) in .$($AppVersion.Type) format`n"
            }
        }
    }
    Write-Verbose "$($AppName) (Version: $($Version)) Release notes are available here: $($ReleaseNotesUrl)"
    Write-Verbose "$($AppName) Install instructions are available here: $($InstallInstructionsUrl)"
}