-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGet-InstallOrder.ps1
53 lines (47 loc) · 1.68 KB
/
Get-InstallOrder.ps1
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
$ErrorActionPreference = "Stop"
$ExcludePackages = @("ezchakra", "ezmgr")
class NimblePackage {
[string]$Name
[string]$Folder
[string[]]$Dependencies
static [NimblePackage]FromFolder($folder) {
Push-Location -Path $folder
$Json = nimble.exe dump --json | ConvertFrom-Json
Pop-Location
$Result = [NimblePackage]::new()
$Result.Name = $Json.name
$Result.Folder = $folder
$Result.Dependencies = $Json |
Select-Object -ExpandProperty requires |
Where-Object { $_.name -ne "nim" } |
Select-Object -ExpandProperty name
return $Result
}
[string]ToString() {
if ($null -eq $this.Dependencies) {
return ("({0})" -f $this.Name)
}
return ("({0}: {1})" -f $this.Name, ($this.Dependencies -join ", "))
}
[void]FilterOutDependencies($Names) {
$this.Dependencies = $this.Dependencies | Where-Object { $Names -contains $_ }
}
}
function Group-Packages($Source) {
$Names = $Source | Select-Object -ExpandProperty Name
foreach ($item in $Source) {
$item.FilterOutDependencies($Names)
}
$Result = $Source | Group-Object {$_.Dependencies.Count -eq 0}
$Result | Where-Object {$_.Name -eq $true } | Select-Object Group
$Result | Where-Object {$_.Name -eq $false } | Select-Object Group
}
$script:Folder = Get-ChildItem .\packages -Directory
$script:Packages = $script:Folder |
ForEach-Object { [NimblePackage]::FromFolder($_) } |
Where-Object { $_.Name -notin $ExcludePackages }
while ($script:Packages.Count -gt 0) {
$local:Parts = Group-Packages $script:Packages
$script:Packages = $local:Parts[1] | Select-Object -ExpandProperty Group
$local:Parts[0] | Select-Object -ExpandProperty Group | Select-Object -ExpandProperty Folder
}