@@ -91,7 +91,7 @@ task Compile -depends Clean {
91
91
$functionsToExport = @ ()
92
92
$sutLib = [System.IO.Path ]::Combine($sut , ' lib' )
93
93
$aliasesToExport = (. $sut \Aliases\PSGSuite.Aliases.ps1).Keys
94
- if (" $ env: NoNugetRestore " -ne ' True ' ) {
94
+ if (-not ( Test-Path $outputModVerDir ) ) {
95
95
$modDir = New-Item - Path $outputModDir - ItemType Directory - ErrorAction SilentlyContinue
96
96
New-Item - Path $outputModVerDir - ItemType Directory - ErrorAction SilentlyContinue | Out-Null
97
97
}
@@ -100,13 +100,22 @@ task Compile -depends Clean {
100
100
Write-BuildLog ' Creating psm1...'
101
101
$psm1 = Copy-Item - Path (Join-Path - Path $sut - ChildPath ' PSGSuite.psm1' ) - Destination (Join-Path - Path $outputModVerDir - ChildPath " $ ( $ENV: BHProjectName ) .psm1" ) - PassThru
102
102
103
- Get-ChildItem - Path (Join-Path - Path $sut - ChildPath ' Private' ) - Recurse - File | ForEach-Object {
104
- " $ ( Get-Content $_.FullName - Raw) `n " | Add-Content - Path $psm1 - Encoding UTF8
105
- }
106
- Get-ChildItem - Path (Join-Path - Path $sut - ChildPath ' Public' ) - Recurse - File | ForEach-Object {
107
- " $ ( Get-Content $_.FullName - Raw) `n Export-ModuleMember -Function '$ ( $_.BaseName ) '`n " | Add-Content - Path $psm1 - Encoding UTF8
108
- $functionsToExport += $_.BaseName
103
+ foreach ($scope in @ (' Private' , ' Public' )) {
104
+ Write-BuildLog " Copying contents from files in source folder to PSM1: $ ( $scope ) "
105
+ $gciPath = Join-Path $sut $scope
106
+ if (Test-Path $gciPath ) {
107
+ Get-ChildItem - Path $gciPath - Filter " *.ps1" - Recurse - File | ForEach-Object {
108
+ Write-BuildLog " Working on: $scope $ ( [System.IO.Path ]::DirectorySeparatorChar) $ ( $_.FullName.Replace (" $gciPath $ ( [System.IO.Path ]::DirectorySeparatorChar) " , ' ' ) -replace ' \.ps1$' ) "
109
+ [System.IO.File ]::AppendAllText($psm1 , (" $ ( [System.IO.File ]::ReadAllText($_.FullName )) `n " ))
110
+ if ($scope -eq ' Public' ) {
111
+ $functionsToExport += $_.BaseName
112
+ [System.IO.File ]::AppendAllText($psm1 , (" Export-ModuleMember -Function '$ ( $_.BaseName ) '`n " ))
113
+ }
114
+ }
115
+ }
109
116
}
117
+
118
+
110
119
Invoke-CommandWithLog {Remove-Module $env: BHProjectName - ErrorAction SilentlyContinue - Force - Verbose:$false }
111
120
112
121
if (" $env: NoNugetRestore " -ne ' True' ) {
@@ -331,10 +340,7 @@ Task Import -Depends Compile {
331
340
} - description ' Imports the newly compiled module'
332
341
333
342
$pesterScriptBlock = {
334
- ' Pester' | Foreach-Object {
335
- Install-Module - Name $_ - Repository PSGallery - Scope CurrentUser - AllowClobber - SkipPublisherCheck - Confirm:$false - ErrorAction Stop - Force
336
- Import-Module - Name $_ - Verbose:$false - ErrorAction Stop - Force
337
- }
343
+ ' Pester' | Resolve-Module - UpdateModules - Verbose
338
344
Push-Location
339
345
Set-Location - PassThru $outputModDir
340
346
if (-not $ENV: BHProjectPath ) {
@@ -368,8 +374,8 @@ $pesterScriptBlock = {
368
374
$testResults = Invoke-Pester @pesterParams
369
375
' Pester invocation complete!'
370
376
if ($testResults.FailedCount -gt 0 ) {
371
- $testResults | Format-List
372
- Write-Error - Message ' One or more Pester tests failed. Build cannot continue!'
377
+ $testResults.TestResult | Where-Object { -not $_ .Passed } | Format-List
378
+ Write-BuildError - Message ' One or more Pester tests failed. Build cannot continue!'
373
379
}
374
380
Pop-Location
375
381
$env: PSModulePath = $origModulePath
0 commit comments