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
77 stars 18 forks source link

[New App Request] Typora (On Proposals list) #102

Open AScott-WWF opened 4 months ago

AScott-WWF commented 4 months ago

Script:

# Get-Typora.ps1

# Define AppName
$AppName = "Typora"

$ReleaseUrl = "https://typora.io/releases/stable?no-warning"
$InstallInstructionsUrl = "https://support.typora.io/Typora-on-Windows/"

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

# Main script to fetch and process links
$AppVersions = @(
    @{AppName = $($AppName); Architecture = 'x86'; Type = 'exe'; Pattern = '-ia32-\d+\.\d+\.\d+\.exe'; VersionPattern = '-(\d+\.\d+\.\d+)\.exe'}
    @{AppName = $($AppName); Architecture = 'x64'; Type = 'exe'; Pattern = '-x64-\d+\.\d+\.\d+\.exe'; VersionPattern = '-(\d+\.\d+\.\d+)\.exe'}
    @{AppName = $($AppName); Architecture = 'ARM64'; Type = 'exe'; Pattern = '-arm64-\d+\.\d+\.\d+\.exe'; VersionPattern = '-(\d+\.\d+\.\d+)\.exe'}
)

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

    #Build each link with File Type specific versions
    $URL = (Get-Link -Uri $ReleaseUrl -MatchProperty href -Pattern $AppVersion.Pattern)
    [version]$Version = Get-Version -String $URL -Pattern $AppVersion.VersionPattern

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

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

    if ($SearchCount -eq 0) {
        Write-Warning "Could not find release for $($AppName) $($AppVersion.Type)"
    }
}

$ReleaseNotesUrl = "https://typora.io/releases/all"
Write-Verbose "$($AppName) (Version: $($Version)) release notes are available here: $($ReleaseNotesUrl)"
Write-Verbose "$($AppName) Install instructions are available here: $($InstallInstructionsUrl)"