-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConvertToNovaModuleSelfUpdatePlan.ps1
More file actions
93 lines (80 loc) · 3.03 KB
/
Copy pathConvertToNovaModuleSelfUpdatePlan.ps1
File metadata and controls
93 lines (80 loc) · 3.03 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
function Get-NovaModuleSelfUpdateLookupCandidate {
[CmdletBinding()]
param(
[pscustomobject]$LookupResult,
[Parameter(Mandatory)][bool]$PrereleaseNotificationsEnabled
)
if ($null -eq $LookupResult) {
return $null
}
if ($PrereleaseNotificationsEnabled -and $null -ne $LookupResult.Prerelease) {
return $LookupResult.Prerelease
}
if ($null -ne $LookupResult.Stable) {
return $LookupResult.Stable
}
return $LookupResult.Prerelease
}
function Get-NovaModuleSelfUpdateLookupRepository {
[CmdletBinding()]
param(
[pscustomobject]$LookupResult,
[object]$LookupCandidate
)
if ($null -ne $LookupCandidate -and $LookupCandidate.PSObject.Properties.Name -contains 'Repository') {
return $LookupCandidate.Repository
}
if ($null -ne $LookupResult -and $LookupResult.PSObject.Properties.Name -contains 'SourceRepository') {
return $LookupResult.SourceRepository
}
return $null
}
function Get-NovaModuleSelfUpdatePlanContext {
[CmdletBinding()]
param(
[pscustomobject]$LookupResult,
[Parameter(Mandatory)][bool]$PrereleaseNotificationsEnabled
)
$lookupCandidate = Get-NovaModuleSelfUpdateLookupCandidate -LookupResult $LookupResult -PrereleaseNotificationsEnabled:$PrereleaseNotificationsEnabled
$lookupCandidateVersion = if ($null -ne $lookupCandidate -and $lookupCandidate.PSObject.Properties.Name -contains 'Version') {
$lookupCandidate.Version
}
else {
$null
}
$lookupCandidateChannel = if ($null -ne $lookupCandidate -and $lookupCandidate.PSObject.Properties.Name -contains 'Channel') {
$lookupCandidate.Channel
}
else {
$null
}
return [pscustomobject]@{
LookupCandidateVersion = $lookupCandidateVersion
LookupCandidateChannel = $lookupCandidateChannel
LookupRepository = Get-NovaModuleSelfUpdateLookupRepository -LookupResult $LookupResult -LookupCandidate $lookupCandidate
PrereleaseNotificationsEnabled = $PrereleaseNotificationsEnabled
}
}
function ConvertTo-NovaModuleSelfUpdatePlan {
[CmdletBinding()]
param(
[Parameter(Mandatory)][pscustomobject]$InstalledModule,
[Parameter(Mandatory)][pscustomobject]$PlanContext,
[string]$TargetVersion,
[switch]$PrereleaseTarget
)
return [pscustomobject]@{
ModuleName = $InstalledModule.ModuleName
CurrentVersion = $InstalledModule.Version
TargetVersion = $TargetVersion
LookupCandidateVersion = $PlanContext.LookupCandidateVersion
LookupCandidateChannel = $PlanContext.LookupCandidateChannel
LookupRepository = $PlanContext.LookupRepository
PrereleaseNotificationsEnabled = $PlanContext.PrereleaseNotificationsEnabled
UpdateAvailable = -not [string]::IsNullOrWhiteSpace($TargetVersion)
Updated = $false
Cancelled = $false
IsPrereleaseTarget = $PrereleaseTarget.IsPresent
UsedAllowPrerelease = $PrereleaseTarget.IsPresent
}
}