Repository navigation
Expand file tree
/
Copy pathSixel.build.ps1
More file actions
128 lines (108 loc) · 4.79 KB
/
Copy pathSixel.build.ps1
File metadata and controls
128 lines (108 loc) · 4.79 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
#! /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$'
$script:folders = @{
ModuleName = $modulename
ProjectRoot = $PSScriptRoot
SourcePath = Join-Path $PSScriptRoot 'src' $modulename
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' $modulename "$modulename.csproj"
}
task Reset {
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
}
$ModuleFile = Import-PowerShellDataFile -Path (Join-Path $script:folders.ProjectRoot 'Module' "$($script:folders.ModuleName).psd1")
[xml]$csproj = Get-Content -Path $folders.CsprojPath -Raw
$frameworks = $csproj.
SelectNodes('//TargetFramework | //TargetFrameworks').
'#text'.
Split(';', [StringSplitOptions]::RemoveEmptyEntries)
$dotnetArgs = @(
'publish'
$folders.CsprojPath
'--configuration', $Configuration
'--nologo'
'--verbosity', 'minimal'
('-p:Version={0}' -f $ModuleFile.ModuleVersion.ToString())
)
foreach ($fwork in $frameworks) {
exec { dotnet @dotnetArgs --framework $fwork --output (Join-Path $folders.DestinationPath $fwork) }
}
}
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
}
$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 CleanAfter {
if ($script:folders.DestinationPath -and (Test-Path $script:folders.DestinationPath)) {
Get-ChildItem -Path $script:folders.DestinationPath -File -Recurse |
Where-Object { $_.Extension -in @('.pdb', '.json') } |
Remove-Item -Force -ErrorAction Ignore
}
}
task All -Jobs Reset, Build, ModuleFiles, GenerateHelp, CleanAfter, Test