Public/Get-KadenVersion.ps1
|
function Get-KadenVersion { <# .SYNOPSIS Show applied versus installed Kaden payload version for a child repository. .DESCRIPTION Returns the installed module version, the applied managed-content version from `.kaden.json` when present, whether those versions match, and whether any transaction journal under `.kaden/transactions` failed to complete. When no journal is open and both versions are present, `RecommendedAction` is `Update` if they differ and `None` if they match. An open journal leaves `RecommendedAction` empty and includes its interruption code and the two repair actions, Resume and Restore. Expired completed journals are removed. Incomplete journals stay. A corrupt `.kaden.json` is refused with `KDN-TXN-PREFLIGHT-FAILED` and directions to repair the file or restore it from version control. .EXAMPLE Get-KadenVersion -Path . #> [CmdletBinding()] param( [Parameter(Mandatory = $true)] [string]$Path ) $childRoot = Resolve-KadenChildRoot -Path $Path Clear-KadenExpiredTransaction -ChildRoot $childRoot $open = Get-KadenOpenJournal -ChildRoot $childRoot $transactionCode = $null $recoveryActions = @() if ($open) { $transactionCode = Get-KadenTransactionCode -Journal $open.Journal $recoveryActions = @('Resume', 'Restore') } $installed = Get-KadenRunningModuleVersion $applied = $null $sharedPath = Join-Path $childRoot '.kaden.json' if (Test-Path -LiteralPath $sharedPath) { try { $shared = Get-Content -LiteralPath $sharedPath -Raw | ConvertFrom-Json } catch { throw 'KDN-TXN-PREFLIGHT-FAILED: Shared configuration is corrupt. Repair .kaden.json or restore it from version control, then retry.' } $applied = [string]$shared.managedContentVersion } $recommendedAction = $null if (-not $open -and $applied -and $installed) { if ($applied -eq $installed) { $recommendedAction = 'None' } else { $recommendedAction = 'Update' } } return [pscustomobject]@{ InstalledVersion = $installed AppliedVersion = $applied IsCurrent = ($applied -and $installed -and ($applied -eq $installed)) IncompleteTransaction = [bool]$open TransactionCode = $transactionCode RecoveryActions = $recoveryActions RecommendedAction = $recommendedAction } } |