Public/New-ModuleTemplate.ps1

<#
.SYNOPSIS
    Creates a full or minimal PowerShell module project scaffold.

.DESCRIPTION
    Generates a complete, professional PowerShell module structure including:
    - Public and Private function folders
    - Optional Tests folder with Pester scaffolding
    - Optional Docs folder for PlatyPS help
    - Optional Analyzer folder with PSScriptAnalyzer settings
    - Optional Scripts folder containing build/publish/documentation scripts
    - Module manifest and loader (.psd1 / .psm1)
    - Optional Git initialization

    The default behavior creates a full module scaffold. Switches allow disabling
    individual components or generating a minimal template.

.PARAMETER Path
    The directory where the module folder will be created.

.PARAMETER Name
    The name of the module. Used for folder creation, manifest generation,
    documentation, and all scaffolding components.

.PARAMETER Minimal
    Generates only the essential module components:
    - Public/Private folders
    - Manifest
    - Loader
    - README
    - Changelog
    Skips tests, docs, analyzer settings, and scripts.

.PARAMETER Force
    Overwrites an existing module folder if it already exists.

.PARAMETER NoGit
    Disables Git initialization even if -InitGit is specified.

.PARAMETER NoTests
    Skips generating Pester test scaffolding.

.PARAMETER NoDocs
    Skips generating PlatyPS documentation scripts and Docs folder.

.PARAMETER NoAnalyzer
    Skips generating PSScriptAnalyzer settings.

.PARAMETER NoScripts
    Skips generating build, publish, and documentation scripts.

.EXAMPLE
    New-ModuleTemplate -Path "C:\Projects" -Name "MyModule"

.EXAMPLE
    New-ModuleTemplate -Path "C:\Projects" -Name "MyModule" -Minimal

.EXAMPLE
    New-ModuleTemplate -Path "C:\Projects" -Name "MyModule" -Force

.NOTES
    This is the orchestrator for all scaffolding functions.
    Folder creation is handled by New-ModuleFolders.
    The module loader is generated by New-ModuleLoader.
#>

function New-ModuleTemplate {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory)]
        [string]$Path,

        [Parameter(Mandatory)]
        [string]$Name,

        [switch]$Minimal,
        [switch]$Force,
        [switch]$NoGit,
        [switch]$NoTests,
        [switch]$NoDocs,
        [switch]$NoAnalyzer,
        [switch]$NoScripts
    )

    $moduleRootPath = Join-Path $Path $Name

    # Handle -Force overwrite
    $moduleExists = Test-Path $moduleRootPath
    if ($moduleExists -and -not $Force) {

        throw "Module path '$moduleRootPath' already exists. Use -Force to overwrite."
    }

    # Create folder structure
    $moduleroot = New-ModuleFolders `
        -Path $Path `
        -Name $Name `
        -Minimal:$Minimal `
        -NoTests:$NoTests `
        -NoDocs:$NoDocs `
        -NoAnalyzer:$NoAnalyzer `
        -NoScripts:$NoScripts


    # Always generate core module components
    New-ModuleManifestFile -ModulePath $moduleroot -Name $Name
    New-ModuleLoader       -ModulePath $moduleroot -Name $Name
    New-ModuleReadme       -ModulePath $moduleroot -Name $Name
    New-ModuleChangelog    -ModulePath $moduleroot

    # Skip advanced scaffolding if -Minimal is used
    if (-not $Minimal) {

        if (-not $NoTests) {
            New-PesterTests -ModulePath $moduleroot -Name $Name
        }

        if (-not $NoAnalyzer) {
            New-AnalyzerSettings -ModulePath $moduleroot
        }

        if (-not $NoDocs) {
            New-DocumentationScripts -ModulePath $moduleroot -Name $Name
        }

        if (-not $NoScripts) {
            New-BuildScript   -ModulePath $moduleroot -Name $Name
            New-PublishScript -ModulePath $moduleroot -Name $Name
        }

        if (-not $NoGit) {
            Initialize-GitRepository -ModulePath $moduleroot
        }
    }

    Write-Information "Module '$Name' created at $moduleroot"
}