-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpsakeFile.ps1
More file actions
147 lines (129 loc) · 4.45 KB
/
psakeFile.ps1
File metadata and controls
147 lines (129 loc) · 4.45 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
#require -Version 7
$ErrorView = 'Detailed'
Version 5
Properties {
$script:OutputPath = $null
$script:OutputFormat = 'Nunit'
$script:psakeVersion = (Get-Module psake).Version
# -----------------------------------------------------------------------------
# Use below settings to manipulate the rendered MDX files
# -----------------------------------------------------------------------------
$script:docusaurusOptions = @{
Module = "Psake"
DocsFolder = "./docs"
SideBar = "commands"
EditUrl = "null" # prevent the `Edit this Page` button from appearing
Exclude = @()
MetaDescription = 'Help page for the PowerShell Psake "%1" command'
MetaKeywords = @(
"PowerShell"
"Psake"
"Help"
"Documentation"
)
PrependMarkdown = @"
:::info This page was generated
Contributions are welcome in [Psake-repo](https://github.com/psake/psake).
:::
"@
AppendMarkdown = @"
## VERSION
*This page was generated using comment-based help in [Psake $($psakeVersion)](https://github.com/psake/psake).*
"@
}
$script:docsOutputFolder = Join-Path -Path $docusaurusOptions.DocsFolder -ChildPath $docusaurusOptions.Sidebar | Join-Path -ChildPath "*.*"
}
FormatTaskName {
param($taskName)
Write-Host 'Task: ' -ForegroundColor Cyan -NoNewline
Write-Host $taskName.ToUpper() -ForegroundColor Blue
}
Task Default -Depends Build
Task Init -Description "Initial action to setup the further action." -Action {
Exec { bun install }
}
Task Build -Depends Init, GenerateCommandReference, FrontMatterCMSSync {
Exec { bun run build }
}
Task Server -Depends Build -Description "Run the docusaurus server." {
Exec { bun run serve }
}
Task Test {
$configuration = New-PesterConfiguration
$configuration.Output.Verbosity = 'Detailed'
$configuration.Run.PassThru = $true
$configuration.Run.Path = "$PSScriptRoot\tests"
try {
$testResult = Invoke-Pester -Configuration $configuration -Verbose
} finally {
}
if ($testResult.FailedCount -gt 0) {
throw 'One or more Pester tests failed'
}
}
(Get-Content ".\package.json" | ConvertFrom-Json -AsHashtable).scripts.Keys | ForEach-Object {
$action = [scriptblock]::create("exec { bun run $($_) }")
$taskSplat = @{
name = "bun_$($_)"
action = $action
depends = @('Init')
description = "Automatic: A script defined in your package.json"
}
Task @taskSplat
}
#region Command Reference Generation Tasks
# Copied from the amazing Pester team! https://github.com/pester/docs/blob/main/generate-command-reference.ps1
$taskSplat = @{
description = "Use Alt3.Docusaurus.Powershell module to generate our reference docs."
depends = 'GenerateCommandReference-Gen'
}
Task -Name 'GenerateCommandReference' @taskSplat
Task -Name 'GenerateCommandReference-Clean' -Action {
Write-Host "Removing existing MDX files" -ForegroundColor Magenta
if (Test-Path -Path $script:docsOutputFolder) {
Remove-Item -Path $script:docsOutputFolder
}
}
Task -Name "GenerateCommandReference-Gen" -Depends 'GenerateCommandReference-Clean' {
Write-Host "Generating new MDX files" -ForegroundColor Magenta
New-DocusaurusHelp @docusaurusOptions
# Fix the links
Get-ChildItem $script:docsOutputFolder | ForEach-Object {
$path = $_.FullName
Write-Host "Fixing relative links for: $path"
(Get-Content $path) | ForEach-Object {
$_ -replace "\[(.+)\]\(\)", '[$1]($1.mdx)'
} | Set-Content $path
}
}
#endregion Command Reference Generation Tasks
#region Sync Front Matter Data
Task -Name 'FrontMatterCMSSync' {
(
'blog/authors.yml',
'blog/tags.yml'
) | ForEach-Object {
if (-not (Test-Path $_)) {
Write-Warning "File not found: $_"
return
}
$name = $_ -replace '\.yml$', '.choices.jsonc'
$outputFile = Join-Path -Path $PSScriptRoot -ChildPath (Split-Path -Path $name -Leaf)
[array]$output = @(
@{
"_comment" = "This file is auto-generated from $_ via a psake task"
}
)
$yaml = Get-Content -Raw $_ | ConvertFrom-Yaml
foreach ($item in $yaml.Keys) {
$value = $yaml[$item]
if (-not $value.Contains('handle')) {
$value.Add('handle', $item)
}
$output += $value
}
Set-Content -Path $outputFile -Force -Value ($output | ConvertTo-Json -Depth 10)
}
# TODO: Add support to sync back from FrontMatter CMS to authors.json and tags.json
} -Description "Syncs Docusaurus JSON data from authors.json and tags.json to FrontMatter CMS friendly choices.json files."
#endregion Sync Front Matter Data