-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGenerate-Documentation.ps1
90 lines (74 loc) · 3.89 KB
/
Generate-Documentation.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
Using module ../src/common/Environment.psm1
Using module ../src/common/Logging.psm1
Using module Alt3.Docusaurus.Powershell
Using module PlatyPS
Invoke-RunMain $PSCmdlet {
Push-Location -Path $PSScriptRoot;
# -----------------------------------------------------------------------------
# Use below settings to manipulate the rendered MDX files
# -----------------------------------------------------------------------------
$Local:DocusaurusOptions = @{
DocsFolder = '../docs/docs'
EditUrl = ''
Exclude = @()
MetaDescription = 'Help page for the "%1" command'
MetaKeywords = @('PowerShell', 'Help', 'Documentation')
}
Invoke-Info 'Removing existing MDX files';
$Local:OutputFolder = Join-Path -Path $Local:DocusaurusOptions.DocsFolder -ChildPath ('modules' | Join-Path -ChildPath '*.*');
if (Test-Path -Path $Local:OutputFolder) {
Remove-Item -Path $Local:OutputFolder;
}
$Local:OutputFolder = Join-Path -Path $Local:DocusaurusOptions.DocsFolder -ChildPath ('scripts' | Join-Path -ChildPath '*.*');
if (Test-Path -Path $Local:OutputFolder) {
Remove-Item -Path $Local:OutputFolder;
}
# -----------------------------------------------------------------------------
# Generate the new MDX Files for each module
# -----------------------------------------------------------------------------
$Local:Modules = Get-ChildItem -Path '../src/' -Include '*.psm1' -File -Recurse | ForEach-Object { $_ } | Sort-Object;
foreach ($Local:Module in $Local:Modules) {
$Local:ModuleDocusaurusOptions = $Local:DocusaurusOptions.Clone();
$Local:ModuleDocusaurusOptions.Module = $Local:Module.BaseName;
$Local:Parents = $Local:Module.DirectoryName.Split('\src\')[1];
$Local:ModuleDocusaurusOptions.SideBar = "modules/$Local:Parents/$($Local:Module.BaseName)";
Invoke-Info "Generating new MDX files for module: $($Local:Module.BaseName) in $Local:Parents";
try {
New-DocusaurusHelp @Local:ModuleDocusaurusOptions;
} catch {
Invoke-Error "Failed to generate MDX files for module: $($Local:Module.BaseName) in $Local:Parents";
}
Invoke-Info 'Render completed successfully';
}
# -----------------------------------------------------------------------------
# Generate the new MDX Files for each script
# -----------------------------------------------------------------------------
$Local:Scripts = Get-ChildItem -Path '../src/' -Include '*.ps1' -File -Recurse | ForEach-Object { $_ } | Sort-Object;
foreach ($Local:Script in $Local:Scripts) {
$Local:ScriptDocusaurusOptions = $Local:DocusaurusOptions.Clone();
$Local:ScriptDocusaurusOptions.Module = $Local:Script.BaseName;
$Local:Parents = $Local:Script.DirectoryName.Split('\src\')[1];
$Local:ScriptDocusaurusOptions.SideBar = "scripts/$Local:Parents/$($Local:Script.BaseName)";
Invoke-Info "Generating new MDX files for script: $($Local:Script.BaseName) in $Local:Parents";
try {
New-DocusaurusHelp @Local:ScriptDocusaurusOptions;
} catch {
Invoke-Error "Failed to generate MDX files for script: $($Local:Script.BaseName) in $Local:Parents";
}
Invoke-Info 'Render completed successfully';
}
# -----------------------------------------------------------------------------
# Generate the Sidebar file
# -----------------------------------------------------------------------------
$Local:Sidebar = '../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 $Local:Sidebar -Force;
Pop-Location;
}