1+ # requires -version 7.2
12[CmdletBinding (ConfirmImpact = ' High' )]
23param (
4+ # Specify this to explicitly specify the version of the package
5+ [Management.Automation.SemanticVersion ]$Version = ' 0.0.0-SOURCE' ,
6+ # You Generally do not need to modify these
37 $Destination = (Join-Path $PSScriptRoot ' Build' ),
48 $ModuleOutFolderPath = (Join-Path $Destination ' ModuleFast' ),
59 $TempPath = (Resolve-Path temp:).ProviderPath + ' \ModuleFastBuild' ,
@@ -36,8 +40,17 @@ Task CopyFiles {
3640 ' ModuleFast.psm1'
3741 ' LICENSE'
3842 ) - Destination $ModuleOutFolderPath
43+ Copy-Item @c - Path ' ModuleFast.ps1' - Destination $Destination
44+ }
45+
46+ Task Version {
47+ # This task only runs if a custom version is needed
48+ if (-not $Version ) { return }
3949
40- Copy-Item ' ModuleFast.ps1' - Destination $Destination - Force
50+ $moduleVersion , $prerelease = $Version -split ' -'
51+ $manifestPath = Join-Path $ModuleOutFolderPath ' ModuleFast.psd1'
52+ $manifestContent = (Get-Content - Raw $manifestPath ) -replace [regex ]::Escape(' ModuleVersion = '' 0.0.0'' ' ), " ModuleVersion = '$moduleVersion '" -replace [regex ]::Escape(' Prerelease = '' SOURCE'' ' ), ($Prerelease ? " Prerelease = '$prerelease '" : ' ' )
53+ $manifestContent | Set-Content - Path $manifestPath
4154}
4255
4356Task GetNugetVersioningAssembly {
@@ -63,8 +76,8 @@ Task Build @(
6376 ' AddNugetVersioningAssemblyRequired'
6477)
6578
66- Task Package {
67- [string ]$repoName = " ModuleFastBuild-" + (New-Guid )
79+ Task Package.Nuget {
80+ [string ]$repoName = ' ModuleFastBuild-' + (New-Guid )
6881 Get-ChildItem $ModuleOutFolderPath - Recurse - Include ' *.nupkg' | Remove-Item @c - Force
6982 try {
7083 Register-PSResourceRepository - Name $repoName - Uri $NugetOutFolderPath - ApiVersion local
@@ -74,5 +87,32 @@ Task Package {
7487 }
7588}
7689
90+ Task Package.Zip {
91+ $zipPath = Join-Path $Destination " ModuleFast.${Version} .zip"
92+ if (Test-Path $zipPath ) {
93+ Remove-Item @c - Path $zipPath
94+ }
95+ Compress-Archive @c - Path $ModuleOutFolderPath - DestinationPath $zipPath
96+ }
97+
98+ Task Pester {
99+ # Run this in a separate job so as not to lock any NuGet DLL packages for future runs. Runspace would lock the package to this process still.
100+ Start-Job {
101+ Invoke-Pester
102+ } | Receive-Job - Wait - AutoRemoveJob
103+ }
104+
105+ Task Package Package.Nuget, Package.Zip
106+
107+ # Supported High Level Tasks
108+ Task Build @ (
109+ ' Clean'
110+ ' CopyFiles'
111+ ' Version'
112+ ' GetNugetVersioningAssembly'
113+ ' AddNugetVersioningAssemblyRequired'
114+ )
115+
116+ Task Test Build, Pester
77117Task . Build, Test, Package
78118Task BuildNoTest Build, Package
0 commit comments