From 20c7c402ef16464bae518e77f11205d0b0cb95fa Mon Sep 17 00:00:00 2001 From: StartAutomating Date: Sun, 17 Apr 2022 00:23:49 -0700 Subject: [PATCH] #38 - Removing single use parts --- Parts/FindUsedParts.ps1 | 75 ------------------------------------- Parts/ImportFormatParts.ps1 | 23 ------------ 2 files changed, 98 deletions(-) delete mode 100644 Parts/FindUsedParts.ps1 delete mode 100644 Parts/ImportFormatParts.ps1 diff --git a/Parts/FindUsedParts.ps1 b/Parts/FindUsedParts.ps1 deleted file mode 100644 index faf8c16..0000000 --- a/Parts/FindUsedParts.ps1 +++ /dev/null @@ -1,75 +0,0 @@ - -param( -[Parameter(Mandatory,ValueFromPipelineByPropertyName)] -[Alias('InnerText','ScriptBlock','ScriptContents')] -[string]$InScript, - -[PSModuleInfo[]] -$FromModule = @(Get-Module), - -# If set, will look for a part globally if it does not find in any of the modules. -[switch] -$AllowGlobal -) - -begin { - if (-not $script:LookedUpCommands) { - $script:LookedUpCommands = @{} - } - if (-not $script:CommandModuleLookup) { - $script:CommandModuleLookup = @{} - } - $GetVariableValue = { - param($name) - $ExecutionContext.SessionState.PSVariable.Get($name).Value - } - - #region <-- ? - $PowerShell_Invoke_Variable = [Regex]::new(@' -(?[\.\&]) # Match the (either a . or a &) -\s{0,} # Followed by Optional Whitespace -\$ # Followed by a Dollar Sign -((?\w+) # Followed by a (any number of repeated word characters) -| # Or a enclosed in curly brackets -(?:(?(?:.|\s)*?(?=\z|(? - -} - - process { - $in = $_ - foreach ($match in $PowerShell_Invoke_Variable.Matches($InScript)) { - $variableName = $match.Groups['Variable'].Value - if (-not $script:LookedUpCommands[$variableName]) { - $foundCommand = - foreach ($module in $FromModule) { - $foundIt = & $module $GetVariableValue $variableName - if ($foundIt) { - $script:CommandModuleLookup[$variableName] = $module - if ($foundIt -is [ScriptBlock]) { - $PSBoundParameters.InScript = "$foundIt" - & $MyInvocation.MyCommand.ScriptBlock @PSBoundParameters - } - $foundIt; break - } - } - - if (-not $foundCommand -and $AllowGlobal) { - $foundCommand = & $getVariableValue $variableName - } - $script:LookedUpCommands[$variableName] = $foundCommand - } - [PSCustomObject][Ordered]@{ - Name = $variableName - ScriptBlock = $script:LookedUpCommands[$variableName] - Module = $script:CommandModuleLookup[$variableName] - FindInput = $in - } - } -} - - - diff --git a/Parts/ImportFormatParts.ps1 b/Parts/ImportFormatParts.ps1 deleted file mode 100644 index a567a9d..0000000 --- a/Parts/ImportFormatParts.ps1 +++ /dev/null @@ -1,23 +0,0 @@ -do { - $lm = Get-Module -Name $moduleName -ErrorAction Ignore - if (-not $lm) { continue } - if ($lm.FormatPartsLoaded) { break } - $wholeScript = @(foreach ($formatFilePath in $lm.exportedFormatFiles) { - foreach ($partNodeName in Select-Xml -LiteralPath $formatFilePath -XPath "/Configuration/Controls/Control/Name[starts-with(., '$')]") { - $ParentNode = $partNodeName.Node.ParentNode - "$($ParentNode.Name)={ -$($ParentNode.CustomControl.CustomEntries.CustomEntry.CustomItem.ExpressionBinding.ScriptBlock)}" - } - }) -join [Environment]::NewLine - New-Module -Name "${ModuleName}.format.ps1xml" -ScriptBlock ([ScriptBlock]::Create(($wholeScript + ';Export-ModuleMember -Variable *'))) | - Import-Module -Global - $onRemove = [ScriptBlock]::Create("Remove-Module '${ModuleName}.format.ps1xml'") - - if (-not $lm.OnRemove) { - $lm.OnRemove = $onRemove - } else { - $lm.OnRemove = [ScriptBlock]::Create($onRemove.ToString() + '' + [Environment]::NewLine + $lm.OnRemove) - } - $lm | Add-Member NoteProperty FormatPartsLoaded $true -Force - -} while ($false)