-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…, Fixes #42 ) Using PipeScript to build the module
- Loading branch information
James Brundage
committed
Sep 6, 2024
1 parent
7310b3f
commit 3c0836c
Showing
7 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
$commandsPath = Join-Path $PSScriptRoot .\Commands | ||
[include('*-*')]$commandsPath | ||
|
||
$myModule = $MyInvocation.MyCommand.ScriptBlock.Module | ||
$ExecutionContext.SessionState.PSVariable.Set($myModule.Name, $myModule) | ||
$myModule.pstypenames.insert(0, $myModule.Name) | ||
|
||
New-PSDrive -Name $MyModule.Name -PSProvider FileSystem -Scope Global -Root $PSScriptRoot -ErrorAction Ignore | ||
|
||
if ($home) { | ||
$MyModuleProfileDirectory = Join-Path $home $MyModule.Name | ||
if (-not (Test-Path $MyModuleProfileDirectory)) { | ||
$null = New-Item -ItemType Directory -Path $MyModuleProfileDirectory -Force | ||
} | ||
New-PSDrive -Name "My$($MyModule.Name)" -PSProvider FileSystem -Scope Global -Root $MyModuleProfileDirectory -ErrorAction Ignore | ||
} | ||
|
||
$KnownVerbs = Get-Verb | Select-Object -ExpandProperty Verb | ||
|
||
# Set a script variable of this, set to the module | ||
# (so all scripts in this scope default to the correct `$this`) | ||
$script:this = $myModule | ||
|
||
$myScriptTypeCommands = foreach ($myScriptType in $myModule.Name) { | ||
$myTypeData = Get-TypeData $myScriptType | ||
if (-not $myTypeData.Members) { continue } | ||
foreach ($myMemberInfo in $myTypeData.Members.GetEnumerator()) { | ||
$myMemberName = $myMemberInfo.Key | ||
$myMember = $myMemberInfo.Value | ||
if ($myMember -is [Management.Automation.Runspaces.ScriptMethodData]) { | ||
$myFunctionName = | ||
if ($myMemberName -in $KnownVerbs) { | ||
"$($myMemberName)-$($myScriptType)" | ||
} else { | ||
"$($myScriptType).$($myMemberName)" | ||
} | ||
# Declare My Function | ||
"function $myFunctionName { $($myMember.Script) }" | ||
if ($myMemberName -in $KnownVerbs) { | ||
# Alias it if it's a known verb, so both verb and noun form are available. | ||
"Set-Alias -Name '$($myScriptType).$($myMemberName)' -Value '$myFunctionName'" | ||
} | ||
|
||
"Set-Alias -Name '$($myMemberName).$($myScriptType)' -Value '$myFunctionName'" | ||
} | ||
} | ||
} | ||
|
||
. ([ScriptBlock]::Create($myScriptTypeCommands -join [Environment]::NewLine)) | ||
|
||
Export-ModuleMember -Alias * -Function * -Variable $myModule.Name |