-
Notifications
You must be signed in to change notification settings - Fork 54
/
build.ps1
49 lines (42 loc) · 1.79 KB
/
build.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
#requires -Module Configuration
<#
.Synopsis
A bootstrapping build, for when an existing ModuleBuilder can't be used to build ModuleBuilder
#>
[CmdletBinding()]
param(
# A specific folder to build into
$OutputDirectory,
# The version of the output module
[Alias("ModuleVersion")]
[string]$SemVer
)
# Sanitize parameters to pass to Build-Module
$ErrorActionPreference = "Stop"
Push-Location $PSScriptRoot -StackName BuildBuildModule
if (-not $Semver) {
if ($semver = gitversion -showvariable SemVer) {
$null = $PSBoundParameters.Add("SemVer", $SemVer)
}
}
try {
# Build ModuleBuilder with ModuleBuilder:
Write-Verbose "Compiling ModuleBuilderBootstrap module"
$OFS = "`n`n"
$Source = Get-ChildItem Source -File -Recurse -Filter *.ps1 |
Sort-Object DirectoryName, Name |
Get-Content -Encoding UTF8 -Delimiter ([char]0)
$Source += "`nExport-ModuleMember -Function *-*"
Get-Module ModuleBuilderBootstrap -ErrorAction Ignore | Remove-Module
New-Module ModuleBuilderBootstrap ([ScriptBlock]::Create($Source)) |
Import-Module -Verbose:$false -DisableNameChecking
# Build new output
$ParameterString = $PSBoundParameters.GetEnumerator().ForEach{ '-' + $_.Key + " '" + $_.Value + "'" } -join " "
Write-Verbose "Build-Module build.psd1 $($ParameterString) -Target CleanBuild"
ModuleBuilderBootstrap\Build-Module -SourcePath build.psd1 @PSBoundParameters -Target CleanBuild -Passthru -OutVariable BuildOutput | Split-Path
Write-Verbose "Module build output in $(Split-Path $BuildOutput.Path)"
# Clean up environment
Remove-Module ModuleBuilderBootStrap -ErrorAction SilentlyContinue -Verbose:$false
} finally {
Pop-Location -StackName BuildBuildModule
}