analyze: add 'structure' option to list root packages across modules
- Commit
36b1857022e95c081972ccce10fd18b010f28755- Author
- vayun-mathur <[email protected]>
- When
- 2026-08-15 18:02 UTC (3 months ago)
- Parents
a9b075d
Diff
analyze.ps1
diff --git a/analyze.ps1 b/analyze.ps1index 0a7d4216e9..8f5934f5ad 100644--- a/analyze.ps1+++ b/analyze.ps1@@ -1,6 +1,6 @@ param ( [Parameter(Position = 0, Mandatory = $true)]- [ValidateSet("package", "module", "ram")]+ [ValidateSet("package", "module", "ram", "structure")] $Type, [Parameter(Mandatory = $false)]@@ -93,6 +93,42 @@ if ($ModuleName) { } } +# List every root package (the first sub-package after each app's base package) and+# report how many modules it appears in, plus the module names.+if ($Type -eq "structure") {+ $entries = foreach ($f in $files) {+ # The module name is the directory holding "src"; it is also the final segment of+ # the app's base package (e.g. music -> com.vayunmathur.music,+ # alchemist -> com.vayunmathur.games.alchemist).+ $module = ($f.FullName -split '\\src\\')[0].Split('\')[-1]++ # Split the package directory into segments, then take the segment right after the+ # one matching the module name. That segment is the root package.+ $segs = (Split-Path ($f.FullName -split '\\src\\')[1]) -split '\\'+ $idx = [array]::IndexOf($segs, $module)+ if ($idx -ge 0 -and ($idx + 1) -lt $segs.Count) {+ [PSCustomObject]@{ Module = $module; Package = $segs[$idx + 1] }+ }+ }++ if (-not $entries) {+ Write-Warning "No root packages found."+ return+ }++ $r = $entries | group Package | ForEach-Object {+ $mods = $_.Group.Module | sort -Unique+ [PSCustomObject]@{+ Package = $_.Name+ Modules = $mods.Count+ ModuleNames = ($mods -join ", ")+ }+ } | sort @{Expression = "Modules"; Descending = $true}, @{Expression = "Package"; Descending = $false}++ $r | Format-Table -AutoSize -Wrap+ return+}+ # Determine grouping logic based on the user's positional command if ($Type -eq "package") { $groupExp = { $_.Directory.Name }