-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
psakeFile.ps1
115 lines (100 loc) · 3.4 KB
/
psakeFile.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
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
#require -Version 7
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 {
yarn install
}
Task Build -depends Init, GenerateCommandReference {
yarn run build
if ($LastExitCode -ne 0) {
throw "NPM Build failed"
}
}
Task Server -depends Build -description "Run the docusaurus server." {
yarn run serve
}
Task Test {
$configuration = [PesterConfiguration]::Default
$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("yarn run $($_)")
$taskSplat = @{
name = "yarn_$($_)"
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
}
}
#region Command Reference Generation Tasks