This repository has been archived by the owner on Oct 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Nuget-Reporter-LG1.ps1.minified.ps1
5 lines (5 loc) · 7.63 KB
/
Nuget-Reporter-LG1.ps1.minified.ps1
1
2
3
4
5
${Nuget-Reporter-LG1.ps1} = {$startitems=Get-ChildItem -LiteralPath HKLM:\SOFTWARE\WOW6432Node\Microsoft\VisualStudio\|Get-ItemProperty -Name "StartMenuFolder" -ErrorAction SilentlyContinue;$projects=@();$p=0;$startitems|% {if($_.StartMenuFolder-ne$null-and$_.StartMenuFolder-ne""){$vsprojc=New-Object -TypeName PSObject;$vsprojc|Add-Member -MemberType NoteProperty -Name "idx" -Value $p;$vsprojc|Add-Member -MemberType NoteProperty -Name "str" -Value ($_.StartMenuFolder | Split-Path -Leaf);$projects+=$vsprojc;$p++}};Write-Host "Detected VS versions:`r`n";$projects|% {$lbl="[{0}] {1}"-f$projects[[Array]::IndexOf($projects,$_)].idx,$projects[[Array]::IndexOf($projects,$_)].str;Write-Host $($lbl) `r`n};$selection=Read-Host "Please Select Visual Studio version for projects..";$completedir="{0}\Documents\{1}\Projects"-f$env:USERPROFILE,$projects[$selection].str;[System.Xml.XmlDocument]$xmlcnf=New-Object System.Xml.XmlDocument;[PSCustomObject[]]$nugInfo=@([PSCustomObject]@{maindir="";packagesIndir=[PSObject[]]@{packName=""} });[PSCustomObject[]]$nugInnerInf=@([PSCustomObject]@{packdir="";packageConfigInfo=[PSObject[]]@{name="";version="";value=0;color=""} });$exportDirTopRpt='{0}\Documents\JsonTopDirs_Rpt.json'-f$env:USERPROFILE;$exportDirCfgRpt='{0}\Documents\JsonCfgFiles_Rpt.json'-f$env:USERPROFILE;$exportDirCfgGroup='{0}\Documents\JsonPackagesGroups_Rpt.json'-f$env:USERPROFILE;$generalConfiguration='{0}\Documents\Rpt_Settings.json'-f$env:USERPROFILE;$config=@();$configval=@();$getCfg=(Get-Content -LiteralPath $generalConfiguration|Out-String|ConvertFrom-Json);$getCfg|% {$config+=$_;$_.PSObject.Properties|% {$configval+=$_.Value}};Write-Host "Select the configuration types to process.." `r`n;for($cnt=0;$cnt -lt $config.Count;$cnt++){$cnfnew=$config[$cnt]-replace"@{",""-replace"=}","";$Cnfstring="Config File: {0} OPTION [{1}] "-f$cnfnew,$cnt;Write-Host $Cnfstring};$opt=Read-Host "Select your option for config file(s) processing [0 - $($config.Count - 1)]";$selectedConfig=$config[$opt]-replace"@{",""-replace"=}","";$xpathsett1=($configval[$opt].PSObject.Properties | Select-Object Value | %{$_.Value})[0];$xpathsett2=($configval[$opt].PSObject.Properties | Select-Object Value | %{$_.Value})[1];$tmp_json1='{0}\Documents\export-jsonout.json'-f$env:USERPROFILE;$tmp_json2='{0}\Documents\export-jsoncleaned.json'-f$env:USERPROFILE;function Get-InnerNugetInfo{param([string]$nugetinfoPath,[int]$startValue)$d=@();$b=@();$xmlcnf.Load($nugetinfoPath);$d+=$xmlcnf.SelectNodes($xpathsett1);$b+=$xmlcnf.SelectNodes($xpathsett2);$newNuget=New-Object -TypeName PSObject;$newNuget|Add-Member -MemberType NoteProperty -Name "name" -Value $d[$startValue].Value;$newNuget|Add-Member -MemberType NoteProperty -Name "version" -Value $b[$startValue].Value;$newNuget|Add-Member -MemberType NoteProperty -Name "value" -Value ($d[$startValue]).Count;$newNuget|Add-Member -MemberType NoteProperty -Name "color" -Value "";[PSObject[]] $inputdirs+=$newNuget;if($startValue-gt0){Get-InnerNugetInfo -nugetInfoPath $nugetinfoPath -startValue ($startValue - 1)};return $inputdirs};$completedir|Get-ChildItem -Recurse -File -Filter $selectedConfig|% {$dirclean=$_.FullName-replace$selectedConfig;$arrNuget=New-Object -TypeName PSCustomObject;$arrNuget|Add-Member -MemberType NoteProperty -Name "maindir" -Value "";$arrNuget|Add-Member -MemberType NoteProperty -Name "packagesIndir" -Value "";$arrNugetCfg=New-Object -TypeName PSCustomObject;$arrNugetCfg|Add-Member -MemberType NoteProperty -Name "packdir" -Value "";$arrNugetCfg|Add-Member -MemberType NoteProperty -Name "packageConfigInfo" -Value "";[PSObject[]]$arrsubnuget=@(@{packName=""});[PSObject[]]$arrsubvernuget=@(@{name="";version="";value=0;color=""});$arrNuget.packagesIndir=$arrsubnuget;$arrNugetCfg.packageConfigInfo=$arrsubvernuget;$nugInfo+=$arrNuget;$nugInnerInf+=$arrNugetCfg};function Report-NugetTopDir{param([string]$topdir)$packdir=@();rm $exportDirTopRpt -ErrorAction SilentlyContinue;$topdir|Get-ChildItem -Directory|% {$packdir+=($_.FullName|Get-ChildItem -Recurse -Depth 1 -Directory -Include "packages")};for($b=0;$b -lt $packdir.Count;$b++){$nugInfo[$b].maindir=$packdir[$b].FullName;$nugInfo[$b].maindir|Get-ChildItem|% {$nugInfo[$b].packagesIndir+=$_.Name}};ConvertTo-Json $nugInfo|Add-Content -LiteralPath $exportDirTopRpt;Start-Process -FilePath $exportDirTopRpt};function Report-NugetConfigDir{param([string]$subCfgdir)$packCfg=@();rm $exportDirCfgRpt -ErrorAction SilentlyContinue;$subCfgdir|Get-ChildItem -Directory|Get-ChildItem -Filter $selectedConfig -Recurse|% {$packCfg+=$_.FullName};for($s=0;$s -lt $packCfg.Count;$s++){$nugInnerInf[$s].packdir=$packCfg[$s];$nugInnerInf[$s].packageConfigInfo=Get-InnerNugetInfo -nugetinfoPath ($nugInnerInf[$s].packdir) -startValue $packCfg.Count};ConvertTo-Json $nugInnerInf|Add-Content -LiteralPath $exportDirCfgRpt;Start-Process -FilePath $exportDirCfgRpt};Report-NugetTopDir -topdir $completedir;function Col-JsonProperties{param([bigint]$inputval)$topval=16711680;$addval=[Math]::Floor(0.01Mb + 1291);$colval;if($inputval.ToString().Length-eq1){$colval=$inputval*$addval;$default='#{0:X}'-f($topval-$colval);$default=$default.Replace("#0F","#F")};if($inputval.ToString().Length-gt2){$colval=$inputval*$addval;$default='#{0:X}'-f($topval-$colval);$default=$default.Replace("#0F","#F")};if($inputval.ToString().Length-ge5){$default=('#{0:X}' -f $topval).Replace("#0F","#F")};if(($inputval.ToString().Length-lt5)-and($inputval.ToString().Length-gt3)){$colval=$inputval*$addval;$default='#{0:X}'-f($topval-$colval);$default=$default.Replace("#0F","#F")};if($inputval.ToString().Length-eq2){$colval=$inputval*$addval;$default='#{0:X}'-f($topval-$colval);$default=$default.Replace("#0F","#F")};return $default};function Export-NugetCfgStats{$outputprop=@();$outCount=@();$outCol=@();rm $exportDirCfgGroup -ErrorAction SilentlyContinue;rm $tmp_json1 -ErrorAction SilentlyContinue;rm $tmp_json2 -ErrorAction SilentlyContinue;Report-NugetConfigDir -subCfgdir $completedir;$packCfg=@();$completedir|Get-ChildItem -Directory|Get-ChildItem -Filter $selectedConfig -Recurse -Depth 10|% {$packCfg+=$_.FullName};for($n=0;$n -lt $packCfg.Count;$n++){$ObjsOut=$nugInnerInf[$n].packageConfigInfo|Where-Object {$_.Name-ne$null}|Select-Object -Last 1;$ObjsOut|% {$_.name=$_.name+" "+$_.version;$outputprop+=$_.name};$outputprop|group|% {$outCount+=$_.Count;$outCol+=(Col-JsonProperties -inputval ($_.Count));foreach($prop in $ObjsOut){$prop.value=$outCount[[Array]::IndexOf($outputprop,$_.Value)];$prop.color=$outCol[[Array]::IndexOf($outputprop,$_.Value)]};ConvertTo-Json $ObjsOut|Add-Content -LiteralPath $tmp_json1}};Get-Content -LiteralPath $tmp_json1|% {$_-replace"\[",""-replace"\]",""-replace"}","},"-replace"},,","},"}|Set-Content -Path $tmp_json2;ConvertTo-Json ($outputprop | group)|Set-Content -LiteralPath $exportDirCfgGroup;Start-Process -FilePath $exportDirCfgGroup;$outputresult=Get-Content -LiteralPath $tmp_json2;$inSrc=Get-Content -LiteralPath "$env:USERPROFILE\Documents\chart-scripts\inputscript.txt"|% {$_-replace"\{DATAINPUT\}",$outputresult-replace'\"\{LABELINPUT\}\"',"'$($selectedConfig) stats'"};$outbody=@("<div id='container'></div>");$inSrc|% {$outbody+=$_};ConvertTo-Html -Title "Nuget packages stats" -Head @("<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>",
"<meta name='viewport' content='width=device-width, initial-scale=1'>",
"<link rel='stylesheet' type='text/css' href='.\css\tree-layout.css'>",
"<script src='.\chart-scripts\highcharts.js'></script>",
"<script src='.\chart-scripts\treemap.js'></script>") -Body $outbody|Set-Content -LiteralPath ".\NugetStatsReport.html";Invoke-Item -LiteralPath ".\NugetStatsReport.html"};Export-NugetCfgStats}