-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
90 additions
and
0 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
eng/common/scripts/Helpers/Service-Level-Readme-Automation-Helpers.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
|
||
function create-service-readme($readmeFolder, $readmeName, $moniker, $msService, $indexTableLink, $serviceName, $author, $msAuthor) | ||
{ | ||
$readmePath = Join-Path $readmeFolder -ChildPath $readmeName | ||
$content = "" | ||
if (Test-Path (Join-Path $readmeFolder -ChildPath $indexTableLink)) { | ||
$content = "## Packages - $moniker`r`n" | ||
$content += "[!INCLUDE [packages]($indexTableLink)]" | ||
} | ||
if (!$content) { | ||
LogError "There are no packages under service '$serviceName'. " | ||
return | ||
} | ||
# Generate the front-matter for docs needs | ||
# $Language, $LanguageDisplayName are the variables globally defined in Language-Settings.ps1 | ||
$metadataString = GenerateDocsMsMetadata -language $Language -languageDisplayName $LanguageDisplayName -serviceName $serviceName ` | ||
-author $author -msAuthor $msAuthor -msService $msService | ||
Add-Content -Path $readmePath -Value $metadataString -NoNewline | ||
|
||
# Add tables, conbined client and mgmt together. | ||
$readmeHeader = "# Azure $serviceName SDK for $languageDisplayName - $moniker`r`n" | ||
Set-Content -Path $readmePath -Value "$metadataString$readmeHeader$content" -NoNewline | ||
} | ||
|
||
# Update the metadata table. | ||
function update-metadata-table($readmeFolder, $readmeName, $serviceName, $msService, $author, $msAuthor) | ||
{ | ||
$readmePath = Join-Path $readmeFolder -ChildPath $readmeName | ||
$readmeContent = Get-Content -Path $readmePath -Raw | ||
$match = $readmeContent -match "^---\n*(?<metadata>(.*\n?)*?)---\n*(?<content>(.*\n?)*)" | ||
$restContent = $readmeContent | ||
$metadata = "" | ||
if ($match) { | ||
$restContent = $Matches["content"].trim() | ||
$metadata = $Matches["metadata"].trim() | ||
} | ||
# $Language, $LanguageDisplayName are the variables globally defined in Language-Settings.ps1 | ||
$metadataString = GenerateDocsMsMetadata -originalMetadata $metadata -language $Language -languageDisplayName $LanguageDisplayName -serviceName $serviceName ` | ||
-author $author -msAuthor $msAuthor -msService $msService | ||
Set-Content -Path $readmePath -Value "$metadataString$restContent" -NoNewline | ||
} | ||
|
||
function generate-markdown-table($readmeFolder, $readmeName, $packageInfos, $moniker) { | ||
$tableHeader = "| Reference | Package | Source |`r`n|---|---|---|`r`n" | ||
$tableContent = "" | ||
$packageInfos = $packageInfos | Sort-Object -Property Type,Package | ||
# Here is the table, the versioned value will | ||
foreach ($pkg in $packageInfos) { | ||
$repositoryLink = "$PackageRepositoryUri/$($pkg.Package)" | ||
if (Test-Path "Function:$GetRepositoryLinkFn") { | ||
$repositoryLink = &$GetRepositoryLinkFn -packageInfo $pkg | ||
} | ||
$packageLevelReadme = "" | ||
if (Test-Path "Function:$GetPackageLevelReadmeFn") { | ||
$packageLevelReadme = &$GetPackageLevelReadmeFn -packageMetadata $pkg | ||
} | ||
|
||
$referenceLink = "[$($pkg.DisplayName)]($packageLevelReadme-readme.md)" | ||
if (!(Test-Path (Join-Path $readmeFolder -ChildPath "$packageLevelReadme-readme.md"))) { | ||
$referenceLink = $pkg.DisplayName | ||
} | ||
$githubLink = $GithubUri | ||
if ($pkg.PSObject.Members.Name -contains "DirectoryPath") { | ||
$githubLink = "$GithubUri/blob/main/$($pkg.DirectoryPath)" | ||
} | ||
$line = "|$referenceLink|[$($pkg.Package)]($repositoryLink)|[Github]($githubLink)|`r`n" | ||
$tableContent += $line | ||
} | ||
$readmePath = Join-Path $readmeFolder -ChildPath $readmeName | ||
if($tableContent) { | ||
Set-Content -Path $readmePath -Value "$tableHeader$tableContent" -NoNewline -Force | ||
} | ||
} | ||
|
||
function generate-service-level-readme($docRepoLocation, $readmeBaseName, $pathPrefix, $packageInfos, $serviceName, $moniker, $author, $msAuthor, $msService) { | ||
$readmeFolder = "$docRepoLocation/$pathPrefix/$moniker/" | ||
$serviceReadme = "$readmeBaseName.md" | ||
$indexReadme = "$readmeBaseName-index.md" | ||
if ($packageInfos) { | ||
generate-markdown-table -readmeFolder $readmeFolder -readmeName $indexReadme -packageInfos $packageInfos -moniker $moniker | ||
} | ||
if (!(Test-Path "$readmeFolder$serviceReadme") -and $packageInfos) { | ||
create-service-readme -readmeFolder $readmeFolder -readmeName $serviceReadme -moniker $moniker -msService $msService ` | ||
-indexTableLink $indexReadme -serviceName $serviceName -author $author -msAuthor $msAuthor | ||
} | ||
elseif (Test-Path "$readmeFolder$serviceReadme") { | ||
update-metadata-table -readmeFolder $readmeFolder -readmeName $serviceReadme -serviceName $serviceName ` | ||
-msService $msService -author $author -msAuthor $msAuthor | ||
} | ||
} |