forked from PoshCode/ModuleBuilder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ps1
More file actions
56 lines (45 loc) · 2.09 KB
/
Copy pathbuild.ps1
File metadata and controls
56 lines (45 loc) · 2.09 KB
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
[CmdletBinding()]
param(
$OutputDirectory = "Output\ModuleBuilder",
$ModuleVersion = "1.0.0"
)
Write-Verbose "BUILDING $(Split-Path $PSScriptRoot -Leaf) VERSION $ModuleVersion" -Verbose
$ErrorActionPreference = "Stop"
Push-Location $PSScriptRoot -StackName BuildBuildModule
try {
# This is a bootstrap hack:
Write-Verbose "Bootstrap hack for building ModuleBuilder with ModuleBuilder"
$OFS = "`n`n"
$Source = Get-ChildItem Source -Directory | Sort-Object Name |
Get-ChildItem -File -Filter *.ps1 -Recurse |
Get-Content
Get-Module ModuleBuilderBootStrap | Remove-Module
[ScriptBlock]::Create("
New-Module ModuleBuilderBootStrap {
$Source
Export-ModuleMember -Function *-*
}
").Invoke() | Import-Module -Verbose:$false
# Restore dependencies
if (-not (Get-Module PSDepend -ListAvailable)) {
Install-Module -Name PSDepend -Scope CurrentUser -Confirm:$False -Repository PSGallery -Force
}
Invoke-PSDepend -Path $PSScriptRoot\build.depend.psd1 -Confirm:$false
Import-Module Configuration
# Clean output if necessary (always)
Write-Verbose "Cleaning output from $OutputDirectory"
Get-Item $OutputDirectory -ErrorAction SilentlyContinue | Remove-Item -Recurse -Force
# Build new output
Write-Verbose "Build-Module ModuleBuilder\Source\build.psd1 -OutputDirectory '$OutputDirectory' -ModuleVersion '$ModuleVersion'"
ModuleBuilderBootStrap\Build-Module Source\build.psd1 -OutputDirectory $OutputDirectory -ModuleVersion $ModuleVersion
# Test module
$ModulePath = (Get-Item $OutputDirectory -Filter *.psd1).FullName
Write-Verbose "Invoke-Pester after importing module from $ModulePath"
Remove-Module ModuleBuilderBootStrap, ModuleBuilder -ErrorAction SilentlyContinue -Verbose:$false
Import-Module $ModulePath -Verbose:$false
Invoke-Pester
# Clean environment after tests
Remove-Module ModuleBuilderBootStrap, ModuleBuilder -ErrorAction SilentlyContinue
} catch {
Pop-Location -StackName BuildBuildModule
}