src/New-ModuleFromTemplate.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
<#
.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 } |