9
9
#>
10
10
11
11
# Validate that the repo has only one root folder
12
- if ((ls $env: APPVEYOR_BUILD_FOLDER - dir).count -ne 1 )
12
+ if ((Get-ChildItem $env: APPVEYOR_BUILD_FOLDER - dir).count -ne 1 )
13
13
{
14
14
$host.SetShouldExit (-1 )
15
15
}
16
16
17
17
$header_pattern = " ^(?s)\s*[-]{3}(.*?)[-]{3}\r?\n"
18
18
$landing_page_pattern = " Module\s*Name\s*:"
19
- $root_path = (ls $env: APPVEYOR_BUILD_FOLDER - dir | select - First 1 ).FullName
19
+ $root_path = (Get-ChildItem $env: APPVEYOR_BUILD_FOLDER - dir | Select-Object - First 1 ).FullName
20
20
$root_name = Split-Path $root_path - Leaf
21
21
$toc_path = Join-Path $root_path " toc.yml"
22
22
23
- Function GetToc
24
- {
25
- if (Test-Path $toc_path )
26
- {
27
- rm $toc_path
28
- }
29
- ni $toc_path
30
- ls $root_path - dir | % {DoGetToc $_.FullName 0 }
31
- sc $toc_path (gc $toc_path | Out-String ).replace(" \" , " /" ) - NoNewline
32
- }
33
23
34
24
Function global :DoGetToc
35
25
{
@@ -42,37 +32,39 @@ Function global:DoGetToc
42
32
$pre = $pre + " "
43
33
}
44
34
45
- ac $toc_path ($pre + " - name: " + (Split-Path $folder_path - Leaf))
46
- $index = ls $folder_path | ? {$_.Name -eq ' index.md' } | select - ExpandProperty FullName
35
+ Add-Content $toc_path ($pre + " - name: " + (Split-Path $folder_path - Leaf))
36
+ $index = Get-ChildItem $folder_path | ? {$_.Name -eq ' index.md' } | Select-Object - ExpandProperty FullName
47
37
if ($index -ne $null )
48
38
{
49
- ac $toc_path ($pre + " href: " + ($index -replace " .*$root_name " , " .." ))
39
+ Add-Content $toc_path ($pre + " href: " + ($index -replace " .*$root_name " , " .." ))
50
40
}
51
41
52
- $sub_folders = ls $folder_path - dir
42
+ $sub_folders = Get-ChildItem $folder_path - dir
53
43
if ($sub_folders -eq $null )
54
44
{
55
- $files = ls $folder_path * .md | select - ExpandProperty FullName
45
+ $files = Get-ChildItem $folder_path * .md | Select-Object - ExpandProperty FullName
56
46
$landing_page = " "
57
- $files | ? {(gc $_ | Out-String ) -match $header_pattern -and $matches [1 ] -match $landing_page_pattern } | select - First 1 | % {
58
- ac $toc_path ($pre + " href: " + ($_ -replace " .*$root_name " , " .." ))
47
+ $files | ? {(Get-Content $_ | Out-String ) -match $header_pattern -and $matches [1 ] -match $landing_page_pattern } | Select-Object - First 1 | % {
48
+ Add-Content $toc_path ($pre + " href: " + ($_ -replace " .*$root_name " , " .." ))
59
49
$landing_page = $_
60
50
}
61
51
62
- ac $toc_path ($pre + " items:" )
52
+ Add-Content $toc_path ($pre + " items:" )
63
53
$pre = $pre + " "
64
54
$files | ? {$_ -ne $landing_page } | % {
65
- ac $toc_path ($pre + " - name: " + (gi $_ ).BaseName + " `r`n " + $pre + " href: " + ($_ -replace " .*$root_name " , " .." ))
55
+ Add-Content $toc_path ($pre + " - name: " + (Get-Item $_ ).BaseName + " `r`n " + $pre + " href: " + ($_ -replace " .*$root_name " , " .." ))
66
56
}
67
57
}
68
58
else
69
59
{
70
- ac $toc_path ($pre + " items:" )
71
- ls $folder_path * .md | ? {$_.Name -ne " index.md" } | select - ExpandProperty FullName | % {ac $toc_path ($pre + " - name: " + (gi $_ ).BaseName + " `r`n " + $pre + " href: " + ($_ -replace " .*$root_name " , " .." ))}
60
+ Add-Content $toc_path ($pre + " items:" )
61
+ Get-ChildItem $folder_path * .md | ? {$_.Name -ne " index.md" } | Select-Object - ExpandProperty FullName | % {
62
+ Add-Content $toc_path ($pre + " - name: " + (Get-Item $_ ).BaseName + " `r`n " + $pre + " href: " + ($_ -replace " .*$root_name " , " .." ))
63
+ }
72
64
73
- if (($sub_folders | select - First 1 ).Name -match ' v\d(.\d)*' )
65
+ if (($sub_folders | Select-Object - First 1 ).Name -match ' v\d(.\d)*' )
74
66
{
75
- $sub_folders = $sub_folders | sort - Property @ {
67
+ $sub_folders = $sub_folders | Sort-Object - Property @ {
76
68
Expression = {
77
69
$version = $_.Name.replace (' v' , ' ' )
78
70
if ($version -match ' ^\d$' )
@@ -116,9 +108,9 @@ $script_block =
116
108
}
117
109
118
110
# remove empty header first
119
- sc $file ((gc $file | Out-String ) -replace " -{3}(\r?\n)+-{3}" , " " ) - NoNewline
111
+ sc $file ((Get-Content $file | Out-String ) -replace " -{3}(\r?\n)+-{3}" , " " ) - NoNewline
120
112
121
- if ((gc $file | Out-String ) -match $pattern )
113
+ if ((Get-Content $file | Out-String ) -match $pattern )
122
114
{
123
115
$header = $matches [1 ]
124
116
$new_header = $matches [1 ]
@@ -130,7 +122,7 @@ $script_block =
130
122
$new_header = " "
131
123
}
132
124
# need to get git log info and resolve relative path
133
- cd (Split-Path $file - parent)
125
+ Set-Location (Split-Path $file - parent)
134
126
135
127
# set or update metadata in the header of .md files
136
128
$date = (Get-Date (git log -- pretty= format:% cd - n 1 -- date= iso $file )).ToUniversalTime()
@@ -152,7 +144,7 @@ $script_block =
152
144
$topic_type = ' conceptual'
153
145
if ((Split-Path $file - Leaf) -ne " index.md" )
154
146
{
155
- $new_header = SetMetadata $header $new_header ' uid' ($file_rel_path.split (' /' , 3 ) | select - Last 1 ) $true
147
+ $new_header = SetMetadata $header $new_header ' uid' ($file_rel_path.split (' /' , 3 ) | Select-Object - Last 1 ) $true
156
148
}
157
149
}
158
150
@@ -169,7 +161,7 @@ $script_block =
169
161
$service = " "
170
162
if (Test-Path $ms_service_file )
171
163
{
172
- $ms_service = (gc $ms_service_file - raw) | ConvertFrom-Json
164
+ $ms_service = (Get-Content $ms_service_file - raw) | ConvertFrom-Json
173
165
$service = $ms_service .($file_rel_path.split (' /' )[2 ]).($file_rel_path.split (' /' )[3 ])
174
166
}
175
167
if ([string ]::IsNullOrWhiteSpace($service ))
@@ -183,37 +175,37 @@ $script_block =
183
175
# reduce unnecessary file write
184
176
if ($header -ne $new_header )
185
177
{
186
- sc $file (gc $file | Out-String ).replace($header , ($new_header -replace " {|}" , " " )) - NoNewline
178
+ Set-Content $file (Get-Content $file | Out-String ).replace($header , ($new_header -replace " {|}" , " " )) - NoNewline
187
179
}
188
180
189
181
# resolve related links to the format that docfx supports [link name](xref:uid)
190
- if ((gc $file | Out-String ) -match $related_link_pattern )
182
+ if ((Get-Content $file | Out-String ) -match $related_link_pattern )
191
183
{
192
184
$related_links = $matches [0 ]
193
185
$new_related_links = $matches [0 ]
194
- $related_links | sls " \[\S.*\]\(.*\)" - AllMatches | % matches | ? {$_ -match " \(.*.md\s*\)" -and $_ -notmatch " xref:" } | % {
195
- $rel_path = (rvpa ($matches [0 ] -replace " \(|\)" , " " )) -replace " .*$root_name " , " " -replace " \\" , " /"
186
+ $related_links | Select-String " \[\S.*\]\(.*\)" - AllMatches | % matches | ? {$_ -match " \(.*.md\s*\)" -and $_ -notmatch " xref:" } | % {
187
+ $rel_path = (Resolve-Path ($matches [0 ] -replace " \(|\)" , " " )) -replace " .*$root_name " , " " -replace " \\" , " /"
196
188
$value = " (xref:" + $rel_path.Substring (1 , $rel_path.LastIndexOf (' /' ))
197
189
$new_related_links = $new_related_links.replace ($_ , ($_ -replace " \\" , " /" -replace " \(.*/" , $value ))
198
190
}
199
191
}
200
192
if ($related_links -ne $new_related_links )
201
193
{
202
- sc $file (gc $file | Out-String ).replace($related_links , $new_related_links ) - NoNewline
194
+ Set-Content $file (Get-Content $file | Out-String ).replace($related_links , $new_related_links ) - NoNewline
203
195
}
204
196
}
205
197
else
206
198
{
207
- sc $file (" ---" + " `r`n " + $new_header + " ---" + " `r`n " + (gc $file | Out-String )) - NoNewline
199
+ Set-Content $file (" ---" + " `r`n " + $new_header + " ---" + " `r`n " + (Get-Content $file | Out-String )) - NoNewline
208
200
}
209
201
}
210
202
Function ProcessFiles
211
203
{
212
- param ([ int ] $max_threads )
213
- $RunspacePool = [RunspaceFactory ]::CreateRunspacePool(1 , $max_threads )
204
+ $max_threads = 8
205
+ $RunspacePool = [RunspaceFactory ]::CreateRunspacePool(1 , $max_threads )
214
206
$RunspacePool.Open ()
215
207
$Jobs = @ ()
216
- ls $root_path - r " *.md" | % {
208
+ Get-ChildItem $root_path - r " *.md" | % {
217
209
$Job = [powershell ]::Create().AddScript($script_block ).AddArgument($_.FullName ).AddArgument($root_path ).AddArgument($header_pattern ).AddArgument($landing_page_pattern )
218
210
$Job.RunspacePool = $RunspacePool
219
211
$Jobs += New-Object PSObject - Property @ {
@@ -224,16 +216,22 @@ Function ProcessFiles
224
216
}
225
217
Do
226
218
{
227
- sleep - Seconds 1
219
+ Start-Sleep - Seconds 5
228
220
} While ($Jobs.Result.IsCompleted -contains $false )
229
221
}
230
222
231
223
# Step 1: process .md files
232
224
echo " Process files ..."
233
- ProcessFiles 8
225
+ ProcessFiles
234
226
235
227
# Step 2: generate toc.yml
236
228
echo " generate toc..."
237
- GetToc
229
+ if (Test-Path $toc_path )
230
+ {
231
+ Remove-Item $toc_path
232
+ }
233
+ New-Item $toc_path
234
+ Get-ChildItem $root_path - dir | % {DoGetToc $_.FullName 0 }
235
+ Set-Content $toc_path (Get-Content $toc_path | Out-String ).replace(" \" , " /" ) - NoNewline
238
236
239
237
echo " completed successfully."
0 commit comments