1
- # Copyright (c) Microsoft Corporation. All rights reserved.
2
- # Licensed under the MIT License.
3
- Param (
4
- $ModulesToGenerate = @ (),
5
- [string ] $ModuleMappingConfigPath = (Join-Path $PSScriptRoot " ../../msgraph-sdk-powershell/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
- git config
-- global user.email
" [email protected] "
32
- git config -- global user.name " Timothy Wamalwa"
33
- git add .
34
- git commit - m " Corrected titles"
35
- }
36
- function Get-FilesByProfile {
37
- Param (
38
- [ValidateSet (" beta" , " v1.0" )]
39
- [string ] $GraphProfile = " v1.0" ,
40
- [ValidateNotNullOrEmpty ()]
41
- [string ] $GraphProfilePath = " graph-powershell-1.0" ,
42
- [ValidateNotNullOrEmpty ()]
43
- [string ] $ModulePrefix = " Microsoft.Graph" ,
44
- [ValidateNotNullOrEmpty ()]
45
- $ModulesToGenerate = @ ()
46
- )
47
-
48
- $ModulesToGenerate | ForEach-Object {
49
- $ModuleName = $_
50
- $docs = Join-Path $SDKDocsPath $ModuleName $GraphProfile " examples"
51
- Copy-Files - DocPath $docs - GraphProfilePath $GraphProfilePath - Module $ModuleName - ModulePrefix $ModulePrefix - GraphProfile $GraphProfile
52
- }
53
-
54
- }
55
- function Copy-Files {
56
- param (
57
- [ValidateSet (" beta" , " v1.0" )]
58
- [string ] $GraphProfile = " v1.0" ,
59
- [ValidateNotNullOrEmpty ()]
60
- [string ] $GraphProfilePath = " graph-powershell-1.0" ,
61
- [ValidateNotNullOrEmpty ()]
62
- [string ] $Module = " Users" ,
63
- [ValidateNotNullOrEmpty ()]
64
- [string ] $ModulePrefix = " Microsoft.Graph" ,
65
- [ValidateNotNullOrEmpty ()]
66
- [string ] $DocPath = " ..\msgraph-sdk-powershell\src\Users\v1.0\examples"
67
- )
68
- $Path = " $ModulePrefix .$ModuleName "
69
- if ($GraphProfile -eq ' beta' ){
70
- $Path = " $ModulePrefix .Beta.$ModuleName "
71
- }
72
- $Destination = Join-Path $WorkLoadDocsPath $GraphProfilePath $Path
73
-
74
- if ((Test-Path $DocPath )) {
75
-
76
- foreach ($File in Get-ChildItem $DocPath ) {
77
- # Read the content of the file searching for example headers.
78
- $Command = [System.IO.Path ]::GetFileName($File )
79
- $content = Get-Content - Path $File
80
- $DestinationFile = Join-Path $Destination $Command
81
- $Content = Get-Content - Path $File
82
- Import-Descriptions - Content $Content - File $DestinationFile
83
-
84
- }
85
-
86
- }
87
- }
88
1
function Import-Descriptions {
89
2
Param (
90
3
[object ]$Content ,
91
4
[string ]$File
92
5
)
6
+ $SearchBlock = " ## EXAMPLES(?s).*## PARAMETERS"
7
+ $SearchBlock2 = " ## DESCRIPTION(?s).*## PARAMETERS"
8
+ $option = [System.Text.RegularExpressions.RegexOptions ]::Multiline
9
+ $Re = [regex ]::new($SearchBlock , $option )
10
+ $Re2 = [regex ]::new($SearchBlock2 , $option )
93
11
$RetainedExamples = New-Object Collections.Generic.List[string ]
94
12
$End = 0
95
13
$NoOfExamples = 0
@@ -99,45 +17,65 @@ function Import-Descriptions {
99
17
}
100
18
$End ++
101
19
}
20
+ Write-Host " Importing descriptions $NoOfExamples "
102
21
Get-ExistingDescriptions - Content $Content - File $File - start 0 - end $End - NoOfExamples $NoOfExamples
22
+ if (Test-Path $File ){
103
23
$TitleCount = 1
104
- $DestinationContent = Get-Content - Path $File
105
- $DestContentCount = 0
106
- foreach ($DestContent in $DestinationContent ){
107
- $DestContentCount ++
108
- }
24
+ $DestinationContent = Get-Content - Encoding UTF8 - Raw $File
25
+ $RetainedContent = $null
109
26
foreach ($Ex in $RetainedExamples ) {
110
- $ContentDescription = $Ex
111
- if (-not ($ContentDescription.Contains (" Add description here" ))){
112
-
113
- $NextExampleCount = $TitleCount + 1
114
- if ($RetainedExamples.Count -gt 1 ){
115
- for ($m = 0 ; $m -lt $DestContentCount ; $m ++ ){
116
- if ($DestinationContent [$m ].Contains(" ### Example $NextExampleCount " )){
117
-
118
- $NewContentBlockWithDescription = $ContentDescription + " `n " + $DestinationContent [$m ]
119
-
120
- (Get-Content $File ) |
121
- Foreach-Object { $_ -replace $DestinationContent [$m ], $NewContentBlockWithDescription } |
122
- Out-File $File
123
-
124
- }
125
-
126
-
127
- }
128
- }
129
-
130
-
27
+ $ContentBody = $Ex.Split (" **##@**" )[0 ]
28
+ $ContentDescription = $Ex.Split (" **##@**" )[2 ]
29
+ $RetainedContent += " $ContentBody$ContentDescription "
131
30
$TitleCount ++
132
- }
31
+
133
32
}
134
- # Replace the last param with description of the last example
135
- $LastExampleDescription = $RetainedExamples [$RetainedExamples.Count - 1 ] + " `n ## PARAMETERS"
136
- if (-not ($RetainedExamples [$RetainedExamples.Count - 1 ].Contains(" Add description here" ))){
137
- (Get-Content $File ) |
138
- Foreach-Object { $_ -replace " ## PARAMETERS" , $LastExampleDescription } |
139
- Out-File $File
33
+
34
+
35
+ if (-not ($Null -eq $RetainedContent ) -and -not ($RetainedContent.Contains (" Add title here" ))){
36
+ if ($DestinationContent -match $Re ){
37
+ $Extracted = $Matches [0 ]
38
+ $FinalOutput = " ## EXAMPLES`r`n $RetainedContent `r`n ## PARAMETERS"
39
+ $text = $DestinationContent.ToString ()
40
+ if (-not ($Extracted.Contains (" `````` powershell" ))){
41
+ $text = $text.Replace ($Extracted , " ## PARAMETERS" )
42
+ Write-Host " Does not have snippet"
43
+ }else {
44
+ $text = $text.Replace ($Extracted , $FinalOutput )
45
+ }
46
+ $text | Out-File $File - Encoding UTF8
47
+ }
48
+ if ($DestinationContent -match $Re2 ){
49
+ $Extracted2 = $Matches [0 ]
50
+ $DescriptionCommand = [System.IO.Path ]::GetFileNameWithoutExtension($File )
51
+ $Description1 = " This example shows how to use the $DescriptionCommand Cmdlet."
52
+ $Description2 = " To learn about permissions for this resource, see the [permissions reference](/graph/permissions-reference)."
53
+
54
+ $text2 = $DestinationContent.ToString ()
55
+ if (-not ($Extracted2.Contains (" ## EXAMPLES" ))){
56
+ Write-Host " Does not have snippet $DescriptionCommand "
57
+ $text2 = $text2.Replace ($Description1 , $null )
58
+ $text2 = $text2.Replace ($Description2 , $null )
59
+ $text2 | Out-File $File - Encoding UTF8
60
+
61
+ }
62
+ }
63
+ $Stream = [IO.File ]::OpenWrite($File )
64
+ try
65
+ {
66
+ $Stream.SetLength ($stream.Length - 2 )
67
+ $Stream.Close ()
68
+ }
69
+ catch
70
+ {
71
+
72
+ }
73
+ $Stream.Dispose ()
74
+ $RetainedExamples.Clear ()
140
75
}
76
+
77
+ }
78
+
141
79
}
142
80
function Get-ExistingDescriptions {
143
81
@@ -149,6 +87,7 @@ function Get-ExistingDescriptions {
149
87
[int ]$End ,
150
88
[int ]$NoOfExamples
151
89
)
90
+ $Title = $null
152
91
$ContentBlock = $null
153
92
154
93
for ($i = $Start ; $i -lt $End ; $i ++ ) {
@@ -171,7 +110,7 @@ function Get-ExistingDescriptions {
171
110
$DescVal = $Content [$j ]
172
111
$RetainedDescription += " $DescVal `n "
173
112
}
174
- $RetainedExamples.Add (" $RetainedDescription " )
113
+ $RetainedExamples.Add (" $ContentBlock **##@** $Title **##@** $ RetainedDescription" )
175
114
if ($NoOfExamples -gt 1 ) {
176
115
$NoOfExamples --
177
116
for ($k = $Start ; $k -lt $End ; $k ++ ) {
@@ -185,23 +124,7 @@ function Get-ExistingDescriptions {
185
124
}
186
125
187
126
}
188
- Set-Location microsoftgraph- docs- powershell
189
- $proposedBranch = " weekly_v2_docs_update_$date "
190
- $exists = git branch - l $proposedBranch
191
- if ([string ]::IsNullOrEmpty($exists )) {
192
- git checkout - b $proposedBranch
193
- }else {
194
- Write-Host " Branch already exists"
195
- git checkout $proposedBranch
196
- }
197
- if (-not (Test-Path $ModuleMappingConfigPath )) {
198
- Write-Error " Module mapping file not be found: $ModuleMappingConfigPath ."
199
- }
200
- if ($ModulesToGenerate.Count -eq 0 ) {
201
- [HashTable ] $ModuleMapping = Get-Content $ModuleMappingConfigPath | ConvertFrom-Json - AsHashTable
202
- $ModulesToGenerate = $ModuleMapping.Keys
203
- }
204
- Set-Location ..\microsoftgraph- docs- powershell
205
- Write-Host - ForegroundColor Green " -------------finished checking out to today's branch-------------"
206
- Start-Copy - ModulesToGenerate $ModulesToGenerate
207
- Write-Host - ForegroundColor Green " -------------Done-------------"
127
+ $File = " C:\Projects\msgraph-sdk-powershell\src\Identity.SignIns\beta\examples\New-MgBetaIdentityProvider.md"
128
+ $DestinationFile = " C:\Projects\microsoftgraph-docs-powershell\microsoftgraph\graph-powershell-beta\Microsoft.Graph.Beta.Identity.SignIns\New-MgBetaIdentityProvider.md"
129
+ $Content = Get-Content - Path $File
130
+ Import-Descriptions - Content $Content - File $DestinationFile
0 commit comments