-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenerate-Documentation.ps1
More file actions
84 lines (72 loc) · 3.21 KB
/
Generate-Documentation.ps1
File metadata and controls
84 lines (72 loc) · 3.21 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
Using module Alt3.Docusaurus.Powershell
Using module PlatyPS
Set-StrictMode -Version Latest;
# -----------------------------------------------------------------------------
# Use below settings to manipulate the rendered MDX files
# -----------------------------------------------------------------------------
$DocusaurusOptions = @{
DocsFolder = Resolve-Path "$PSScriptRoot/../docs/docs"
EditUrl = "null"
Exclude = @()
MetaDescription = 'Help page for the "%1" command'
MetaKeywords = @('PowerShell', 'Help', 'Documentation')
}
Write-Output 'Removing existing MDX files';
$OutputFolder = $DocusaurusOptions.DocsFolder | Join-Path -ChildPath 'modules';
if (Test-Path -Path $OutputFolder) {
Remove-Item -Path $OutputFolder -Recurse -Force;
}
$OutputFolder = $DocusaurusOptions.DocsFolder | Join-Path -ChildPath 'scripts';
if (Test-Path -Path $OutputFolder) {
Remove-Item -Path $OutputFolder -Recurse -Force;
}
$TempFolder = Join-Path -Path ([System.IO.Path]::GetTempPath()) -ChildPath 'Alt3.Docusaurus.Powershell';
if (Test-Path -Path $TempFolder) {
Remove-Item -Path $TempFolder -Recurse -Force;
}
# -----------------------------------------------------------------------------
# Generate the new MDX Files for each module
# -----------------------------------------------------------------------------
# TODO - Add support for scripts
$Slash = [System.IO.Path]::DirectorySeparatorChar;
$Modules = Get-ChildItem -Path "$PSScriptRoot/../src/" -Include '*.psm1' -File -Recurse |
Where-Object { $_.FullName -notlike "*${Slash}Compiler${Slash}*" };
foreach ($Module in $Modules) {
$ModuleDocusaurusOptions = $DocusaurusOptions.Clone();
$ModuleDocusaurusOptions.Module = $Module.BaseName;
$Parents = $Module.DirectoryName.Split("${Slash}src${Slash}")[1];
$Type = $Module.Extension -eq '.psm1' ? 'module' : 'script';
$ModuleDocusaurusOptions.SideBar = "$Type/$Parents/$($Module.BaseName)";
Write-Output "Generating new MDX files for module: $($Module.BaseName) in $Parents";
try {
$Error.clear()
try {
Import-Module -Name $Module.FullName -Force -ErrorAction Stop;
} catch {
$Errs = $Error.clone();
Write-Error "Unable to import $($Module.FullName)"
Write-Error "Possible errors:"
Write-Output $Errs
continue
}
New-DocusaurusHelp @ModuleDocusaurusOptions;
} catch {
Write-Error "Failed to generate MDX files for module: $($Module.BaseName) in $Parents" -ErrorAction Continue;
Write-Error $_ -ErrorAction Continue;
} finally {
Remove-Module -Name $Module.BaseName -Force -ErrorAction SilentlyContinue;
}
}
# -----------------------------------------------------------------------------
# Generate the Sidebar file
# -----------------------------------------------------------------------------
$Sidebar = "$PSScriptRoot/../docs/sidebars.js";
@'
// @ts-check
/** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */
const sidebars = {
ModulesSidebar: [{type: 'autogenerated', dirName: 'modules'}],
ScriptsSidebar: [{type: 'autogenerated', dirName: 'scripts'}],
};
export default sidebars;
'@ | Set-Content -Path $Sidebar -Force;