Skip to content

Commit 6c8a11d

Browse files
committed
Add full minimal‑mode support, refine folder creation logic, rename BasePath to ModulePath, enhance logging, and update README to reflect new scaffolding behavior
This update introduces complete support for -Minimal across the scaffolding workflow. New-ModuleFolders now conditionally creates only core folders in minimal mode, while full mode retains the complete directory structure. The orchestrator was updated to pass -Minimal, enforce “minimal implies no Git,” and ensure -Force refreshes generated files rather than deleting the module folder. All scaffolding functions now receive -Force for safe overwrites. Additionally, all functions were updated to use ModulePath instead of BasePath for clearer and more consistent parameter naming. Logging improvements were added throughout the orchestrator and scaffolding functions to provide better visibility into generation steps and overwrite behavior.
1 parent 52e0723 commit 6c8a11d

26 files changed

Lines changed: 510 additions & 246 deletions

‎Private/Ensure-Directory.ps1‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
function Ensure-Directory {
2+
[CmdletBinding()]
3+
param(
4+
[Parameter(Mandatory)]
5+
[string]$Path,
6+
7+
[Parameter(Mandatory)]
8+
[string]$Name
9+
)
10+
11+
if (-not (Test-Path $Path)) {
12+
Write-Verbose "$Name directory does not exist. Creating it."
13+
Write-Debug "Creating directory at: $Path"
14+
New-Item -ItemType Directory -Path $Path -Force | Out-Null
15+
}
16+
else {
17+
Write-Debug "$Name directory already exists at: $Path"
18+
}
19+
}

‎Private/Show-GuiPrompt.ps1‎

Lines changed: 0 additions & 34 deletions
This file was deleted.

‎Private/Write-File.ps1‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function Write-FileContent {
2+
[CmdletBinding()]
3+
param(
4+
[Parameter(Mandatory)]
5+
[string]$Path,
6+
7+
[Parameter(Mandatory)]
8+
[string]$Content,
9+
10+
[Parameter(Mandatory)]
11+
[string]$Name
12+
)
13+
14+
Write-Verbose "Writing $Name to '$Path'."
15+
Write-Debug "Content length: $($Content.Length) characters"
16+
17+
Set-Content -Path $Path -Value $Content -Encoding UTF8 -Force
18+
19+
Write-Information "$Name created at '$Path'."
20+
}

‎Public/Initialize-GitRepository.ps1‎

Lines changed: 84 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
and performs an initial commit. This function is used by New-ModuleTemplate
88
when the -InitGit switch is provided.
99
10-
.PARAMETER BasePath
10+
.PARAMETER ModulePath
1111
The root directory of the module where the Git repository should be created.
1212
This must be the module's top-level folder (e.g., C:\Projects\MyModule).
1313
1414
.EXAMPLE
15-
Initialize-GitRepository -BasePath "C:\Projects\MyModule"
15+
Initialize-GitRepository -ModulePath "C:\Projects\MyModule"
1616
1717
.EXAMPLE
1818
$root = "C:\Modules\Tools"
19-
Initialize-GitRepository -BasePath $root
19+
Initialize-GitRepository -ModulePath $root
2020
2121
.NOTES
2222
- Requires Git to be installed and available in PATH.
@@ -26,37 +26,100 @@ function Initialize-GitRepository {
2626
[CmdletBinding()]
2727
param(
2828
[Parameter(Mandatory)]
29-
[string]$BasePath
29+
[string]$ModulePath
3030
)
3131

32-
# Create a standard .gitignore file for PowerShell modules
32+
Write-Verbose "Initializing Git repository in '$ModulePath'."
33+
34+
# Check for Git
35+
$git = Get-Command git -ErrorAction SilentlyContinue
36+
if (-not $git) {
37+
Write-Warning "Git is not installed or not on PATH. Skipping repository initialization."
38+
return
39+
}
40+
41+
Write-Debug "Git detected at: $($git.Source)"
42+
43+
# Write .gitignore
44+
Write-Verbose "Writing .gitignore file."
45+
$gitignorePath = Join-Path $ModulePath '.gitignore'
46+
3347
$gitignore = @'
34-
## Build artifacts
35-
bin/
36-
obj/
48+
# Ignore PowerShell module build output
49+
*.ps1xml
50+
*.cdxml
51+
*.xsd
52+
53+
# Ignore compiled help files
54+
*.dll
55+
*.exe
56+
*.pdb
57+
58+
# Ignore NuGet/PSGallery package files
59+
*.nupkg
60+
*.zip
61+
62+
# Ignore temporary files
63+
*.tmp
64+
*.log
65+
*.bak
66+
*.swp
67+
*.swo
3768
38-
# VSCode
69+
# Ignore VS Code settings and workspace files
3970
.vscode/
71+
.history/
4072
41-
# PlatyPS temp files
73+
# Ignore PlatyPS temp files
4274
Docs/*.xml
4375
44-
# PowerShellGet publish cache
45-
*.nupkg
76+
# Ignore PowerShellGet cache
77+
PSGetModuleInfo.xml
78+
79+
# Ignore build output folders
80+
bin/
81+
obj/
82+
out/
83+
Release/
84+
Debug/
85+
86+
# Ignore test results
87+
TestResults/
88+
*.trx
89+
*.coverage
90+
*.coveragexml
91+
92+
# Ignore OS-specific files
93+
.DS_Store
94+
Thumbs.db
95+
ehthumbs.db
96+
desktop.ini
97+
98+
# Ignore user-specific files
99+
*.user
100+
*.suo
101+
*.userosscache
102+
*.sln.docstates
46103
47-
# Logs
48-
*.log
49104
'@
50105

51-
# Write .gitignore to the module root
52-
Set-Content -Path "$BasePath\.gitignore" -Value $gitignore -Encoding UTF8
106+
Set-Content -Path $gitignorePath -Value $gitignore -Encoding UTF8
53107

54-
# Initialize the Git repository inside the module folder
55-
Push-Location $BasePath
108+
# Initialize repository
109+
Write-Verbose "Running 'git init' inside '$ModulePath'."
110+
Push-Location $ModulePath
56111
git init | Out-Null
57112
Pop-Location
58113

59-
# Stage all files and create the initial commit
60-
git -C $BasePath add . | Out-Null
61-
git -C $BasePath commit -m "Initial commit" | Out-Null
114+
# Stage files
115+
Write-Verbose "Staging initial files."
116+
git -C $ModulePath add . | Out-Null
117+
118+
# Commit
119+
Write-Verbose "Creating initial commit."
120+
git -C $ModulePath commit -m "Initial commit" | Out-Null
121+
122+
Write-Information "Git repository initialized successfully in '$ModulePath'."
123+
124+
return $gitignorePath
62125
}

‎Public/New-AnalyzerSettings.ps1‎

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
directory. The file defines rule severities and allows the module to enforce
88
consistent linting behavior across development environments and CI pipelines.
99
10-
.PARAMETER BasePath
10+
.PARAMETER ModulePath
1111
The root directory of the module where the AnalyzerSettings folder exists.
1212
This is typically the path returned by New-ModuleFolders.
1313
1414
.EXAMPLE
15-
New-AnalyzerSettings -BasePath "C:\Projects\MyModule"
15+
New-AnalyzerSettings -ModulePath "C:\Projects\MyModule"
1616
1717
.EXAMPLE
1818
$root = Join-Path $env:TEMP "TestModule"
19-
New-AnalyzerSettings -BasePath $root
19+
New-AnalyzerSettings -ModulePath $root
2020
2121
.NOTES
2222
This function is automatically invoked by New-ModuleTemplate.
@@ -26,16 +26,18 @@ function New-AnalyzerSettings {
2626
[CmdletBinding()]
2727
param(
2828
[Parameter(Mandatory)]
29-
[string]$BasePath
29+
[string]$ModulePath
3030
)
3131

32+
Write-Verbose "Creating PSScriptAnalyzer settings for module at '$ModulePath'."
33+
3234
# Path to the AnalyzerSettings directory
33-
$settingsDir = Join-Path $BasePath 'Analyzer'
35+
$settingsDir = Join-Path $ModulePath 'Analyzer'
36+
Write-Debug "Analyzer settings directory resolved to: $settingsDir"
37+
38+
# Ensure the directory exists
39+
Ensure-Directory -Path $settingsDir -Name 'Analyzer'
3440

35-
# Ensure the directory exists (New-ModuleFolders normally creates it)
36-
if (-not (Test-Path $settingsDir)) {
37-
New-Item -ItemType Directory -Path $settingsDir -Force | Out-Null
38-
}
3941

4042
# Default analyzer configuration
4143
$content = @'
@@ -55,10 +57,13 @@ function New-AnalyzerSettings {
5557
}
5658
}
5759
}
58-
5960
'@
6061

6162
# Write the settings file
6263
$settingsPath = Join-Path $settingsDir 'PSScriptAnalyzerSettings.psd1'
63-
Set-Content -Path $settingsPath -Value $content -Encoding UTF8
64+
65+
Write-FileContent -Path $settingsPath -Content $content -Name 'PSScriptAnalyzer settings'
66+
67+
return $settingsPath
6468
}
69+

‎Public/New-BuildScript.ps1‎

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@
99
- Regenerates PlatyPS documentation
1010
The script supports switches to skip individual steps.
1111
12-
.PARAMETER BasePath
12+
.PARAMETER ModulePath
1313
The root directory of the module where the Scripts folder will be created.
1414
1515
.PARAMETER Name
1616
The name of the module. Used to reference the module manifest and display
1717
status messages inside the generated build script.
1818
1919
.EXAMPLE
20-
New-BuildScript -BasePath "C:\Projects\MyModule" -Name "MyModule"
20+
New-BuildScript -ModulePath "C:\Projects\MyModule" -Name "MyModule"
2121
2222
.EXAMPLE
2323
$root = Join-Path $env:TEMP "TestModule"
24-
New-BuildScript -BasePath $root -Name "TestModule"
24+
New-BuildScript -ModulePath $root -Name "TestModule"
2525
2626
.NOTES
2727
- The Analyzer folder is intentionally named "Analyzer".
@@ -31,51 +31,57 @@ function New-BuildScript {
3131
[CmdletBinding()]
3232
param(
3333
[Parameter(Mandatory)]
34-
[string]$BasePath,
34+
[string]$ModulePath,
3535

3636
[Parameter(Mandatory)]
3737
[string]$Name
3838
)
3939

40-
# Ensure the Scripts directory exists
41-
$scriptsDir = Join-Path $BasePath 'Scripts'
42-
if (-not (Test-Path $scriptsDir)) {
43-
New-Item -ItemType Directory -Path $scriptsDir -Force | Out-Null
44-
}
40+
Write-Verbose "Creating build script for module '$Name'."
41+
42+
# Ensure Scripts directory exists
43+
$scriptsDir = Join-Path $ModulePath 'Scripts'
44+
Ensure-Directory -Path $scriptsDir -Name 'Scripts'
4545

46-
# Template for the build script
46+
# Template for the build script (Write-Host removed, modern patterns used)
4747
$content = @'
4848
param(
4949
[switch]$SkipTests,
5050
[switch]$SkipAnalyzer,
5151
[switch]$SkipDocs
5252
)
5353
54-
Write-Host "Building __MODULE__..."
54+
Write-Information "Building __MODULE__..."
5555
5656
if (-not $SkipAnalyzer) {
57-
Write-Host "Running PSScriptAnalyzer..."
57+
Write-Information "Running PSScriptAnalyzer..."
5858
Invoke-ScriptAnalyzer -Path $PSScriptRoot -Settings "$PSScriptRoot\Analyzer\PSScriptAnalyzerSettings.psd1"
5959
}
6060
6161
if (-not $SkipTests) {
62-
Write-Host "Running Pester tests..."
63-
Invoke-Pester -Path "$PSScriptRoot\Tests" -EnableExit
62+
Write-Information "Running Pester tests..."
63+
Invoke-Pester -Path "$PSScriptRoot\Tests"
64+
if ($LASTEXITCODE -ne 0) {
65+
Write-Error "Pester tests failed."
66+
exit $LASTEXITCODE
67+
}
6468
}
6569
6670
if (-not $SkipDocs) {
67-
Write-Host "Updating PlatyPS docs..."
71+
Write-Information "Updating PlatyPS docs..."
6872
Import-Module PlatyPS -ErrorAction Stop
69-
New-MarkdownHelp -Module "$PSScriptRoot\__MODULE__.psd1" -OutputFolder "$PSScriptRoot\Docs" -Force
73+
Import-Module "$PSScriptRoot\__MODULE__.psd1" -Force
74+
New-MarkdownHelp -Module __MODULE__ -OutputFolder "$PSScriptRoot\Docs" -Force
7075
}
7176
72-
Write-Host "Build complete."
77+
Write-Information "Build complete."
7378
'@
7479

7580
# Replace placeholder with module name
7681
$content = $content.Replace('__MODULE__', $Name)
7782

78-
# Write the build script
83+
# Write the build script using helper
7984
$buildScriptPath = Join-Path $scriptsDir 'build.ps1'
80-
Set-Content -Path $buildScriptPath -Value $content -Encoding UTF8 -Force
85+
86+
Write-FileContent -Path $buildScriptPath -Content $content -Name 'Build script'
8187
}

0 commit comments

Comments
 (0)