-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerateDocs.ps1
More file actions
74 lines (63 loc) · 2.59 KB
/
generateDocs.ps1
File metadata and controls
74 lines (63 loc) · 2.59 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
$moduleRoot = ".\DevSetup" # Adjust as needed
$manifestPath = Join-Path $moduleRoot "DevSetup.psd1" # Adjust as needed
# Create backup of the manifest file
$backupPath = "$manifestPath.backup"
Copy-Item -Path $manifestPath -Destination $backupPath -Force
Write-Host "Created backup: $backupPath" -ForegroundColor Green
try {
$functionNames = @()
Get-ChildItem -Path $moduleRoot -Filter "*.ps1" -Recurse | ForEach-Object {
$functionNames += $_.BaseName
}
# Remove duplicates and sort for consistency
$functionNames = $functionNames | Select-Object -Unique | Sort-Object
# Read the original manifest
$manifest = Import-PowerShellDataFile $manifestPath
# Create a new manifest with updated FunctionsToExport
New-ModuleManifest -Path $manifestPath `
-RootModule $manifest.RootModule `
-ModuleVersion $manifest.ModuleVersion `
-GUID $manifest.GUID `
-Author $manifest.Author `
-CompanyName $manifest.CompanyName `
-Copyright $manifest.Copyright `
-Description $manifest.Description `
-PowerShellVersion $manifest.PowerShellVersion `
-FunctionsToExport $functionNames `
-CmdletsToExport $manifest.CmdletsToExport `
-VariablesToExport $manifest.VariablesToExport
$markdownPath = '.\DevSetup\docs'
$mamlPath = '.\DevSetup\en-US'
# Import module by manifest path instead of name
$importedModule = Import-Module -Name $manifestPath -Force -PassThru
# Get the module name for the documentation
$moduleName = $importedModule.Name
$mdHelpParams = @{
Module = $moduleName # Use module name, not path
OutputFolder = $markdownPath
AlphabeticParamsOrder = $true
UseFullTypeName = $true
WithModulePage = $true
ExcludeDontShow = $false
Encoding = [System.Text.Encoding]::UTF8
}
New-MarkdownHelp @mdHelpParams
Update-MarkdownHelp -Path $markdownPath
$extHelpParams = @{
Path = $markdownPath
OutputPath = $mamlPath
}
New-ExternalHelp @extHelpParams
Write-Host "Documentation generation completed successfully" -ForegroundColor Green
}
catch {
Write-Error "Documentation generation failed: $($_.Exception.Message)"
}
finally {
# Restore the original manifest file from backup
if (Test-Path $backupPath) {
Copy-Item -Path $backupPath -Destination $manifestPath -Force
Remove-Item -Path $backupPath -Force
Write-Host "Restored original manifest and cleaned up backup" -ForegroundColor Yellow
}
}