|
| 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 | + [string] $SDKDocsPath = (Join-Path $PSScriptRoot "../../msgraph-sdk-powershell/src"), |
| 7 | + [string] $WorkLoadDocsPath = (Join-Path $PSScriptRoot "../microsoftgraph") |
| 8 | +) |
| 9 | +function Get-GraphMapping { |
| 10 | + $graphMapping = @{} |
| 11 | + $graphMapping.Add("v1.0", "v1.0") |
| 12 | + $graphMapping.Add("beta", "beta") |
| 13 | + return $graphMapping |
| 14 | +} |
| 15 | + |
| 16 | +function Start-Copy { |
| 17 | + Param( |
| 18 | + $ModulesToGenerate = @() |
| 19 | + ) |
| 20 | + |
| 21 | + $ModulePrefix = "Microsoft.Graph" |
| 22 | + $GraphMapping = Get-GraphMapping |
| 23 | + $GraphMapping.Keys | ForEach-Object { |
| 24 | + $graphProfile = $_ |
| 25 | + $profilePath = "graph-powershell-1.0" |
| 26 | + if($graphProfile -eq "beta"){ |
| 27 | + $profilePath = "graph-powershell-beta" |
| 28 | + } |
| 29 | + Get-FilesByProfile -GraphProfile $graphProfile -GraphProfilePath $profilePath -ModulePrefix $ModulePrefix -ModulesToGenerate $ModulesToGenerate |
| 30 | + } |
| 31 | + |
| 32 | +} |
| 33 | +function Get-FilesByProfile{ |
| 34 | + Param( |
| 35 | + [ValidateSet("beta", "v1.0")] |
| 36 | + [string] $GraphProfile = "v1.0", |
| 37 | + [ValidateNotNullOrEmpty()] |
| 38 | + [string] $GraphProfilePath = "graph-powershell-1.0", |
| 39 | + [ValidateNotNullOrEmpty()] |
| 40 | + [string] $ModulePrefix = "Microsoft.Graph", |
| 41 | + [ValidateNotNullOrEmpty()] |
| 42 | + $ModulesToGenerate = @() |
| 43 | + ) |
| 44 | + |
| 45 | + $ModulesToGenerate | ForEach-Object { |
| 46 | + $ModuleName = $_ |
| 47 | + $docs = Join-Path $SDKDocsPath $ModuleName $GraphProfile "docs" |
| 48 | + Copy-Files -DocPath $docs -GraphProfilePath $GraphProfilePath -Module $ModuleName -ModulePrefix $ModulePrefix -GraphProfile $GraphProfile |
| 49 | + } |
| 50 | + |
| 51 | +} |
| 52 | +function Copy-Files{ |
| 53 | + param( |
| 54 | + [ValidateSet("beta", "v1.0")] |
| 55 | + [string] $GraphProfile = "v1.0", |
| 56 | + [ValidateNotNullOrEmpty()] |
| 57 | + [string] $GraphProfilePath = "graph-powershell-1.0", |
| 58 | + [ValidateNotNullOrEmpty()] |
| 59 | + [string] $Module = "Users", |
| 60 | + [ValidateNotNullOrEmpty()] |
| 61 | + [string] $ModulePrefix = "Microsoft.Graph", |
| 62 | + [ValidateNotNullOrEmpty()] |
| 63 | + [string] $DocPath = "..\msgraph-sdk-powershell\src\Users\v1.0\docs" |
| 64 | + ) |
| 65 | + $Path = "$ModulePrefix.$ModuleName" |
| 66 | + $ModifiedModuleName = $Module |
| 67 | + if($GraphProfile -eq 'beta'){ |
| 68 | + $Path = "$ModulePrefix.Beta.$ModuleName" |
| 69 | + $ModifiedModuleName = "Beta.$Module" |
| 70 | + } |
| 71 | + $destination = Join-Path $WorkLoadDocsPath $GraphProfilePath $Path |
| 72 | + |
| 73 | + Write-Host -ForegroundColor DarkYellow "Copying v1 markdown files to " $destination |
| 74 | + Get-ChildItem $destination -Recurse -File | ForEach-Object { |
| 75 | + $Command = [System.IO.Path]::GetFileNameWithoutExtension($_) |
| 76 | + if($Command -eq "Microsoft.Graph.$ModifiedModuleName" -or $Command -eq "README"){ |
| 77 | + #Extract URI path |
| 78 | + }else{ |
| 79 | + $CommandDetails = Find-MgGraphCommand -Command $Command |
| 80 | + if($CommandDetails){ |
| 81 | + if(-not($CommandDetails.Module -eq $ModifiedModuleName)){ |
| 82 | + Remove-Item $_ |
| 83 | + } |
| 84 | + }else{ |
| 85 | + Remove-Item $_ |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + |
| 93 | + |
| 94 | + |
| 95 | + |
| 96 | +# Set-Location microsoftgraph-docs-powershell |
| 97 | +# $date = Get-Date -Format "dd-MM-yyyy" |
| 98 | +# $proposedBranch = "weekly_v2_docs_update_$date" |
| 99 | +# $exists = git branch -l $proposedBranch |
| 100 | +# if ([string]::IsNullOrEmpty($exists)) { |
| 101 | +# git checkout -b $proposedBranch |
| 102 | +# }else{ |
| 103 | +# Write-Host "Branch already exists" |
| 104 | +# git checkout $proposedBranch |
| 105 | +# } |
| 106 | +# if (-not (Test-Path $ModuleMappingConfigPath)) { |
| 107 | +# Write-Error "Module mapping file not be found: $ModuleMappingConfigPath." |
| 108 | +# } |
| 109 | +if ($ModulesToGenerate.Count -eq 0) { |
| 110 | + [HashTable] $ModuleMapping = Get-Content $ModuleMappingConfigPath | ConvertFrom-Json -AsHashTable |
| 111 | + $ModulesToGenerate = $ModuleMapping.Keys |
| 112 | +} |
| 113 | + |
| 114 | +#Set-Location ..\microsoftgraph-docs-powershell |
| 115 | +Write-Host -ForegroundColor Green "-------------finished checking out to today's branch-------------" |
| 116 | +Start-Copy -ModulesToGenerate $ModulesToGenerate |
| 117 | +Write-Host -ForegroundColor Green "-------------Done-------------" |
0 commit comments