-
Notifications
You must be signed in to change notification settings - Fork 9
/
build.ps1
67 lines (56 loc) · 2.5 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
param(
[switch]$Force
)
$ErrorActionPreference = "Stop"
# Attempt to retrieve relevant script files
$Classes = Get-ChildItem (Join-Path $PSScriptRoot src\Classes) -ErrorAction SilentlyContinue -Filter *.class.ps1
$Public = Get-ChildItem (Join-Path $PSScriptRoot src\Public) -ErrorAction SilentlyContinue -Filter *.ps1
$Private = Get-ChildItem (Join-Path $PSScriptRoot src\Private) -ErrorAction SilentlyContinue -Filter *.ps1
# classes on which other classes might depend, must be specified in order
$ClassDependees = @(
'TimeLine'
'Profiler'
)
$publishDir = New-Item -ItemType Directory -Path (Join-Path $PSScriptRoot publish\PSProfiler) @PSBoundParameters
$moduleFile = New-Item -Path $publishDir.FullName -Name "PSProfiler.psm1" -ItemType File @PSBoundParameters
@'
using namespace System.Collections.Generic
using namespace System.Management.Automation.Language
using namespace System.Diagnostics
'@ |Add-Content -LiteralPath $moduleFile.FullName @PSBoundParameters
# import classes on which others depend first
foreach($classDependee in $ClassDependees)
{
try{
Get-Content (Join-Path (Join-Path $PSScriptRoot src\Classes) "$classDependee.class.ps1") |Where-Object {$_ -notlike 'using namespace*'} |Add-Content -LiteralPath $moduleFile.FullName @PSBoundParameters
}
catch{
Write-Error -Message "Failed to import class $($classDependee): $_"
}
}
@'
$Visitor = switch($PSVersionTable['PSVersion'].Major){
{$_ -ge 7} {
"AstVisitor7.class.ps1"
}
default {
"AstVisitor.class.ps1"
}
}
Write-Verbose "Loading '$Visitor'"
. (Join-Path $PSScriptRoot $Visitor)
'@ |Add-Content -LiteralPath $moduleFile.FullName
# dot source the functions
foreach($import in @($Public;$Private))
{
try{
$import |Get-Content |Where-Object {$_ -notlike 'using namespace*'} |Add-Content -LiteralPath $moduleFile.FullName
}
catch{
Write-Error -Message "Failed to import function $($import.fullname): $_"
}
}
"Export-ModuleMember -Function $($Public.BaseName -join ',')" |Add-Content -LiteralPath $moduleFile.FullName @PSBoundParameters
Copy-Item (Join-Path $PSScriptRoot src\PSProfiler.psd1) -Destination $publishDir.FullName @PSBoundParameters
Copy-Item (Join-Path $PSScriptRoot src\PSProfiler.format.ps1xml) -Destination $publishDir.FullName @PSBoundParameters
Copy-Item (Join-Path $PSScriptRoot src\Classes\AstVisitor*.class.ps1) -Destination $publishDir.FullName @PSBoundParameters -PassThru