Public/New-PSBuildPipeline.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 |
<#
.SYNOPSIS Creates a new build pipeline. .DESCRIPTION Creates build pipeline files and scaffolds base structure, to the target module. .PARAMETER Module The name of a module, or the parent path of a module manifest. .NOTES This scaffolding script is inspired by The PowerShell Build Pipeline as proposed by xainey (Michael Willis): https://xainey.github.io/2017/powershell-module-pipeline/ Written by Karl Wallenius, Redeploy AB. #> function New-PSBuildPipeline { [CmdletBinding()] param( [Parameter(Mandatory = $false, Position = 0)] [string] $Module ) begin { # Import templates from variables. $TemplatesPath = Merge-Path $PSScriptRoot, "..", "templates" . (Merge-Path $TemplatesPath, "t_build.ps1") . (Merge-Path $TemplatesPath, "t_build_settings.ps1") . (Merge-Path $TemplatesPath, "t_build_utils.ps1") . (Merge-Path $TemplatesPath, "t_gitignore.ps1") } process { $modulePath = Get-ModulePath -Path $Module $moduleName = Split-Path $modulePath -Leaf $buildFilePath = Merge-Path $modulePath, "$moduleName.build.ps1" $buildSettingsFilePath = Merge-Path $modulePath, "$moduleName.settings.ps1" $buildUtilsFilePath = Merge-Path $modulePath, "build_utils.ps1" $gitIgnoreFilePath = Merge-Path $modulePath, ".gitignore" Write-Verbose "Creating build file." [void](New-Item -Path $buildFilePath -ItemType File) $BuildFileContent -replace "<module>", "$moduleName" | Set-Content -Path $buildFilePath -Encoding utf8 Write-Verbose "Creating build settings file." [void](New-Item -Path $buildSettingsFilePath -ItemType File) $BuildSettingsFileContent -replace "<module>", "$moduleName" | Set-Content -Path $buildSettingsFilePath -Encoding utf8 Write-Verbose "Creating build utilities file." [void](New-Item -Path $buildUtilsFilePath -ItemType File) $BuildUtilsFileContent | Set-Content -Path $buildUtilsFilePath -Encoding utf8 Write-Verbose "Creating .gitignore file." [void](New-Item -Path $gitIgnoreFilePath -ItemType File) $GitIgnoreFileContent | Set-Content -Path $gitIgnoreFilePath -Encoding utf8 } } |