microsoft/typespec
Publicmirrored fromhttps://github.com/microsoft/typespecAvailable
eng/emitters/scripts/Generate-APIView-CodeFile.ps1
42lines · modecode
| 1 | param ( |
| 2 | [Parameter(mandatory = $true)] |
| 3 | $ArtifactPath, |
| 4 | $NpmDevopsFeedRegistry = "https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-js@Local/npm/registry/" |
| 5 | ) |
| 6 | |
| 7 | Set-StrictMode -Version 3 |
| 8 | if (!(Test-Path -Path $ArtifactPath)) |
| 9 | { |
| 10 | Write-Error "Incorrect path to api-extractor artifacts. Path: $($ArtifactPath)" |
| 11 | exit 1 |
| 12 | } |
| 13 | |
| 14 | $apiviewParser = "@azure-tools/ts-genapi@2.0.11" |
| 15 | Write-Host "Installing $($apiviewParser)" |
| 16 | npm install $apiviewParser --registry $NpmDevopsFeedRegistry |
| 17 | $installedPath = npm ls @azure-tools/ts-genapi -p |
| 18 | if (!(Test-Path -Path $installedPath)) |
| 19 | { |
| 20 | Write-Host "@Azure-tools/ts-genapi is not installed to $($installedPath)" |
| 21 | exit 1 |
| 22 | } |
| 23 | |
| 24 | Write-Host "Setting working directory to $($installedPath)" |
| 25 | Push-Location $installedPath |
| 26 | try { |
| 27 | $apiFiles = @(Get-ChildItem -Path $ArtifactPath -Recurse -Filter "*.api.json") |
| 28 | foreach ($apiPkgFile in $apiFiles) |
| 29 | { |
| 30 | $apiFilePath = $apiPkgFile.FullName |
| 31 | $FileName = Split-Path -Leaf $apiFilePath |
| 32 | $OutDirectory = Split-Path -Path $apiFilePath |
| 33 | $OutFileName = "$($FileName.split('.')[0])_js.json" |
| 34 | $OutFilePath = Join-Path -Path $OutDirectory $OutFileName |
| 35 | Write-Host "Converting api-extractor file $($apiFilePath) to APIview code file $($OutFilePath)" |
| 36 | node ./dist/export.js $apiFilePath $OutFilePath |
| 37 | } |
| 38 | } |
| 39 | finally |
| 40 | { |
| 41 | Pop-Location |
| 42 | } |
| 43 | |