1
+ # Copyright (c) Microsoft Corporation. All rights reserved.
2
+ # Licensed under the MIT License.
3
+ Param (
4
+ $ModulesToGenerate = @ (),
5
+ [string ] $ModuleMappingConfigPath = (Join-Path $PSScriptRoot " .\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-Invalid-NextLine {
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
+ }
27
+ function Get-FilesByProfile {
28
+ Param (
29
+ [ValidateSet (" beta" , " v1.0" )]
30
+ [string ] $GraphProfile = " v1.0" ,
31
+ [ValidateNotNullOrEmpty ()]
32
+ [string ] $GraphProfilePath = " graph-powershell-1.0" ,
33
+ [ValidateNotNullOrEmpty ()]
34
+ [string ] $ModulePrefix = " Microsoft.Graph" ,
35
+ [ValidateNotNullOrEmpty ()]
36
+ $ModulesToGenerate = @ ()
37
+ )
38
+
39
+ $ModulesToGenerate | ForEach-Object {
40
+ $ModuleName = $_
41
+ Get-Files - GraphProfile $GraphProfile - GraphProfilePath $GraphProfilePath - Module $ModuleName - ModulePrefix $ModulePrefix
42
+ }
43
+
44
+ }
45
+ function Get-Files {
46
+ param (
47
+ [ValidateSet (" beta" , " v1.0" )]
48
+ [string ] $GraphProfile = " v1.0" ,
49
+ [ValidateNotNullOrEmpty ()]
50
+ [string ] $GraphProfilePath = " graph-powershell-1.0" ,
51
+ [ValidateNotNullOrEmpty ()]
52
+ [string ] $Module = " Users" ,
53
+ [ValidateNotNullOrEmpty ()]
54
+ [string ] $ModulePrefix = " Microsoft.Graph"
55
+ )
56
+ if ($GraphProfile -eq " beta" ){
57
+ $ModulePrefix = " Microsoft.Graph.Beta"
58
+ }
59
+ $moduleImportName = " $ModulePrefix .$ModuleName "
60
+ $moduleDocsPath = Join-Path $PSScriptRoot " $GraphProfilePath \$moduleImportName "
61
+ Update-Files - ModuleDocsPath $moduleDocsPath - GraphProfile $GraphProfile - ModuleName $ModuleName
62
+ }
63
+
64
+ if (-not (Test-Path $ModuleMappingConfigPath )) {
65
+ Write-Error " Module mapping file not be found: $ModuleMappingConfigPath ."
66
+ }
67
+ if ($ModulesToGenerate.Count -eq 0 ) {
68
+ [HashTable ] $ModuleMapping = Get-Content $ModuleMappingConfigPath | ConvertFrom-Json - AsHashTable
69
+ $ModulesToGenerate = $ModuleMapping.Keys
70
+ }
71
+ function Update-Files {
72
+ param (
73
+ [ValidateNotNullOrEmpty ()]
74
+ [string ] $ModuleDocsPath ,
75
+ [ValidateSet (" beta" , " v1.0" )]
76
+ [string ] $GraphProfile = " v1.0" ,
77
+ [ValidateNotNullOrEmpty ()]
78
+ [string ] $ModuleName = " Users"
79
+ )
80
+ try {
81
+ foreach ($filePath in Get-ChildItem $ModuleDocsPath ){
82
+ Refine_File - FilePath $filePath - GraphProfile $GraphProfile - ModuleName $ModuleName
83
+ # Special-Escape -FilePath $FilePath -GraphProfile $GraphProfile -ModuleName $ModuleName
84
+ # Start-Sleep -Seconds 5
85
+ }
86
+ }catch {
87
+ Write-Host " `n Error Message: " $_.Exception.Message
88
+ Write-Host " `n Error in Line: " $_.InvocationInfo.Line
89
+ Write-Host " `n Error in Line Number: " $_.InvocationInfo.ScriptLineNumber
90
+ Write-Host " `n Error Item Name: " $_.Exception.ItemName
91
+ }
92
+ }
93
+ function Refine_File {
94
+ param (
95
+ [ValidateNotNullOrEmpty ()]
96
+ [string ] $FilePath ,
97
+ [ValidateSet (" beta" , " v1.0" )]
98
+ [string ] $GraphProfile = " v1.0" ,
99
+ [ValidateNotNullOrEmpty ()]
100
+ [string ] $ModuleName = " Users"
101
+ )
102
+ $tempFilePath = " $env: TEMP \$ ( $FilePath | Split-Path - Leaf) "
103
+
104
+ $replace = " "
105
+ try {
106
+ $text = Get-Content - Path $FilePath
107
+ Write-Host $FilePath
108
+ foreach ($content in $text ){
109
+ if ($content -match " \\n" ){
110
+ $text = $text -replace " \\n" , $replace
111
+ }
112
+ }
113
+ $text > $tempFilePath
114
+ Remove-Item - Path $FilePath
115
+ Move-Item - Path $tempFilePath - Destination $FilePath
116
+ }catch {
117
+ Write-Host " `n Error Message: " $_.Exception.Message
118
+ Write-Host " `n Error in Line: " $_.InvocationInfo.Line
119
+ Write-Host " `n Error in Line Number: " $_.InvocationInfo.ScriptLineNumber
120
+ Write-Host " `n Error Item Name: " $_.Exception.ItemName
121
+ }
122
+ }
123
+
124
+
125
+ # Set-Location microsoftgraph-docs-powershell
126
+ # $date = Get-Date -Format "dd-MM-yyyy"
127
+ # $proposedBranch = "weekly_v2_docs_update_$date"
128
+ # $exists = git branch -l $proposedBranch
129
+ # if ([string]::IsNullOrEmpty($exists)) {
130
+ # git checkout -b $proposedBranch
131
+ # }else{
132
+ # Write-Host "Branch already exists"
133
+ # $currentBranch = git rev-parse --abbrev-ref HEAD
134
+ # if($currentBranch -ne $proposedBranch){
135
+ # git checkout $proposedBranch
136
+ # }
137
+ # git checkout $proposedBranch
138
+ # }
139
+ Remove-Invalid - NextLine - ModulesToGenerate $ModulesToGenerate
140
+ # cd microsoftgraph-docs-powershell
141
+ Write-Host - ForegroundColor Green " -------------Done-------------"
0 commit comments