-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Requires eng/common changes in Azure/azure-sdk-tools#6632. Note: There's also a cleanup [PR](Azure/azure-sdk-tools#6800) to cleanup older language specific items. Test run of docindex:https://dev.azure.com/azure-sdk/internal/_build/results?buildId=2970911&view=logs&j=dc056dfc-c0cf-5958-c8c4-8da4f91a3739 Converts a collection of metadata JSON files into an onboarding spec.
- Loading branch information
1 parent
91a5e90
commit c33c612
Showing
4 changed files
with
120 additions
and
9 deletions.
There are no files selected for viewing
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
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,78 @@ | ||
. "$PSScriptRoot/Docs-ToC.ps1" | ||
|
||
# $SetDocsPackageOnboarding = "Set-${Language}-DocsPackageOnboarding" | ||
function Set-javascript-DocsPackageOnboarding($moniker, $metadata, $docRepoLocation, $packageSourceOverride) { | ||
$onboardingFile = GetOnboardingFile ` | ||
-docRepoLocation $docRepoLocation ` | ||
-moniker $moniker | ||
|
||
$onboardingSpec = Get-Content $onboardingFile -Raw | ConvertFrom-Json -AsHashtable | ||
|
||
$packagesToOnboard = @() | ||
foreach ($package in $metadata) { | ||
$packageSpec = [ordered]@{ | ||
name = Get-DocsMsPackageName ` | ||
-packageName $package.Name ` | ||
-packageVersion $package.Version | ||
} | ||
|
||
# $packageSourceOverride is irrelevant here as preview packages are | ||
# published up to NPM directly as alpha versions. The version from the | ||
# package metadata is sufficient. | ||
|
||
# Merge properties from from overrides, duplicate keys will be overwritten | ||
if ($package.ContainsKey('DocsCiConfigProperties')) { | ||
$overrides = $package['DocsCiConfigProperties'] | ||
foreach ($key in $overrides.Keys) { | ||
$packageSpec[$key] = $overrides[$key] | ||
} | ||
} | ||
|
||
$packagesToOnboard += $packageSpec | ||
} | ||
|
||
$onboardingSpec['npm_package_sources'] = $packagesToOnboard | ||
|
||
Set-Content ` | ||
-Path $onboardingFile ` | ||
-Value ($onboardingSpec | ConvertTo-Json -Depth 100) | ||
} | ||
|
||
function GetPackageInfoFromDocsMsConfig($packageName) { | ||
if (!$packageName) { | ||
throw "Package name must not be empty" | ||
} | ||
|
||
$name = $packageName | ||
$version = '' | ||
if ($packageName.IndexOf('@', 1) -ne -1) { | ||
$secondAtIndex = $packageName.IndexOf('@', 1) | ||
|
||
# "@azure/[email protected]" -> "@azure/package" | ||
$name = $packageName.Substring(0, $secondAtIndex) | ||
|
||
# "@azure/[email protected]" -> "1.2.3" | ||
$version = $packageName.Substring($secondAtIndex + 1) | ||
} | ||
|
||
return @{ | ||
Name = $name | ||
Version = $version | ||
} | ||
} | ||
|
||
# $GetDocsPackagesAlreadyOnboarded = "Get-${Language}-DocsPackagesAlreadyOnboarded" | ||
function Get-javascript-DocsPackagesAlreadyOnboarded($docRepoLocation, $moniker) { | ||
$packageOnboardingFile = GetOnboardingFile ` | ||
-docRepoLocation $DocRepoLocation ` | ||
-moniker $moniker | ||
|
||
$onboardedPackages = @{} | ||
$onboardingSpec = ConvertFrom-Json (Get-Content $packageOnboardingFile -Raw) | ||
foreach ($spec in $onboardingSpec.npm_package_sources) { | ||
$packageInfo = GetPackageInfoFromDocsMsConfig $spec.name | ||
$onboardedPackages[$packageInfo.Name] = $packageInfo | ||
} | ||
|
||
return $onboardedPackages | ||
} |
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
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,24 @@ | ||
Import-Module Pester | ||
|
||
BeforeAll { | ||
. $PSScriptRoot/../Docs-Onboarding.ps1 | ||
} | ||
|
||
Describe 'GetPackageInfoFromDocsMsConfig' { | ||
It 'Returns expected values' -ForEach @( | ||
@{ inputValue = '@azure/[email protected]'; expectedValue = @{ Name = '@azure/package'; Version = '1.2.3' } }, | ||
@{ inputValue = '@azure/package'; expectedValue = @{ Name = '@azure/package'; Version = '' } } | ||
) { | ||
$result = GetPackageInfoFromDocsMsConfig $inputValue | ||
$result.Name | Should -Be $expectedValue.Name | ||
$result.Version | Should -Be $expectedValue.Version | ||
} | ||
|
||
It 'Throws when given $null' { | ||
{ GetPackageInfoFromDocsMsConfig $null } | Should -Throw | ||
} | ||
|
||
It 'Throws when given an empty string' { | ||
{ GetPackageInfoFromDocsMsConfig '' } | Should -Throw | ||
} | ||
} |