Skip to content

Commit 1fc47c7

Browse files
committed
fix(debug): 🐛 Refactor debug harness for improved module loading
* Added checks for `$env:BHProjectPath` and adjusted paths for module imports. * Set up output directory more robustly. * Changed `Invoke-Plaster` to use `-WhatIf` for safer execution.
1 parent 6e761be commit 1fc47c7

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

debugHarness.ps1

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
11
# Use this file to debug the module.
2-
Import-Module $PSScriptRoot\src\Plaster.psd1
2+
if ($null -eq $env:BHProjectPath) {
3+
$path = Join-Path -Path $PSScriptRoot -ChildPath '..\build.ps1'
4+
. $path -Task Build
5+
}
6+
$manifest = Import-PowerShellDataFile -Path $env:BHPSModuleManifest
7+
$outputDir = Join-Path -Path $env:BHProjectPath -ChildPath 'Output'
8+
$outputModDir = Join-Path -Path $outputDir -ChildPath $env:BHProjectName
9+
$outputModVerDir = Join-Path -Path $outputModDir -ChildPath $manifest.ModuleVersion
10+
$outputModVerManifest = Join-Path -Path $outputModVerDir -ChildPath "$($env:BHProjectName).psd1"
11+
Get-Module $env:BHProjectName | Remove-Module -Force -ErrorAction Ignore
12+
Import-Module -Name $outputModVerManifest -Verbose:$false -ErrorAction Stop
13+
14+
#region Setup Output Directory
15+
$OutDir = Join-Path $outputDir "\HarnessOutput"
16+
Remove-Item $OutDir -Recurse -ErrorAction SilentlyContinue
17+
New-Item -ItemType Directory -Path $OutDir | Out-Null
18+
#endregion Setup Output Directory
319

420
# Various debug scenarios other than running Invoke-Plaster.
521
# Invoke-Pester $PSScriptRoot\test
622
# Test-PlasterManifest "$PSScriptRoot\src\Templates\NewModule\plasterManifest.xml" -Verbose
723
# Invoke-psake $PSScriptRoot\build.psake.ps1 -taskList BuildHelp
824
# return
925

10-
$OutDir = "$PSScriptRoot\examples\Out"
11-
Remove-Item $OutDir -Recurse -ErrorAction SilentlyContinue
12-
1326
# $PlasterParams = @{
1427
# TemplatePath = "$PSScriptRoot\src\Templates\AddPSScriptAnalyzerSettings"
1528
# DestinationPath = $OutDir
@@ -19,7 +32,7 @@ Remove-Item $OutDir -Recurse -ErrorAction SilentlyContinue
1932
# }
2033

2134
$PlasterParams = @{
22-
TemplatePath = "$PSScriptRoot\src\Templates\NewPowerShellScriptModule"
35+
TemplatePath = "$PSScriptRoot\Plaster\Templates\NewPowerShellScriptModule"
2336
DestinationPath = $OutDir
2437
ModuleName = 'FooUtils'
2538
Version = '1.2.0'
@@ -48,7 +61,7 @@ $PlasterParams = @{
4861
# PassThru = $true
4962
# }
5063

51-
$obj = Invoke-Plaster @PlasterParams -Force
64+
$obj = Invoke-Plaster @PlasterParams -WhatIf
5265

5366
"PassThru object is:"
5467
$obj

0 commit comments

Comments
 (0)