Skip to content

Commit 024fbf2

Browse files
committed
Update build script
1 parent 62136d8 commit 024fbf2

File tree

3 files changed

+65
-9
lines changed

3 files changed

+65
-9
lines changed

Modules/ScriptLogger/ScriptLogger.psm1

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,53 @@
77
module context.
88
#>
99

10+
#region Namepsace Loader
1011

11-
## Module loader
12+
#endregion Namepsace Loader
13+
14+
#region Module Loader
15+
16+
# Get and dot source all classes (internal)
17+
Split-Path -Path $PSCommandPath |
18+
Get-ChildItem -Filter 'Classes' -Directory |
19+
Get-ChildItem -Include '*.ps1' -File -Recurse |
20+
ForEach-Object { . $_.FullName }
21+
22+
# Get and dot source all helper functions (internal)
23+
Split-Path -Path $PSCommandPath |
24+
Get-ChildItem -Filter 'Helpers' -Directory |
25+
Get-ChildItem -Include '*.ps1' -File -Recurse |
26+
ForEach-Object { . $_.FullName }
27+
28+
# Get and dot source all external functions (public)
29+
Split-Path -Path $PSCommandPath |
30+
Get-ChildItem -Filter 'Functions' -Directory |
31+
Get-ChildItem -Include '*.ps1' -File -Recurse |
32+
ForEach-Object { . $_.FullName }
33+
34+
#endregion Module Loader
35+
36+
#region Module Configuration
37+
38+
#endregion Module Configuration
39+
40+
41+
42+
43+
<#
44+
.SYNOPSIS
45+
Root module file.
46+
47+
.DESCRIPTION
48+
The root module file loads all classes, helpers and functions into the
49+
module context.
50+
#>
51+
52+
#region Namepsace Loader
53+
54+
#endregion Namepsace Loader
55+
56+
#region Module Loader
1257

1358
# Get and dot source all classes (internal)
1459
Split-Path -Path $PSCommandPath |
@@ -28,11 +73,14 @@ Split-Path -Path $PSCommandPath |
2873
Get-ChildItem -Include '*.ps1' -File -Recurse |
2974
ForEach-Object { . $_.FullName }
3075

76+
#endregion Module Loader
3177

32-
## Module configuration
78+
#region Module Configuration
3379

3480
# Module path
3581
New-Variable -Name 'ModulePath' -Value $PSScriptRoot
3682

3783
# Module wide array hosting all script loggers
3884
$Script:Loggers = @{}
85+
86+
#endregion Module Configuration

build.psake.ps1

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,11 @@ Task Merge -depends Stage -requiredVariables ReleasePath, ModulePath, ModuleName
282282
$moduleContent = New-Object -TypeName 'System.Collections.Generic.List[System.String]'
283283
$moduleDefinition = New-Object -TypeName 'System.Collections.Generic.List[System.String]'
284284

285-
# Load code of the module header
286-
$moduleContent.Add((Get-Content -Path "$ModulePath\$moduleName\$moduleName.psm1" | Select-Object -First 12) -join "`r`n")
285+
# Load code of the module namespace loader
286+
if ((Get-Content -Path "$ModulePath\$moduleName\$moduleName.psm1" -Raw) -match '#region Namepsace Loader[\r\n](?<NamespaceLoader>[\S\s]*)[\r\n]#endregion Namepsace Loader')
287+
{
288+
$moduleContent.Add($matches['NamespaceLoader'])
289+
}
287290

288291
# Load code for all class files
289292
foreach ($file in (Get-ChildItem -Path "$ModulePath\$moduleName\Classes" -Filter '*.ps1' -Recurse -File -ErrorAction 'SilentlyContinue'))
@@ -303,8 +306,11 @@ Task Merge -depends Stage -requiredVariables ReleasePath, ModulePath, ModuleName
303306
$moduleContent.Add((Get-Content -Path $file.FullName -Raw))
304307
}
305308

306-
# Load code of the module file itself
307-
$moduleContent.Add((Get-Content -Path "$ModulePath\$moduleName\$moduleName.psm1" | Select-Object -Skip 24) -join "`r`n")
309+
# Load code of the module namespace loader
310+
if ((Get-Content -Path "$ModulePath\$moduleName\$moduleName.psm1" -Raw) -match '#region Module Configuration[\r\n](?<ModuleConfiguration>[\S\s]*)#endregion Module Configuration')
311+
{
312+
$moduleContent.Add($matches['ModuleConfiguration'])
313+
}
308314

309315
# Concatenate whole code into the module file
310316
$moduleContent | Set-Content -Path "$ReleasePath\$moduleName\$moduleName.psm1" -Encoding UTF8 -Verbose:$VerbosePreference
@@ -330,7 +336,6 @@ Task Merge -depends Stage -requiredVariables ReleasePath, ModulePath, ModuleName
330336
}
331337
}
332338

333-
334339
# Save the updated module definition
335340
$moduleDefinition | Set-Content -Path "$ReleasePath\$moduleName\$moduleName.psd1" -Encoding UTF8 -Verbose:$VerbosePreference
336341
}
@@ -403,7 +408,9 @@ Task ScriptAnalyzer -requiredVariables ReleasePath, ModulePath, ModuleNames, Scr
403408
{
404409
$moduleScriptAnalyzerFile = Join-Path -Path $ScriptAnalyzerPath -ChildPath "$moduleName-$ScriptAnalyzerFile"
405410

411+
# Invoke script analyzer on the module but exclude all examples
406412
$analyzeResults = Invoke-ScriptAnalyzer -Path "$ReleasePath\$moduleName" -IncludeRule $ScriptAnalyzerRules -Recurse
413+
$analyzeResults = $analyzeResults | Where-Object { $_.ScriptPath -notlike "$releasePath\$moduleName\Examples\*" }
407414
$analyzeResults | ConvertTo-Json | Out-File -FilePath $moduleScriptAnalyzerFile -Encoding UTF8
408415

409416
Show-ScriptAnalyzerResult -ModuleName $moduleName -Rule $ScriptAnalyzerRules -Result $analyzeResults
@@ -567,6 +574,7 @@ function Get-GitMergeStatus($Branch)
567574
function Show-ScriptAnalyzerResult($ModuleName, $Rule, $Result)
568575
{
569576
$colorMap = @{
577+
ParseError = 'DarkRed'
570578
Error = 'Red'
571579
Warning = 'Yellow'
572580
Information = 'Cyan'

build.settings.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ Properties {
44
$ModuleNames = 'ScriptLogger'
55

66
$GalleryEnabled = $true
7-
$GalleryKey = Use-VaultSecureString -TargetName 'PowerShell Gallery Key'
7+
$GalleryKey = Use-VaultSecureString -TargetName 'PowerShell Gallery Key (claudiospizzi)'
88

99
$GitHubEnabled = $true
1010
$GitHubRepoName = 'claudiospizzi/ScriptLogger'
11-
$GitHubToken = Use-VaultSecureString -TargetName 'GitHub Token'
11+
$GitHubToken = Use-VaultSecureString -TargetName 'GitHub Token (claudiospizzi)'
1212
}

0 commit comments

Comments
 (0)