ps/Modules/build-project.ps1

78 lines
3.1 KiB
PowerShell
Raw Permalink Normal View History

2023-05-30 22:51:22 -07:00
<#
.SYNOPSIS
Runs a build on a given project in the Alkami.PowerShell module system
.EXAMPLE
.\build-project.ps1 .\Alkami.PowerShell.IIS\
.PARAMETER FolderPath
The name of the folder to examine all files under
.PARAMETER Configuration
The MSBuild build configuration to use. Typically Release or Debug
.PARAMETER CleanFirst
Should MSBuild clean the project first?
.PARAMETER AsBuildServer
Run the tests on a developer machine as a build server
#>
[CmdletBinding()]
Param(
$FolderPath,
$Configuration = "Release",
[switch]$CleanFirst,
[switch]$AsBuildServer
)
process {
. $PSScriptRoot\.build\Load-Includes.ps1
#$nugetPath = Join-Path -Path (Join-Path -Path $PSScriptRoot -ChildPath ".nuget") -ChildPath "NuGet.exe"
Write-Verbose "Examining project located at $FolderPath";
## Run the full build when this isn't on the build server, because the build-server does other things
$csprojPaths = (Get-ChildItem *.csproj -Path $FolderPath)
if (!$AsBuildServer -and (@($csprojPaths).Count -gt 0)) {
Write-Host "Running msbuild in $FolderPath" -ForegroundColor Green
foreach($csprojPath in $csprojPaths) {
if ($CleanFirst) {
$buildConfigs = (Get-BuildConfigs (Join-Path $FolderPath $csprojPath))
foreach($buildConfig in $buildConfigs) {
& (Get-MSBuildPath) $csprojPath.FullName /m /t:Clean /p:"Configuration=$buildConfig" /clp:ErrorsOnly /nologo
}
}
& nuget restore $csprojPath.FullName -PackagesDirectory (Join-Path $PSScriptRoot packages) -Verbosity quiet
& (Get-MSBuildPath) $csprojPath.FullName /nr:true /t:rebuild /p:"Configuration=$Configuration;AllowedReferenceRelatedFileExtensions=pdb;ExcludeFromBuild=`"Test`";optimize=$true;PostBuildEvent=`"`";PreBuildEvent=`"`"" /clp:ErrorsOnly /v:q /nologo
}
return $null
} else {
$publicPath = (Join-Path $FolderPath Public)
$privatePath = (Join-Path $FolderPath Private)
if (Test-Path $publicPath) {
$psStopWatch = [System.Diagnostics.Stopwatch]::StartNew()
Write-Host "Processing PowerShell module $FolderPath" -ForegroundColor Green
$psdName = (Split-Path $FolderPath -Leaf)
$psd1Filename = $psdName + ".psd1"
$psd1Filepath = (Join-Path $FolderPath $psd1Filename)
$psm1Filename = $psdName + ".psm1"
$psm1Filepath = (Join-Path $FolderPath $psm1Filename)
$ps1xmlFilename = $psdName + ".ps1xml"
$ps1xmlFilepath = (Join-Path $FolderPath $ps1xmlFilename)
Test-FunctionNames $publicPath
Update-FunctionNamesInPSD1 $publicPath $psd1Filepath
Update-AliasesInPSD1 $publicPath $psd1Filepath
Join-PSM1FromFiles $publicPath $privatePath $psm1Filepath
Join-PS1XMLFromFiles $publicPath $ps1xmlFilepath
Update-FormatsToProcessInPSD1 $publicPath $psd1Filepath
Write-Host "Done processing PowerShell module after $($psStopWatch.Elapsed)" -ForegroundColor Green
$psStopWatch.Stop()
}
}
}