-
Notifications
You must be signed in to change notification settings - Fork 2
/
PostBuild.ps1
67 lines (61 loc) · 2.84 KB
/
PostBuild.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
#Requires -Version 5.1 -Modules platyPS
param
(
[Parameter(Mandatory)]
[string]
$OutputFile
)
$ModuleName = [System.IO.Path]::GetFileNameWithoutExtension($OutputFile)
$OutputDir = Split-Path -LiteralPath $OutputFile
$FormatFiles = Get-ChildItem -LiteralPath "$PSScriptRoot\PowerShellFormatFiles" -File | Copy-Item -Destination $OutputDir -Force -PassThru
$TypeFiles = Get-ChildItem -LiteralPath "$PSScriptRoot\PowerShellTypeFiles" -File | Copy-Item -Destination $OutputDir -Force -PassThru
$ModuleInfo = Import-Module -Name $OutputFile -PassThru -ErrorAction Stop
$CmdletsToExport = $ModuleInfo.ExportedCmdlets.Keys.ForEach({"'$_'"}) -join ','
Remove-Module -ModuleInfo $ModuleInfo
#region Create help files
$DocFiles = Get-ChildItem -LiteralPath (Join-Path -Path $PSScriptRoot -ChildPath Docs) -ErrorAction Ignore
if ($DocFiles)
{
$null = New-Item -Path "$OutputDir\en-US" -ItemType Directory -Force
$HelpFile = New-ExternalHelp -Path "$PSScriptRoot\Docs" -OutputPath "$OutputDir\en-US" -ErrorAction Stop -Force
$HelpContent = [xml]::new()
$HelpContent.Load($HelpFile.FullName)
$HelpExamples = Select-Xml -Xml $HelpContent.helpItems -XPath //command:example -Namespace @{command = "http://schemas.microsoft.com/maml/dev/command/2004/10"}
foreach ($Example in $HelpExamples)
{
# Adds 2 linebreaks between each example
for ($i = 0; $i -lt 2; $i++)
{
$Element = $HelpContent.CreateElement('maml', 'para', 'http://schemas.microsoft.com/maml/2004/10')
$null = $Example.Node.remarks.AppendChild($Element)
}
}
$HelpContent.Save($HelpFile.FullName)
}
#endregion
#region Update module manifest
$null = New-Item -Path "$OutputDir\$ModuleName.psd1" -ItemType File -Force
$FormatList = ($FormatFiles | ForEach-Object -Process {
"'$($_.Name)'"
}) -join ','
$TypeList = ($TypeFiles | ForEach-Object -Process {
"'$($_.Name)'"
}) -join ','
$FileList = (Get-ChildItem -LiteralPath $OutputDir -File -Recurse | ForEach-Object -Process {
"'$($_.FullName.Replace("$OutputDir\", ''))'"
}) -join ','
$ReleaseNotes = Get-Content -LiteralPath "$PSScriptRoot\Release notes.txt" -Raw
$Version = $ReleaseNotes.Split(':')[0]
((Get-Content -LiteralPath "$PSScriptRoot\ModuleManifest.psd1" -Raw) -replace '{(?=[^\d])','{{' -replace '(?<!\d)}','}}') -f @(
"'$Version'"
$TypeList
$FormatList
$CmdletsToExport
$FileList
$ReleaseNotes
) | Set-Content -LiteralPath "$OutputDir\$ModuleName.psd1" -Force
#endregion
$ReleaseDir = Join-Path -Path $PSScriptRoot -ChildPath "Releases\$ModuleName\$Version"
Get-Item -LiteralPath $ReleaseDir -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Stop
$null = New-Item -Path $ReleaseDir -ItemType Directory -Force
Get-ChildItem -LiteralPath $OutputDir | Copy-Item -Destination $ReleaseDir -Force -Recurse -Container -ErrorAction Stop