Public/New-SpecModule.ps1

function New-SpecModule {
    <#
    .SYNOPSIS
    Creates a new PowerShell module with standard files and structure.
 
    .DESCRIPTION
    The New-SpecModule function creates a new PowerShell module with a standardized structure. It generates the necessary folders, module loader (.psm1) file, module help content, module manifest (.psd1) file, README.md file, and tests.ps1 file within the module's root directory.
 
    .PARAMETER moduleName
    Specifies the name of the module.
 
    .PARAMETER modulePath
    Specifies the path where the module's root directory should be created.
 
    .PARAMETER moduleShortDescription
    Specifies a short description of the module.
 
    .PARAMETER DisplayDirectoryTree
    Switch parameter. If specified, displays the file tree structure of the module's directory.
 
    .EXAMPLE
    New-SpecModule -moduleName "MyModule" -modulePath "C:\Path\To\Module" -moduleShortDescription "This module provides various utilities for XYZ." -DisplayDirectoryTree
 
    This example creates a new PowerShell module named "MyModule" with standardized files and structure located at "C:\Path\To\Module" and displays the directory tree structure.
 
    The following structure is created:
 
    C:\Path\To\Module\MyModule
    └── MyModule
        ├── en-US
        │ └── about_MyModule.help.txt
        ├── Private
        ├── Public
        ├── MyModule.psd1
        └── MyModule.psm1
    ├── Tests
    │ └── MyModule.tests.ps1
    ├── README.md
 
    .NOTES
    Author : owen.heaume
    Version : 1.1
    #>


    [cmdletbinding()]

    param (
        [parameter (mandatory = $true, Position = 0)]
        [string]$moduleName,

        [parameter (mandatory = $true, Position = 1)]
        [string]$modulePath,

        [parameter (mandatory = $true, Position = 2)]
        [string]$moduleShortDescription,

        [Switch]$DisplayDirectoryTree
    )

    # Create folder structure
    $fullModulePath = Join-Path "$modulePath\$modulename" $moduleName
    if (!(Test-Path $fullModulePath)) {
        Write-host "creating module directory structure..." -ForegroundColor DarkCyan
        $FoldersCreated = new-SpecModuleStructure -modulename $moduleName -modulepath $modulePath
    } else {
        Write-Warning "Path already exists. Please choose a different path or module name."
        $FoldersCreated = $false
    }

    #initialise other vars
    $PSM1Created = $false
    $moduleHelpCreated = $false
    $psd1Created = $false

    if ($FoldersCreated) {
        write-host "OK" -ForegroundColor DarkGreen
        #Creating .psm1 module loader
        write-host "Creating .psm1 file..." -ForegroundColor DarkCyan
        $PSM1Created = Add-SpecPSM1 -moduleName $moduleName -modulePath $modulePath

        if ($PSM1Created) {
            write-host "OK" -ForegroundColor DarkGreen
            # Create module help file template
            write-host "Creating module help file..." -ForegroundColor DarkCyan
            $moduleHelpCreated = Add-SpecModuleHelp -moduleName $moduleName -modulePath $modulePath -moduleShortDescription $moduleShortDescription
        } else {
            write-host "Module help file was not created" -ForegroundColor DarkYellow
        }

        if ($moduleHelpCreated) {
            write-host "OK" -ForegroundColor DarkGreen
            # Create .psd1 module manifest file
            write-host "Creating module manifest file..." -ForegroundColor DarkCyan
            $psd1Created = new-specModuleManifest -moduleName $moduleName -modulePath $modulePath -moduleShortDescription $moduleShortDescription
        } else {
            write-host "Unable to create module manifest file" -ForegroundColor DarkYellow
        }

        if ($psd1Created) {
            # Create README.md
            write-host "OK" -ForegroundColor DarkGreen
            write-host "Creating module README.md file..." -ForegroundColor DarkCyan
            $readmeCreated = Add-SpecReadMeFile -moduleName $moduleName -modulePath $modulePath
        } else {
            write-host "Unable to create README.md file" -ForegroundColor DarkYellow
        }

        if ($readmeCreated) {
            # Create .tests.ps1 file
            write-host "OK" -ForegroundColor DarkGreen
            write-host "Creating $moduleName.tests.ps1 file..." -ForegroundColor DarkCyan
            $testsCreated = new-SpecTestsPS1File -moduleName $moduleName -modulePath $modulePath
        } else {
            write-host "Unable to create $moduleName.tests.ps1 file" -ForegroundColor DarkYellow
        }

        if ($testsCreated) {
            write-host "OK" -ForegroundColor DarkGreen
            write-host "Finished Processing!`n" -ForegroundColor Darkcyan
            if ($DisplayDirectoryTree.IsPresent) { Get-SpecFileTree -moduleName $moduleName -modulePath $modulePath }
        } else {
            write-host "Unable to create tests.ps1 file" -ForegroundColor DarkYellow
        }
    }

}