-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTextMate.build.ps1
More file actions
151 lines (127 loc) · 5.96 KB
/
TextMate.build.ps1
File metadata and controls
151 lines (127 loc) · 5.96 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#! /usr/bin/pwsh
#Requires -Version 7.4 -Module InvokeBuild
param(
[string]$Configuration = 'Release',
[switch]$SkipHelp,
[switch]$SkipTests
)
Write-Host "$($PSBoundParameters.GetEnumerator())" -ForegroundColor Cyan
$modulename = [System.IO.Path]::GetFileName($PSCommandPath) -replace '\.build\.ps1$'
# $modulename = 'PSTextMate'
$script:folders = @{
ModuleName = $modulename
ProjectRoot = $PSScriptRoot
TempLib = Join-Path $PSScriptRoot 'templib'
OutputPath = Join-Path $PSScriptRoot 'output'
DestinationPath = Join-Path $PSScriptRoot 'output' 'lib'
ModuleSourcePath = Join-Path $PSScriptRoot 'module'
DocsPath = Join-Path $PSScriptRoot 'docs' 'en-US'
TestPath = Join-Path $PSScriptRoot 'tests'
CsprojPath = Join-Path $PSScriptRoot 'src' 'PSTextMate' 'PSTextMate.csproj'
}
task Clean {
if (Test-Path $folders.OutputPath) {
Remove-Item -Path $folders.OutputPath -Recurse -Force -ErrorAction 'Ignore'
}
New-Item -Path $folders.OutputPath -ItemType Directory -Force | Out-Null
}
task Build {
if (-not (Test-Path $folders.CsprojPath)) {
Write-Warning 'C# project not found, skipping Build'
return
}
exec {
dotnet publish $folders.CsprojPath --configuration $Configuration --nologo --verbosity minimal --output $folders.TempLib
}
$null = New-Item -Path $folders.outputPath -ItemType Directory -Force
$rids = @('win-x64', 'osx-arm64', 'linux-x64','linux-arm64','win-arm64')
foreach ($rid in $rids) {
$ridDest = Join-Path $folders.DestinationPath $rid
$null = New-Item -Path $ridDest -ItemType Directory -Force
$nativePath = Join-Path $folders.TempLib 'runtimes' $rid 'native'
if (-not (Test-Path $nativePath -PathType Container)) {
continue
}
foreach ($nativeFile in Get-ChildItem -Path $nativePath -File) {
$destinationFile = Join-Path $ridDest $nativeFile.Name
try {
if (Test-Path $destinationFile -PathType Leaf) {
Remove-Item -Path $destinationFile -Force
}
Move-Item -Path $nativeFile.FullName -Destination $ridDest -Force
}
catch {
Write-Warning "Skipping native file update for '$destinationFile': $($_.Exception.Message)"
}
}
}
Get-ChildItem -Path $folders.TempLib -File | Move-Item -Destination $folders.DestinationPath -Force
if (Test-Path -Path $folders.TempLib -PathType Container) {
Remove-Item -Path $folders.TempLib -Recurse -Force -ErrorAction 'Ignore'
}
}
task ModuleFiles {
if (Test-Path $folders.ModuleSourcePath) {
Get-ChildItem -Path $folders.ModuleSourcePath -File | Copy-Item -Destination $folders.OutputPath -Force
}
else {
Write-Warning "Module directory not found at: $($folders.ModuleSourcePath)"
}
}
task GenerateHelp -if (-not $SkipHelp) {
if (-not (Test-Path $folders.DocsPath)) {
Write-Warning "Documentation path not found at: $($folders.DocsPath)"
return
}
if (-not (Get-Module -ListAvailable -Name Microsoft.PowerShell.PlatyPS)) {
Write-Host ' Installing Microsoft.PowerShell.PlatyPS...' -ForegroundColor Yellow
Install-Module -Name Microsoft.PowerShell.PlatyPS -Scope CurrentUser -Force -AllowClobber
}
Import-Module Microsoft.PowerShell.PlatyPS -ErrorAction Stop
$modulePath = Join-Path $folders.OutputPath ($folders.ModuleName + '.psd1')
if (-not (Test-Path $modulePath)) {
Write-Warning "Module manifest not found at: $modulePath. Skipping help generation."
return
}
Import-Module $modulePath -Force
$helpOutputPath = Join-Path $folders.OutputPath 'en-US'
New-Item -Path $helpOutputPath -ItemType Directory -Force | Out-Null
$allCommandHelp = Get-ChildItem -Path $folders.DocsPath -Filter '*.md' -Recurse -File |
Where-Object { $_.Name -ne "$($folders.ModuleName).md" } |
Import-MarkdownCommandHelp
if ($allCommandHelp.Count -gt 0) {
$tempOutputPath = Join-Path $helpOutputPath 'temp'
Export-MamlCommandHelp -CommandHelp $allCommandHelp -OutputFolder $tempOutputPath -Force | Out-Null
$generatedFile = Get-ChildItem -Path $tempOutputPath -Filter '*.xml' -Recurse -File | Select-Object -First 1
if ($generatedFile) {
Move-Item -Path $generatedFile.FullName -Destination $helpOutputPath -Force
}
Remove-Item -Path $tempOutputPath -Recurse -Force -ErrorAction SilentlyContinue
}
}
task Test -if (-not $SkipTests) {
if (-not (Test-Path $folders.TestPath)) {
Write-Warning "Test directory not found at: $($folders.TestPath)"
return
}
Import-Module (Join-Path $folders.OutputPath ($folders.ModuleName + '.psd1')) -ErrorAction Stop
Import-Module (Join-Path $folders.TestPath 'testhelper.psm1') -ErrorAction Stop
$pesterConfig = New-PesterConfiguration
# $pesterConfig.Output.Verbosity = 'Detailed'
$pesterConfig.Run.Path = $folders.TestPath
$pesterConfig.Run.Throw = $true
$pesterConfig.Debug.WriteDebugMessages = $false
Invoke-Pester -Configuration $pesterConfig
}
task DotNetTest -if (-not $SkipTests) {
exec {
dotnet test (Join-Path $PSScriptRoot 'tests' 'PSTextMate.InteractiveTests' 'PSTextMate.InteractiveTests.csproj') --configuration $Configuration --nologo
}
}
task CleanAfter {
if ($script:folders.DestinationPath -and (Test-Path $script:folders.DestinationPath)) {
Get-ChildItem $script:folders.DestinationPath -File -Recurse | Where-Object { $_.Extension -in '.pdb', '.json' } | Remove-Item -Force -ErrorAction Ignore
}
}
task All -Jobs Clean, Build, ModuleFiles, GenerateHelp, CleanAfter, Test, DotNetTest
task BuildAndTest -Jobs Clean, Build, ModuleFiles, CleanAfter #, Test