Public/New-PsFunction.ps1
function New-PsFunction { <# .Synopsis A function that creates a function.ps1 and function.Tests.ps1 file stub .DESCRIPTION A function that creates a function.ps1 and function.Tests.ps1 file stub for an easy start to creating powershell modules/function in a TDD manner .EXAMPLE New-PsFunction "AwesomeModule" "Write-CleanCode" "Public" New-PsFunction "AwesomeModule" "Write-MessyCode" "Internal" New-PsFunction "AwesomeModule" "Write-CleanCode" #(defaults to 'Public') #> [CmdletBinding(SupportsShouldProcess=$true)] param ( [Parameter( Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] [string]$ModuleName, [Parameter( Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] [ValidatePattern("^[a-zA-Z]{3,}-[a-zA-Z]{3,}$")] [string]$FunctionName, [Parameter( Mandatory=$false, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] [ValidateSet("Public", "Internal")] [string]$FunctionType="Public" ) BEGIN{ . "$PSscriptRoot\Get-PsModuleBuilderPath.ps1" $path = Get-PsModuleBuilderPath Write-Debug "ModuleBuilderPath: $path" $whatifMessage = @" Creating: $path\$ModuleName\$FunctionType\$FunctionName.ps1 $path\$ModuleName\$FunctionType\$FunctionName.Tests.ps1 "@ }#begin PROCESS{ if ($psCmdlet.ShouldProcess("for module $ModuleName", $whatifMessage)) { if(!(Test-Path "$path\$ModuleName\" -PathType Container)) { Throw "The Module $ModuleName folder doesn't exist... $path\$ModuleName" } if(!(Test-Path "$path\$ModuleName\$FunctionType\" -PathType Container)) { Write-Debug "The Module $ModuleName $FunctionType folder doesn't exist... Creating $path\$ModuleName\$FunctionType" New-Item "$path\$ModuleName\$FunctionType\" -ItemType Directory -Force | Out-Null } Write-Debug $whatifMessage Invoke-Plaster -TemplatePath "$PSscriptRoot\..\Data\MetaFunction" ` -DestinationPath "$path\$ModuleName\$FunctionType" ` -FunctionName $FunctionName ` -FunctionLocation "$path\$ModuleName\$FunctionType" ` -NoLogo ` -Force } }#process END{}#end } |