|
1 | 1 | #Requires -Version 7.0
|
2 | 2 |
|
3 | 3 | param(
|
4 |
| - [string] $BuildNumber, |
5 | 4 | [string] $OutputDirectory,
|
6 |
| - [switch] $Prerelease, |
7 |
| - [switch] $TargetNpmJsFeed |
| 5 | + [switch] $TargetNpmJsFeed, |
| 6 | + [string] $emitterPackagePath |
8 | 7 | )
|
9 | 8 |
|
10 | 9 | $ErrorActionPreference = 'Stop'
|
11 | 10 | Set-StrictMode -Version 3.0
|
12 | 11 | . "$PSScriptRoot/../../common/scripts/common.ps1"
|
13 | 12 | Set-ConsoleEncoding
|
14 | 13 |
|
15 |
| -$packageRoot = Resolve-Path "$RepoRoot/eng/packages/http-client-csharp" |
16 |
| -$mgmtPackageRoot = Resolve-Path "$RepoRoot/eng/packages/http-client-csharp-mgmt" |
17 |
| -$outputPath = $OutputDirectory ? $OutputDirectory : (Join-Path $packageRoot "artifacts" "build") |
18 |
| -$mgmtOutputPath = $OutputDirectory ? $OutputDirectory : (Join-Path $mgmtPackageRoot "artifacts" "build") |
19 |
| - |
20 | 14 | function Build-Emitter {
|
21 | 15 | param (
|
22 | 16 | [string]$packageRoot,
|
23 |
| - [string]$outputPath |
| 17 | + [string]$outputPath, |
| 18 | + [hashtable]$overrides |
24 | 19 | )
|
25 | 20 |
|
26 | 21 | Push-Location $packageRoot
|
27 | 22 | try {
|
28 | 23 | Write-Host "Working in $PWD"
|
29 |
| - |
30 |
| - $outputPath = New-Item -ItemType Directory -Force -Path $outputPath | Select-Object -ExpandProperty FullName |
31 |
| - |
32 |
| - $emitterVersion = (npm pkg get version).Trim('"') |
| 24 | + Write-Host "TargetNpmJsFeed: $TargetNpmJsFeed" |
33 | 25 |
|
34 |
| - if ($BuildNumber) { |
35 |
| - # set package versions |
36 |
| - $versionTag = $Prerelease ? "-alpha" : "-beta" |
37 |
| - |
38 |
| - $emitterVersion = "$($emitterVersion.Split('-')[0])$versionTag.$BuildNumber" |
39 |
| - Write-Host "Setting output variable 'emitterVersion' to $emitterVersion" |
40 |
| - Write-Host "##vso[task.setvariable variable=emitterVersion;isoutput=true]$emitterVersion" |
41 |
| - } |
| 26 | + $outputPath = New-Item -ItemType Directory -Force -Path $outputPath | Select-Object -ExpandProperty FullName |
42 | 27 |
|
43 | 28 | # build and pack the emitter
|
44 |
| - Invoke-LoggedCommand "npm install @types/node --save-dev" -GroupOutput |
45 | 29 | Invoke-LoggedCommand "npm run build" -GroupOutput
|
46 | 30 |
|
47 |
| - if ($BuildNumber) { |
48 |
| - Write-Host "Updating version package.json to the new emitter version`n" |
49 |
| - Invoke-LoggedCommand "npm pkg set version=$emitterVersion" |
50 |
| - } |
51 |
| - |
52 | 31 | # remove any existing tarballs
|
53 | 32 | Remove-Item -Path "./*.tgz" -Force | Out-Null
|
54 |
| - |
| 33 | + |
55 | 34 | #pack the emitter
|
56 | 35 | Invoke-LoggedCommand "npm pack"
|
57 | 36 | $file = Get-ChildItem -Filter "*.tgz" | Select-Object -ExpandProperty FullName
|
58 | 37 |
|
59 |
| - # ensure the packages directory exists |
60 |
| - New-Item -ItemType Directory -Force -Path "$outputPath/packages" | Out-Null |
| 38 | + Write-Host "Copying $file to $outputPath" |
| 39 | + Copy-Item $file -Destination $outputPath |
61 | 40 |
|
62 |
| - Write-Host "Copying $file to $outputPath/packages" |
63 |
| - Copy-Item $file -Destination "$outputPath/packages" |
64 |
| - |
65 |
| - if ($TargetNpmJsFeed) { |
66 |
| - $overrides = @{} |
67 |
| - } |
68 |
| - else { |
| 41 | + if (!$TargetNpmJsFeed) { |
69 | 42 | $feedUrl = "https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-js-test-autorest/npm/registry"
|
70 | 43 |
|
71 |
| - $overrides = @{ |
72 |
| - "@azure-typespec/http-client-csharp" = "$feedUrl/@azure-typespec/http-client-csharp/-/http-client-csharp-$emitterVersion.tgz" |
73 |
| - } |
| 44 | + $packageJson = Get-Content -Path "./package.json" | ConvertFrom-Json |
| 45 | + $packageVersion = $packageJson.version |
| 46 | + $packageName = $packageJson.name |
| 47 | + |
| 48 | + $unscopedName = $packageName.Split("/")[1] |
| 49 | + $overrides[$packageName] = "$feedUrl/$packageName/-/$unscopedName-$packageVersion.tgz" |
74 | 50 | }
|
| 51 | + |
| 52 | + # restore the package.json and package-lock.json files to their original state |
| 53 | + Write-Host "Restoring package.json and package-lock.json to their original state" |
| 54 | + Invoke-LoggedCommand "git restore package.json package-lock.json" |
75 | 55 | }
|
76 | 56 | finally {
|
77 | 57 | Pop-Location
|
78 | 58 | }
|
79 | 59 | }
|
80 | 60 |
|
81 |
| -Build-Emitter -packageRoot $packageRoot -outputPath $outputPath |
| 61 | +$overrides = @{} |
| 62 | + |
| 63 | +$outputPath = $OutputDirectory ? $OutputDirectory : (Join-Path $RepoRoot "artifacts" "emitters") |
| 64 | +New-Item -ItemType Directory -Force -Path $outputPath | Out-Null |
| 65 | + |
| 66 | +# strip leading slash from emitterPackagePath if it exists |
| 67 | +if ($emitterPackagePath.StartsWith("/")) { |
| 68 | + $emitterPackagePath = $emitterPackagePath.Substring(1) |
| 69 | +} |
| 70 | +$packageRoot = Join-Path $RepoRoot $emitterPackagePath |
| 71 | +Build-Emitter -packageRoot $packageRoot -outputPath $outputPath -overrides $overrides |
| 72 | + |
| 73 | +Write-Host "Writing overrides to $outputPath/overrides.json" |
82 | 74 |
|
83 |
| -Build-Emitter -packageRoot $mgmtPackageRoot -outputPath $mgmtOutputPath |
| 75 | +$overrides | ConvertTo-Json | Out-File -FilePath "$outputPath/overrides.json" -Encoding utf8 -Force |
| 76 | +Get-Content -Path "$outputPath/overrides.json" | Out-Host |
0 commit comments