Decky/scripts/Set-Version.ps1

31 lines
1.2 KiB
PowerShell

#requires -Version 5.1
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[ValidatePattern('^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$')]
[string]$Version
)
$ErrorActionPreference = 'Stop'
$repositoryRoot = Split-Path -Parent $PSScriptRoot
$appRoot = Join-Path $repositoryRoot 'app'
Push-Location $appRoot
try {
& npm.cmd version $Version --no-git-tag-version --allow-same-version
if ($LASTEXITCODE) { throw 'npm could not update package.json and package-lock.json.' }
} finally {
Pop-Location
}
$tauriConfigPath = Join-Path $appRoot 'src-tauri\tauri.conf.json'
$tauriConfig = Get-Content -Raw -LiteralPath $tauriConfigPath
$tauriConfig = [regex]::Replace($tauriConfig, '(?m)(^\s*"version"\s*:\s*")[^"]+("\s*,)', "`${1}$Version`${2}", 1)
[IO.File]::WriteAllText($tauriConfigPath, $tauriConfig, (New-Object Text.UTF8Encoding($false)))
$cargoManifestPath = Join-Path $appRoot 'src-tauri\Cargo.toml'
$cargoManifest = Get-Content -Raw -LiteralPath $cargoManifestPath
$cargoManifest = [regex]::Replace($cargoManifest, '(?m)(^version\s*=\s*")[^"]+("\s*$)', "`${1}$Version`${2}", 1)
[IO.File]::WriteAllText($cargoManifestPath, $cargoManifest, (New-Object Text.UTF8Encoding($false)))
Write-Host "Decky version set to $Version in npm, Tauri, and Cargo manifests."