Skip to content

Commit

Permalink
disable extra logging on module load
Browse files Browse the repository at this point in the history
  • Loading branch information
ninmonkey committed Nov 16, 2023
1 parent 18e7566 commit fe52d77
Show file tree
Hide file tree
Showing 2 changed files with 171 additions and 43 deletions.
78 changes: 40 additions & 38 deletions root_autoloader.ps1
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#Requires -Version 7.0
using namespace system.collections.generic
using namespace System.Collections.Generic
# __init__.ps1

Write-Warning "🐱‍👤finish $PSCommandPath"
# Write-Warning "🐱‍👤finish $PSCommandPath"

$____debug = @{
Export_Module_Listing_On_Startup = $false
Expand Down Expand Up @@ -32,7 +32,7 @@ $strUL = @{
}


'[dev.nin] / refactor this {0}' -f $PSCommandPath | write-warning
'[dev.nin] / refactor this {0}' -f $PSCommandPath | Write-Warning


Function Join-Hashtable {
Expand Down Expand Up @@ -310,17 +310,22 @@ function _find_moduleInitDir {

$dirsToLoad = _find_moduleInitDir
| Sort-Object { $_.FullName -match 'beforeAll' } -Descending # future will allow sort order from '__init__.ps1'

$dirsToLoad | Write-Host -foreg Green
# | % fullname

$DirsToLoad | Join-String @strUL | Write-Verbose
$DirsToLoad | Join-String @strUL { $_.Name } | Write-Debug
$DirsToLoad
| Join-String @strUL | Write-Verbose
$DirsToLoad
| Join-String @strUL { $_.Name } | Write-Debug
# | Write-Information
'before'
# 'before'

# $NinModuleInfo
# | ConvertTo-Json -Depth 50 | Set-Content 'temp:\last_NinModuleInfo.json' -Encoding utf8

$NinModuleInfo | ConvertTo-Json -Depth 50 | Set-Content 'temp:\last_NinModuleInfo.json' -Encoding utf8
Get-Content 'temp:\last_NinModuleInfo.json' -Encoding utf8
| bat -l json -f -p | Write-Information
# Get-Content 'temp:\last_NinModuleInfo.json' -Encoding utf8
# | bat -l json -f -p | Write-Information


# $origTest = Get-ChildItem -File -Path (Get-Item -ea stop $PSScriptRoot)
Expand Down Expand Up @@ -417,31 +422,33 @@ if ($script:publicToExport['variable']) {

$meta | Format-Table | Out-String | Write-Information

if ($true) {
# tip: 'Join-String' does not require the empty and $null gaurds, left in for intent
# detect not yet transferred over
if ($publicToExport.function.Count -gt 0) {
$publicToExport.function | Join-String @strUl
| Join-String -op "(eventually deprecated warning): `$publicToExport.function is not empty, migrate to 'ninModuleInfo' Items: `n"
| Write-Debug
}
if ($publicToExport.alias.Count -gt 0) {
$publicToExport.alias | Join-String @strUl
| Join-String -op "(eventually deprecated warning): `$publicToExport.alias is not empty, migrate to 'ninModuleInfo' Items: `n"
| Write-Debug
# if ($true) {
# # tip: 'Join-String' does not require the empty and $null gaurds, left in for intent
# # detect not yet transferred over
# if ($publicToExport.function.Count -gt 0) {
# $publicToExport.function
# | Join-String @strUl
# | Join-String -op "(eventually deprecated warning): `$publicToExport.function is not empty, migrate to 'ninModuleInfo' Items: `n"
# | Write-Debug
# }
# if ($publicToExport.alias.Count -gt 0) {
# $publicToExport.alias
# | Join-String @strUl
# | Join-String -op "(eventually deprecated warning): `$publicToExport.alias is not empty, migrate to 'ninModuleInfo' Items: `n"
# | Write-Debug

}
if ($publicToExport.cmdlet.Count -gt 0) {
$publicToExport.cmdlet | Join-String @strUl | Write-Warning # | Write-Debug
| Join-String -op "(eventually deprecated warning): `$publicToExport.cmdlet is not empty, migrate to 'ninModuleInfo' Items: `n"
| Write-Debug
}
if ($publicToExport.variable.Count -gt 0) {
$publicToExport.variable | Join-String @strUl | Write-Warning # | Write-Debug
| Join-String -op "(eventually deprecated warning): `$publicToExport.variable is not empty, migrate to 'ninModuleInfo' Items: `n"
| Write-Debug
}
}
# }
# if ($publicToExport.cmdlet.Count -gt 0) {
# $publicToExport.cmdlet | Join-String @strUl | Write-Warning # | Write-Debug
# | Join-String -op "(eventually deprecated warning): `$publicToExport.cmdlet is not empty, migrate to 'ninModuleInfo' Items: `n"
# | Write-Debug
# }
# if ($publicToExport.variable.Count -gt 0) {
# $publicToExport.variable | Join-String @strUl | Write-Warning # | Write-Debug
# | Join-String -op "(eventually deprecated warning): `$publicToExport.variable is not empty, migrate to 'ninModuleInfo' Items: `n"
# | Write-Debug
# }
# }
$devNinRoot = '~\.dev-nin\dump'


Expand All @@ -456,11 +463,6 @@ $__exportPaths = @{

}

if ($true) {
}



if ($false -and $____debug.Export_Super_ExcessiveTest) {
"`$____debug.Export_Super_ExcessiveTest: `$true from '$PSCommandPath'"
| Write-Warning
Expand Down
136 changes: 131 additions & 5 deletions zeroDepend_autoloader/Format-ShortTypeName.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,68 @@ function Format-ShortSciTypeName {
}
}

$script:__ninNamespaceMapping = @{
'PoshCode.Pansies' = 'Pansies'
'System.Xml.Linq' = 'xml.Linq'
'System.Linq' = 'Linq'
'Newtonsoft.Json' = 'newtjs'
'Runtime.InteropServices' = 'ri'
'Reflection' = 'r'
'Text.RegularExpressions' = 't.re' # 're' or 't.re'
'Text' = 't'
'Runtime' = 'run' # 'run' or 'rt'
'Runspaces' = 'runs'
'Xml.Schema' = 'schema.'
'Windows' = 'win'
'Threading' = 't' # '' or 't'
'Windows.Networking.Sockets' = 'win.sock'
'Windows.Media' = 'win.media'
'Windows.Networking' = 'win.net'
'Windows.Globalization' = 'global' # 'cult' or 'global'
'System.Management.Automation' = 'sma'
'System.Security.Cryptography' = 'crypto'
'Microsoft.PowerShell.Commands' = 'pwsh.cmds'
'Microsoft.ApplicationInsights' = 'app.insight'
'Microsoft.CodeAnalysis' = 'code.analysis'
'ABI.Windows.Networking' = 'abi.net'
'ABI.Windows.Globalization' = 'abi.global'
'ABI.Windows.Devices.Bluetooth' = 'abi.bluetooth'
'System.Diagnostics' = 'diag'
'System.Net.NetworkInformation' = 'net.info'
'System.Xml.Xsl' = 'xsl'
'System.Management.Automation.Configuration' = 'sma.Configuration'
'System.Management.Automation.Host' = 'sma.Host'
'System.Management.Automation.Internal' = 'sma.Internal'
'System.Management.Automation.Language' = 'sma.Language'
'System.Management.Automation.Provider' = 'sma.Provider'
'System.Management.Automation.PSTasks' = 'sma.PSTasks'
'System.Management.Automation.Remoting' = 'sma.Remoting'
'System.Management.Automation.Remoting.Client' = 'sma.Remoting.Client'
'System.Management.Automation.Remoting.Internal' = 'sma.Remoting.Internal'
'System.Management.Automation.Remoting.WSMan' = 'sma.Remoting.WSMan'
'System.Management.Automation.Runspaces' = 'sma.Runspaces'
'System.Management.Automation.Security' = 'sma.Security'
'System.Management.Automation.Subsystem' = 'sma.Subsystem'
'System.Management.Automation.Subsystem.DSC' = 'sma.Subsystem.DSC'
'System.Management.Automation.Subsystem.Prediction' = 'sma.Subsystem.Prediction'
'System.Management.Automation.Tracing' = 'sma.Tracing'
} | %{ $_.GetEnumerator() } | sort-Object { $_.Key.Length } -Desc

if($True -and 'exportGlobal') {
$global:__ninNamespaceMapping = $script:__ninNamespaceMapping
}

function Format-ShortTypeName {
<#
.EXAMPLE
PS> [System.Management.Automation.VerboseRecord] | shortTypeName
[VerboseRecord]
.notes
to find type names, try:
find-type -Namespace *xml* | Format-ShortTypeName | sls 'xml' -AllMatches
.example
PS>
Expand All @@ -264,6 +320,14 @@ function Format-ShortTypeName {
[IO.DirectoryInfo]
[VerboseRecord]
[RgbColorProviderRoot]
.EXAMPLE
PS> gci . | xa.TypeOf -FormatMode TypeInfo
| Sort-Object -Unique | Format-ShortTypeName
# output:
[IO.DirectoryInfo]
[IO.FileInfo]
.notes
render-* implies ansi colors
Expand All @@ -273,19 +337,81 @@ function Format-ShortTypeName {
Ninmonkey.Console\Render-ShortTypeName
#>
[Alias('shortTypeName')]
[Alias(
'shortTypeName'
)]
[CmdletBinding()]
param(
[AllowNull()]
[Parameter(Mandatory, ValueFromPipeline)]
[object]$InputObject
[object]$InputObject,

# using '$script:__ninNamespaceMapping'
[Alias('UsingMapping')][switch]$UsingCustomMapping,
# replace namespaces with something short, not nothing
[switch]$UsingNamespaceAliases
)
process {
if($null -eq $InputObject){ return 'TrueNull' }
$IsRawString = $InputObject -is 'string'
if($IsRawString) {
if($InputObject.Length -eq 0) {
return '[String]::Empty'
}
}

$nameString = ''
if ($InputObject -is 'type') {
$Target = $InputObject
} else {
$nameString = $Target.FullName
} elseif($InputObject -isnot 'string' ) {
$Target = $InputObject.GetType()
$nameString = $Target.FullName
} else {
$nameString = $InputObject
}
$accum = $nameString
Join-String -op 'initial input ' -single -inp $accum | Write-Debug

if($UsingCustomMapping) {
foreach($pair in $script:__ninNamespaceMapping.GetEnumerator()) {
$Pair.Key, $Pair.Value | Join-String -op ' try name: ' | write-debug
[string]$regexKey = [Regex]::escape( $Pair.Key )
if($accum -match $regexKey) {
$toBreak = $true
}
$accum = $accum -replace $regexKey, $Pair.Value
Join-String -op ' set value := ' -inp $accum | Write-Debug
if($ToBreak){
break
}
}
Join-String -op 'final value ' -inp $accum | Write-Debug
Join-String -op '[' -os ']' -Input $accum
return
}

$Target.FullName -replace '^System\.(Management.Automation\.)?', '' -replace '^PoshCode\.Pansies', 'Pansies'
| Join-String -op '[' -os ']'
if( -not $UsingNamespaceAliases) {
$accum = $accum -replace
'^(System\.)?(Management.Automation\.)?', '' -replace
'^PoshCode\.Pansies', 'Pansies'
} else {
$accum = $accum -replace
'^(System\.)?(Management.Automation\.)?', 'sma.' -replace
'^PoshCode\.Pansies', 'Pansies'

}
Join-String -op 'final value ' -inp $accum | Write-Debug
Join-String -op '[' -os ']' -Input $accum


# if ($InputObject -is 'type') {
# $Target = $InputObject
# } else {
# $Target = $InputObject.GetType()
# }

# $Target.FullName -replace '^System\.(Management.Automation\.)?', '' -replace '^PoshCode\.Pansies', 'Pansies'
# | Join-String -op '[' -os ']'
}
}

0 comments on commit fe52d77

Please sign in to comment.