@@ -4,18 +4,130 @@ $ErrorActionPreference = 'Stop'
44Import-Module " $PSScriptRoot \OSDCloudCustomBuilder.psd1" - Force
55Write-Host " Building OSDCloudCustomBuilder module..."
66
7- # Perform validations or build packaging
8- $PesterConfig = @ {
9- Run = @ {
10- Path = ' ./tests'
7+ # Process command-line arguments
8+ param (
9+ [Parameter (Position = 0 )]
10+ [ValidateSet (' Build' , ' Test' , ' Analyze' , ' Clean' , ' Docs' )]
11+ [string ]$Task = ' Build'
12+ )
13+
14+ # Determine what to do based on the task
15+ switch ($Task ) {
16+ ' Test' {
17+ Write-Host " Running tests..." - ForegroundColor Cyan
18+
19+ # Create test helper directories if they don't exist
20+ $testHelpersPath = Join-Path $PSScriptRoot ' tests\TestHelpers'
21+ if (-not (Test-Path $testHelpersPath )) {
22+ New-Item - Path $testHelpersPath - ItemType Directory - Force | Out-Null
23+ }
24+
25+ # Configure Pester
26+ $PesterConfig = @ {
27+ Run = @ {
28+ Path = ' ./tests'
29+ ExcludePath = ' ./tests/TestHelpers' # Exclude the helper modules from being run as tests
30+ }
31+ CodeCoverage = @ {
32+ Enabled = $true
33+ Path = @ (' ./Public/*.ps1' , ' ./Private/*.ps1' , ' ./Shared/*.ps1' )
34+ OutputPath = ' ./coverage.xml'
35+ OutputFormat = ' JaCoCo'
36+ }
37+ Output = @ {
38+ Verbosity = ' Detailed'
39+ }
40+ TestResult = @ {
41+ Enabled = $true
42+ OutputPath = ' ./testResults.xml'
43+ OutputFormat = ' NUnitXml'
44+ }
45+ }
46+
47+ # Run Pester tests
48+ Invoke-Pester - Configuration $PesterConfig
1149 }
12- CodeCoverage = @ {
13- Enabled = $true
14- Path = @ (' ./Public/*.ps1' , ' ./Private/*.ps1' , ' ./Shared/*.ps1' )
50+
51+ ' Analyze' {
52+ Write-Host " Analyzing code quality..." - ForegroundColor Cyan
53+
54+ # Ensure PSScriptAnalyzer is installed
55+ if (-not (Get-Module - ListAvailable - Name PSScriptAnalyzer)) {
56+ Write-Host " Installing PSScriptAnalyzer..." - ForegroundColor Yellow
57+ Install-Module - Name PSScriptAnalyzer - Force - Scope CurrentUser
58+ }
59+
60+ # Run PSScriptAnalyzer
61+ Invoke-ScriptAnalyzer - Path $PSScriptRoot - Recurse - Settings (Join-Path $PSScriptRoot ' PSScriptAnalyzer.settings.psd1' )
1562 }
16- Output = @ {
17- Verbosity = ' Detailed'
63+
64+ ' Clean' {
65+ Write-Host " Cleaning build artifacts..." - ForegroundColor Cyan
66+
67+ # List of artifacts to remove
68+ $artifactPaths = @ (
69+ ' ./output' ,
70+ ' ./coverage.xml' ,
71+ ' ./testResults.xml' ,
72+ ' ./artifacts'
73+ )
74+
75+ # Remove each artifact
76+ foreach ($path in $artifactPaths ) {
77+ $fullPath = Join-Path $PSScriptRoot $path
78+ if (Test-Path $fullPath ) {
79+ Remove-Item - Path $fullPath - Recurse - Force
80+ Write-Host " Removed: $path " - ForegroundColor Gray
81+ }
82+ }
1883 }
19- }
2084
21- Invoke-Pester - Configuration $PesterConfig
85+ ' Docs' {
86+ Write-Host " Generating documentation..." - ForegroundColor Cyan
87+
88+ # Check for PlatyPS module
89+ if (-not (Get-Module - ListAvailable - Name PlatyPS)) {
90+ Write-Host " Installing PlatyPS..." - ForegroundColor Yellow
91+ Install-Module - Name PlatyPS - Force - Scope CurrentUser
92+ }
93+
94+ # Generate documentation
95+ $docsPath = Join-Path $PSScriptRoot ' docs'
96+ if (-not (Test-Path $docsPath )) {
97+ New-Item - Path $docsPath - ItemType Directory - Force | Out-Null
98+ }
99+
100+ # Generate documentation for each public function
101+ $publicFunctions = Get-ChildItem - Path (Join-Path $PSScriptRoot ' Public' ) - Filter " *.ps1"
102+ foreach ($function in $publicFunctions ) {
103+ $functionName = $function.BaseName
104+ $docPath = Join-Path $docsPath " $functionName .md"
105+
106+ # Only generate if it doesn't exist or is older than the function file
107+ if (-not (Test-Path $docPath ) -or
108+ (Get-Item $docPath ).LastWriteTime -lt $function.LastWriteTime ) {
109+ Write-Host " Generating documentation for $functionName ..." - ForegroundColor Gray
110+ $null = New-MarkdownHelp - Command $functionName - OutputFolder $docsPath - Force
111+ }
112+ }
113+ }
114+
115+ default {
116+ # 'Build'
117+ Write-Host " Building module..." - ForegroundColor Cyan
118+
119+ # Run versioning from build.settings.ps1
120+ . (Join-Path $PSScriptRoot ' build.settings.ps1' )
121+
122+ # Copy any required files to output if needed
123+ $outputPath = Join-Path $PSScriptRoot ' output'
124+ if (-not (Test-Path $outputPath )) {
125+ New-Item - Path $outputPath - ItemType Directory - Force | Out-Null
126+ }
127+
128+ # You can add more build steps here
129+
130+ # Run tests as part of the build
131+ & $PSCommandPath - Task Test
132+ }
133+ }
0 commit comments