Skip to content

Commit c74569b

Browse files
author
Qingqing Sun
committed
user command full name instead of alias for better understanding
1 parent 4102b9f commit c74569b

File tree

3 files changed

+77
-84
lines changed

3 files changed

+77
-84
lines changed

process_files_and_toc.ps1

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,17 @@
99
#>
1010

1111
# 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)
1313
{
1414
$host.SetShouldExit(-1)
1515
}
1616

1717
$header_pattern = "^(?s)\s*[-]{3}(.*?)[-]{3}\r?\n"
1818
$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
2020
$root_name = Split-Path $root_path -Leaf
2121
$toc_path = Join-Path $root_path "toc.yml"
2222

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-
}
3323

3424
Function global:DoGetToc
3525
{
@@ -42,37 +32,39 @@ Function global:DoGetToc
4232
$pre = $pre + " "
4333
}
4434

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
4737
if($index -ne $null)
4838
{
49-
ac $toc_path ($pre + " href: " + ($index -replace ".*$root_name", ".."))
39+
Add-Content $toc_path ($pre + " href: " + ($index -replace ".*$root_name", ".."))
5040
}
5141

52-
$sub_folders = ls $folder_path -dir
42+
$sub_folders = Get-ChildItem $folder_path -dir
5343
if($sub_folders -eq $null)
5444
{
55-
$files = ls $folder_path *.md | select -ExpandProperty FullName
45+
$files = Get-ChildItem $folder_path *.md | Select-Object -ExpandProperty FullName
5646
$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", ".."))
5949
$landing_page = $_
6050
}
6151

62-
ac $toc_path ($pre + " items:")
52+
Add-Content $toc_path ($pre + " items:")
6353
$pre = $pre + " "
6454
$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", ".."))
6656
}
6757
}
6858
else
6959
{
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+
}
7264

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)*')
7466
{
75-
$sub_folders = $sub_folders | sort -Property @{
67+
$sub_folders = $sub_folders | Sort-Object -Property @{
7668
Expression = {
7769
$version = $_.Name.replace('v', '')
7870
if($version -match '^\d$')
@@ -116,9 +108,9 @@ $script_block =
116108
}
117109

118110
# 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
120112

121-
if((gc $file | Out-String) -match $pattern)
113+
if((Get-Content $file | Out-String) -match $pattern)
122114
{
123115
$header = $matches[1]
124116
$new_header = $matches[1]
@@ -130,7 +122,7 @@ $script_block =
130122
$new_header = ""
131123
}
132124
# need to get git log info and resolve relative path
133-
cd (Split-Path $file -parent)
125+
Set-Location (Split-Path $file -parent)
134126

135127
# set or update metadata in the header of .md files
136128
$date = (Get-Date (git log --pretty=format:%cd -n 1 --date=iso $file)).ToUniversalTime()
@@ -152,7 +144,7 @@ $script_block =
152144
$topic_type = 'conceptual'
153145
if((Split-Path $file -Leaf) -ne "index.md")
154146
{
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
156148
}
157149
}
158150

@@ -169,7 +161,7 @@ $script_block =
169161
$service = ""
170162
if(Test-Path $ms_service_file)
171163
{
172-
$ms_service = (gc $ms_service_file -raw) | ConvertFrom-Json
164+
$ms_service = (Get-Content $ms_service_file -raw) | ConvertFrom-Json
173165
$service = $ms_service.($file_rel_path.split('/')[2]).($file_rel_path.split('/')[3])
174166
}
175167
if([string]::IsNullOrWhiteSpace($service))
@@ -183,37 +175,37 @@ $script_block =
183175
# reduce unnecessary file write
184176
if($header -ne $new_header)
185177
{
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
187179
}
188180

189181
# 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)
191183
{
192184
$related_links = $matches[0]
193185
$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 "\\", "/"
196188
$value = "(xref:" + $rel_path.Substring(1, $rel_path.LastIndexOf('/'))
197189
$new_related_links = $new_related_links.replace($_, ($_ -replace "\\", "/" -replace "\(.*/", $value))
198190
}
199191
}
200192
if($related_links -ne $new_related_links)
201193
{
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
203195
}
204196
}
205197
else
206198
{
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
208200
}
209201
}
210202
Function ProcessFiles
211203
{
212-
param([int]$max_threads)
213-
$RunspacePool = [RunspaceFactory ]::CreateRunspacePool(1, $max_threads)
204+
$max_threads = 8
205+
$RunspacePool = [RunspaceFactory]::CreateRunspacePool(1, $max_threads)
214206
$RunspacePool.Open()
215207
$Jobs = @()
216-
ls $root_path -r "*.md" | % {
208+
Get-ChildItem $root_path -r "*.md" | % {
217209
$Job = [powershell]::Create().AddScript($script_block).AddArgument($_.FullName).AddArgument($root_path).AddArgument($header_pattern).AddArgument($landing_page_pattern)
218210
$Job.RunspacePool = $RunspacePool
219211
$Jobs += New-Object PSObject -Property @{
@@ -224,16 +216,22 @@ Function ProcessFiles
224216
}
225217
Do
226218
{
227-
sleep -Seconds 1
219+
Start-Sleep -Seconds 5
228220
} While ($Jobs.Result.IsCompleted -contains $false)
229221
}
230222

231223
# Step 1: process .md files
232224
echo "Process files ..."
233-
ProcessFiles 8
225+
ProcessFiles
234226

235227
# Step 2: generate toc.yml
236228
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
238236

239237
echo "completed successfully."

process_xplat_cli_content.ps1

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,20 @@ $git_prefix = 'https://github.com/' + $env:APPVEYOR_REPO_NAME + '/blob/'
2323

2424
Function GetToc
2525
{
26-
cd $root_path
26+
Set-Location $root_path
2727
if(Test-Path $toc_path)
2828
{
29-
rm $toc_path
29+
Remove-Item $toc_path
3030
}
31-
ni $toc_path
31+
New-Item $toc_path
3232
$conceptual = Join-Path $root_path "Conceptual"
33-
if((Test-Path $conceptual) -and (ls $conceptual).count -ne 0)
33+
if((Test-Path $conceptual) -and (Get-ChildItem $conceptual).count -ne 0)
3434
{
35-
ac $toc_path "- name: Conceptual"
36-
ac $toc_path " items:"
35+
Add-Content $toc_path ("- name: Conceptual" + "`r`n" + " items:")
3736
DoGetConceptualToc $conceptual 1
3837
}
3938
DoGetReferenceToc $root_path 0
40-
sc $toc_path (gc $toc_path | Out-String).replace("\", "/") -NoNewline
39+
Set-Content $toc_path (Get-Content $toc_path | Out-String).replace("\", "/") -NoNewline
4140
}
4241

4342
Function PreparePre
@@ -57,11 +56,11 @@ Function global:DoGetConceptualToc
5756
param([string]$folder_path, [int]$level)
5857

5958
$pre = PreparePre $level
60-
ls $folder_path *.md | % {ac $toc_path (($pre + "- name: " + $_.BaseName) + "`r`n" + $pre + " href: " + (Resolve-Path $_.FullName -Relative))}
61-
$sub_folders = ls $folder_path -dir
59+
Get-ChildItem $folder_path *.md | % {Add-Content $toc_path (($pre + "- name: " + $_.BaseName) + "`r`n" + $pre + " href: " + (Resolve-Path $_.FullName -Relative))}
60+
$sub_folders = Get-ChildItem $folder_path -dir
6261
if($sub_folders -ne $null)
6362
{
64-
ac $toc_path ($pre + " items:")
63+
Add-Content $toc_path ($pre + " items:")
6564
$sub_folders | % {DoGetConceptualToc $_.FullName ($level + 1)}
6665
}
6766
}
@@ -71,12 +70,12 @@ Function global:DoGetReferenceToc
7170
param([string]$folder_path, [int]$level)
7271

7372
$pre = PreparePre $level
74-
ls $folder_path *.yml | ? {$_.BaseName -ne "toc"} | % {
75-
ac $toc_path ($pre + "- name: " + ($_.BaseName) + "`r`n" + $pre + " href: " + (Resolve-Path $_.FullName -Relative))
73+
Get-ChildItem $folder_path *.yml | ? {$_.BaseName -ne "toc"} | % {
74+
Add-Content $toc_path ($pre + "- name: " + ($_.BaseName) + "`r`n" + $pre + " href: " + (Resolve-Path $_.FullName -Relative))
7675
$sub_path = Join-Path $folder_path $_.BaseName
7776
if(Test-Path $sub_path)
7877
{
79-
ac $toc_path ($pre+ " items:")
78+
Add-Content $toc_path ($pre+ " items:")
8079
DoGetReferenceToc $sub_path ($level + 1)
8180
}
8281
}
@@ -86,7 +85,7 @@ Function GetJsFilePath
8685
{
8786
param([string]$file_path)
8887

89-
$all = gc $file_path | Out-String | sls "filePath:.*js" -AllMatches | % matches | % {$_ -replace "filePath:\s*", ""}
88+
$all = Get-Content $file_path | Out-String | Select-String "filePath:.*js" -AllMatches | % matches | % {$_ -replace "filePath:\s*", ""}
9089
if($all -eq $null -or $all.count -eq 0)
9190
{
9291
return $null
@@ -135,7 +134,7 @@ Function ProcessReferenceFiles
135134
$metadata = AssembleMetadata $metadata "content_git_url" $git_url
136135
$metadata = AssembleMetadata $metadata "original_content_git_url" $git_url
137136
$js_full_path = Join-Path $env:APPVEYOR_BUILD_FOLDER "lib\$js_path"
138-
cd (split-path $js_full_path -parent)
137+
Set-Location (Split-Path $js_full_path -Parent)
139138
$date = (Get-Date (git log --pretty=format:%cd -n 1 --date=iso $js_full_path)).ToUniversalTime()
140139
$metadata = AssembleMetadata $metadata "update_at" (Get-Date $date -format g)
141140
$metadata = AssembleMetadata $metadata "ms.date" (Get-Date $date -format d)
@@ -150,7 +149,7 @@ Function ProcessReferenceFiles
150149
$metadata = AssembleMetadata $metadata 'keywords' ${env:keywords}
151150
$metadata = AssembleMetadata $metadata 'manager' ${env:manager}
152151

153-
ac $path $metadata
152+
Add-Content $path $metadata
154153
}
155154

156155
Function SetMetadata
@@ -179,7 +178,7 @@ Function ProcessConceptualFiles
179178

180179
$header_pattern = "^(?s)\s*[-]{3}(.*?)[-]{3}\r?\n"
181180
$valid_header = $true
182-
if((gc $path | Out-String) -match $header_pattern)
181+
if((Get-Content $path | Out-String) -match $header_pattern)
183182
{
184183
$header = $matches[1]
185184
$new_header = $matches[1]
@@ -192,7 +191,7 @@ Function ProcessConceptualFiles
192191
}
193192
$file_rel_path = $path -replace ".*$root_name", "/$root_name" -replace "\\", "/" -replace ".*Conceptual","/Documentation"
194193
$file_full_path = Join-Path $env:APPVEYOR_BUILD_FOLDER $file_rel_path
195-
cd (Split-Path $file_full_path -parent)
194+
Set-Location (Split-Path $file_full_path -Parent)
196195
$date = (Get-Date (git log --pretty=format:%cd -n 1 --date=iso $file_full_path)).ToUniversalTime()
197196
$new_header = SetMetadata $header $new_header 'updated_at' (Get-Date $date -format g) $true
198197
$new_header = SetMetadata $header $new_header 'ms.date' (Get-Date $date -format d) $true
@@ -217,18 +216,18 @@ Function ProcessConceptualFiles
217216
{
218217
if($valid_header)
219218
{
220-
sc $path (gc $path | Out-String).replace($header, $new_header) -NoNewline
219+
Set-Content $path (Get-Content $path | Out-String).replace($header, $new_header) -NoNewline
221220
}
222221
else
223222
{
224-
sc $path ("---" + "`r`n" + $new_header + "---" + "`r`n" + (gc $path | Out-String)) -NoNewline
223+
Set-Content $path ("---" + "`r`n" + $new_header + "---" + "`r`n" + (Get-Content $path | Out-String)) -NoNewline
225224
}
226225
}
227226
}
228227
Function ProcessFiles
229228
{
230-
ls $root_path *.yml -r | ? {$_.BaseName -ne 'toc'} | % {ProcessReferenceFiles $_.FullName}
231-
ls $root_path -dir | ? {$_.BaseName -eq "Conceptual"} | % {ls $_.FullName *.md -r} | % {ProcessConceptualFiles $_.FullName}
229+
Get-ChildItem $root_path *.yml -r | ? {$_.BaseName -ne 'toc'} | % {ProcessReferenceFiles $_.FullName}
230+
Get-ChildItem $root_path -dir | ? {$_.BaseName -eq "Conceptual"} | % {Get-ChildItem $_.FullName *.md -r} | % {ProcessConceptualFiles $_.FullName}
232231
}
233232

234233
echo "generate toc..."

0 commit comments

Comments
 (0)