Skip to content

Instantly share code, notes, and snippets.

@scbedd
Last active April 10, 2020 19:21
Show Gist options
  • Save scbedd/b1b507cfb7b81616b651843f51824fcd to your computer and use it in GitHub Desktop.
Save scbedd/b1b507cfb7b81616b651843f51824fcd to your computer and use it in GitHub Desktop.
Copy Readmes To Docs
# Example Usage: ./copy_readmes.ps1 -CodeRepo C:/repo/sdk-for-python -DocRepo C:/repo/azure-docs-sdk-python
# Highly recommended that you use Powershell Core.
# git reset --hard origin/smoke-test on the doc repo prior to running this
param (
[String]$CodeRepo,
[String]$DocRepo,
[String]$TargetServices = "keyvault,storage"
)
$PACKAGE_README_REGEX = ".*[\/\\]sdk[\\\/][^\/\\]+[\\\/][^\/\\]+[\/\\]README\.md"
if ($CodeRepo -Match "net")
{
$TARGET_FOLDER = Join-Path -Path $DocRepo -ChildPath "api/overview/azure"
}
else {
$TARGET_FOLDER = Join-Path -Path $DocRepo -ChildPath "docs-ref-services"
}
$selectedServices = $TargetServices -Split "," | % { return $_.Trim() }
foreach($service in $selectedServices){
$readmePath = Join-Path -Path $CodeRepo -ChildPath "sdk/$service"
Write-Host "Examining: $readmePath"
$readmeFiles = gci -r $readmePath/* -Include "*README.md" | ? { return $_.FullName -match $PACKAGE_README_REGEX -and !($_ -like "nspkg")}
foreach($file in $readmeFiles){
Write-Host "`tOutputting $($file.FullName)"
$fileContent = Get-Content $file
$readmeName = "$($file.Directory.Name.Replace('azure-','').Replace('Azure.', '').ToLower())-readme.md"
$readmeOutputLocation = Join-Path $TARGET_FOLDER -ChildPath $readmeName
Set-Content -Path $readmeOutputLocation -Value $fileContent
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment