src/New-ModuleFromTemplate.ps1

<#
.Synopsis
   Creates a new PowerShell module from a Plaster template.
.DESCRIPTION
   The cmdlet is a wrapper for creating PowerShell modules with a defined structure based on a Plaster template file.
    
.EXAMPLE
   New-ModuleFromTemplate -DestinationPath .\SampleProject -ModuleName mymodule -Description "This is a test" -GitHub
 
   This example shows an invocation with the mandatory parameters only for creating a PowerShell module inside a GitHub project.
 
   The following lines show the output generated by the Invoke-Plaster cmdlet when executing the above example.
   -----------------------------------------------------------------
   Destination path: C:\tmp\SampleProject
        Create .gitignore
        Create appveyor.yml
        Create LICENSE
        Create README.md
        Create mymodule\mymodule.psm1
        Create mymodule\src\
        Create mymodule\tests\
        Update LICENSE
        Update README.md
        Modify README.md into temp file before copying to destination
        Update README.md
        Create mymodule\mymodule.psd1
        Modify mymodule\mymodule.psd1 into temp file before copying to destination
        Update mymodule\mymodule.psd1
 
   Your new PowerShell module project 'mymodule' has been created.
   -----------------------------------------------------------------
   The invocation example from above creates the following module structur:
     
    .\SampleProject\
        |--mymodule\
            |--src\
            |--tests\
            |--mymodule.psd1
            |--mymodule.psm1
        |--.gitignore
        |--appveyor.yml
        |--LICENSE
        |--README.md
    
.EXAMPLE
   New-ModuleFromTemplate -DestinationPath . -ModuleName mymodule -Description "This is a test"
 
   This example shows an invocation with the mandatory parameters only.
 
   The following lines show the output generated by the Invoke-Plaster cmdlet when executing the above example.
   -----------------------------------------------------------------
   Destination path: C:\tmp\mymodule
        Create mymodule\mymodule.psm1
        Create mymodule\src\
        Create mymodule\tests\
        Create mymodule\mymodule.psd1
        Modify mymodule\mymodule.psd1 into temp file before copying to destination
        Update mymodule\mymodule.psd1
 
   Your new PowerShell module project 'mymodule' has been created.
   -----------------------------------------------------------------
   The invocation example from above creates the following module structur:
     
    .\mymodule\
        |--src\
        |--tests\
        |--mymodule.psd1
        |--mymodule.psm1
#>

function New-ModuleFromTemplate
{
    [CmdletBinding()]
    Param(
        # Specifies the path to the location of the newly created PowerShell Module.
        [Parameter(Mandatory)]
        [string]
        $DestinationPath,

        # Specifies the name of the new PowerShell Module.
        [Parameter(Mandatory)]
        [string]
        $ModuleName,

        # Specifies the description used to insert into the new PowerShell Module Manifest file.
        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [string]
        $Description,

        # Specifies the author used to insert into the new PowerShell Module Manifest file.
        [Parameter()]
        [ValidateNotNullOrEmpty()]
        [string]
        $Author,

        # Specifies the version number used to insert into the new PowerShell Module Manifest file.
        [Parameter()]
        [string]
        $Version,

        # Specifies the company name used to insert into the new PowerShell Module Manifest file.
        [Parameter()]
        [string]
        $Company,

        # Specifies the minimum required PowerShell version used to insert into the new PowerShell Module Manifest file.
        [Parameter()]
        [string]
        $PowerShellVersion,

        # Specifies if the required parameters defined in the Plaster template will be prompted using the Invoke-Plaster function.
        [Parameter()]
        [switch]
        $NoPrompt,

        # Creates a GitHub project for your new PowerShell module.
        [Parameter()]
        [switch]
        $GitHub
    )

    # Adds all passed mandatory parameters to the parameter hashtable
    $PlasterParameters = Add-MandatoryParameters $MyInvocation @{
        TemplatePath = "${PSScriptRoot}\NewModuleTemplate\"
    }

    # Create links for non mandatory parameters and default values to Invoke-Plaster parameter names
    # which will then be used for decision making based on the NoPrompt parameter and passed values
    $PlasterParameters = Add-NonMandatoryParameters $PlasterParameters $NoPrompt.IsPresent @{
        Author = @{ Passed = $Author; Default = 'Unknown' }
        Version = @{ Passed = $Version; Default = '0.1.0' }
        Company = @{ Passed = $Company; Default = 'Unknown' }
        PowerShellVersion = @{ Passed = $PowerShellVersion; Default = 'None' }
    }

    if ($GitHub.IsPresent){
        # 0 for GitHub
        $projectType = 'GitHub'        
    }
    else {
        # 1 for None
        $projectType = 'None' 
    }
    $PlasterParameters.Add('ProjectType', $projectType)

    Invoke-Plaster @PlasterParameters -Force -NoLogo
}