|
| 1 | +# Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +# Licensed under the MIT License. |
| 3 | +Param( |
| 4 | + $ModulesToGenerate = @(), |
| 5 | + [string] $ModuleMappingConfigPath = (Join-Path $PSScriptRoot "../microsoftgraph/config/ModulesMapping.jsonc") |
| 6 | +) |
| 7 | +function Get-GraphMapping { |
| 8 | + $graphMapping = @{} |
| 9 | + $graphMapping.Add("v1.0", "graph-powershell-1.0") |
| 10 | + $graphMapping.Add("beta", "graph-powershell-beta") |
| 11 | + return $graphMapping |
| 12 | +} |
| 13 | + |
| 14 | +function Remove-InvalidFullStops { |
| 15 | + Param( |
| 16 | + $ModulesToGenerate = @() |
| 17 | + ) |
| 18 | + |
| 19 | + $ModulePrefix = "Microsoft.Graph" |
| 20 | + $GraphMapping = Get-GraphMapping |
| 21 | + $GraphMapping.Keys | ForEach-Object { |
| 22 | + $graphProfile = $_ |
| 23 | + Get-FilesByProfile -GraphProfile $graphProfile -GraphProfilePath $GraphMapping[$graphProfile] -ModulePrefix $ModulePrefix -ModulesToGenerate $ModulesToGenerate |
| 24 | + } |
| 25 | + |
| 26 | + git config --global user.email "[email protected]" |
| 27 | + git config --global user.name "Timothy Wamalwa" |
| 28 | + git add . |
| 29 | + git commit -m "Removed invalid full stops from the beginning of lines" |
| 30 | +} |
| 31 | +function Get-FilesByProfile { |
| 32 | + Param( |
| 33 | + [ValidateSet("beta", "v1.0")] |
| 34 | + [string] $GraphProfile = "v1.0", |
| 35 | + [ValidateNotNullOrEmpty()] |
| 36 | + [string] $GraphProfilePath = "graph-powershell-1.0", |
| 37 | + [ValidateNotNullOrEmpty()] |
| 38 | + [string] $ModulePrefix = "Microsoft.Graph", |
| 39 | + [ValidateNotNullOrEmpty()] |
| 40 | + $ModulesToGenerate = @() |
| 41 | + ) |
| 42 | + |
| 43 | + $ModulesToGenerate | ForEach-Object { |
| 44 | + $ModuleName = $_ |
| 45 | + Get-Files -GraphProfile $GraphProfile -GraphProfilePath $GraphProfilePath -Module $ModuleName -ModulePrefix $ModulePrefix |
| 46 | + } |
| 47 | + |
| 48 | +} |
| 49 | +function Get-Files { |
| 50 | + param( |
| 51 | + [ValidateSet("beta", "v1.0")] |
| 52 | + [string] $GraphProfile = "v1.0", |
| 53 | + [ValidateNotNullOrEmpty()] |
| 54 | + [string] $GraphProfilePath = "graph-powershell-1.0", |
| 55 | + [ValidateNotNullOrEmpty()] |
| 56 | + [string] $Module = "Users", |
| 57 | + [ValidateNotNullOrEmpty()] |
| 58 | + [string] $ModulePrefix = "Microsoft.Graph" |
| 59 | + ) |
| 60 | + if ($GraphProfile -eq "beta") { |
| 61 | + $ModulePrefix = "Microsoft.Graph.Beta" |
| 62 | + } |
| 63 | + $moduleImportName = "$ModulePrefix.$ModuleName" |
| 64 | + $moduleDocsPath = Join-Path $PSScriptRoot "..\microsoftgraph\$GraphProfilePath\$moduleImportName" |
| 65 | + Update-Files -ModuleDocsPath $moduleDocsPath |
| 66 | + |
| 67 | +} |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | +function Update-Files { |
| 72 | + Param( |
| 73 | + [ValidateNotNullOrEmpty()] |
| 74 | + [string] $ModuleDocsPath |
| 75 | + ) |
| 76 | + $files = Get-ChildItem -Path $ModuleDocsPath -Filter *.md -Recurse |
| 77 | + $files | ForEach-Object { |
| 78 | + $FilePath = $_.FullName |
| 79 | + # Read the file and remove any full stops at the beginning of a line |
| 80 | + (Get-Content $FilePath) -replace '^\.', '' | Set-Content $FilePath |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | +if (-not (Test-Path $ModuleMappingConfigPath)) { |
| 85 | + Write-Error "Module mapping file not be found: $ModuleMappingConfigPath." |
| 86 | +} |
| 87 | +if ($ModulesToGenerate.Count -eq 0) { |
| 88 | + [HashTable] $ModuleMapping = Get-Content $ModuleMappingConfigPath | ConvertFrom-Json -AsHashTable |
| 89 | + $ModulesToGenerate = $ModuleMapping.Keys |
| 90 | +} |
| 91 | +Remove-InvalidFullStops -ModulesToGenerate $ModulesToGenerate |
| 92 | + |
| 93 | + |
| 94 | + |
| 95 | + |
0 commit comments