3636 [int ]$Parallelization = [Environment ]::ProcessorCount
3737)
3838
39+ $sdkFolder = Join-Path - Path $PSScriptRoot " .." " .." " sdk"
40+
3941class GenerationInformation {
4042 # The directory where the library is located. Used for logging and validation.
4143 [string ]$LibraryFolder
@@ -59,11 +61,10 @@ class GenerationInformation {
5961function Find-GenerationInformation {
6062 param (
6163 [System.Collections.ArrayList ]$GenerationInformations ,
62- [string ]$ServiceDirectory ,
63- [string ]$RegenerationType
64+ [string ]$LibraryFolder
6465 )
6566
66- $path = " sdk/ $ServiceDirectory "
67+ $path = Join-Path - Path $sdkFolder $LibraryFolder
6768 if ($RegenerationType -eq ' Swagger' -or $RegenerationType -eq ' All' ) {
6869 # Search for 'Update-Codegeneration.ps1' script in the specified service directory.
6970 Get-ChildItem - Path $path - Filter " Update-Codegeneration.ps1" - Recurse | ForEach-Object {
@@ -99,46 +100,42 @@ foreach ($serviceDirectory in $ServiceDirectories.Split(',')) {
99100 if ($serviceDirectory -match ' \w+/\w+' ) {
100101 # The service directory is a specific library, e.g., "communication/azure-communication-chat"
101102 # Search the directory directly for an "Update-Codegeneration.ps1" script.
102- Find-GenerationInformation $generationInformations $serviceDirectory $RegenerationType
103+ Find-GenerationInformation $generationInformations $serviceDirectory
103104 } else {
104105 # The service directory is a top-level service, e.g., "storage"
105106 # Search for all libraries under the service directory.
106- foreach ($libraryFolder in Get-ChildItem - Path " sdk/$serviceDirectory " - Directory) {
107- Find-GenerationInformation $generationInformations " $serviceDirectory /$ ( $libraryFolder.Name ) " $RegenerationType
107+ $searchPath = Join-Path - Path $sdkFolder $serviceDirectory
108+ Get-ChildItem - Path $searchPath - Directory | ForEach-Object {
109+ Find-GenerationInformation $generationInformations " $serviceDirectory /$ ( $_.Name ) "
108110 }
109111 }
110112}
111113
112114if ($generationInformations.Count -eq 0 ) {
113115 $kind = $RegenerationType -eq ' All' ? ' Swagger or TypeSpec' : $RegenerationType
114- Write-Host @"
115- ======================================
116- No $kind generation files to regenerate in directories: $ServiceDirectories .
117- ======================================
118- "@
116+ Write-Host " No $kind generation files to regenerate in directories: $ServiceDirectories ."
119117 exit 0
120118}
121119
122120if ($RegenerationType -eq ' Swagger' -or $RegenerationType -eq ' All' ) {
123121 # Ensure Autorest is installed.
124122 $output = (& npm install - g autorest 2>&1 )
125123 if ($LASTEXITCODE -ne 0 ) {
126- Write-Error " Failed to install Autorest for Swagger regeneration."
127- Write-Error $output
124+ Write-Error " Failed to install Autorest for Swagger regeneration.`n $output "
128125 exit 1
129126 }
130127}
131128
132129if ($RegenerationType -eq ' TypeSpec' -or $RegenerationType -eq ' All' ) {
133130 $output = (& npm install - g @azure - tools/ typespec- client- generator- cli 2>&1 )
134131 if ($LASTEXITCODE -ne 0 ) {
135- Write-Error " Error installing @azure-tools/typespec-client-generator-cli"
136- Write-Error " $output "
132+ Write-Error " Error installing @azure-tools/typespec-client-generator-cli`n $output "
137133 exit 1
138134 }
139135}
140136
141137$generateScript = {
138+ $separatorBar = " ======================================"
142139 $directory = $_.LibraryFolder
143140 $updateCodegenScript = $_.ScriptPath
144141
@@ -147,85 +144,58 @@ $generateScript = {
147144 $generateOutput = (& $updateCodegenScript 6>&1 )
148145
149146 if ($LastExitCode -ne 0 ) {
150- Write-Host @"
151- ======================================
152- Error running Swagger regeneration $updateCodegenScript
153- ======================================
154- $ ( [String ]::Join(" `n " , $generateOutput ))
155- "@
147+ Write-Host " $separatorBar `n Error running Swagger regeneration $updateCodegenScript `n $ ( [String ]::Join(" `n " , $generateOutput )) `n $separatorBar "
156148 throw
157149 } else {
158150 # prevent warning related to EOL differences which triggers an exception for some reason
159151 (& git - c core.safecrlf= false diff -- ignore- space- at- eol -- exit-code -- " $directory /*.java" ) | Out-Null
160152
161153 if ($LastExitCode -ne 0 ) {
162154 $status = (git status - s " $directory " | Out-String )
163- Write-Host @"
164- ======================================
165- The following Swagger generated files in directoy $directory are out of date:
166- ======================================
167- $status
168- "@
155+ Write-Host " $separatorBar `n The following Swagger generated files in directoy $directory are out of date`n $status `n $separatorBar "
169156 throw
170157 } else {
171- Write-Host @"
172- ======================================
173- Successfully ran Swagger regneration with no diff $updateCodegenScript
174- ======================================
175- "@
158+ Write-Host " $separatorBar `n Successfully ran Swagger regneration with no diff $updateCodegenScript `n $separatorBar "
176159 }
177160 }
178161 } elseif ($_.Type -eq ' TypeSpec' ) {
179- Push-Location $Directory
162+ Push-Location $directory
180163 try {
181- $generateOutput = (& tsp- client update 2>&1 )
182- if ($LastExitCode -ne 0 ) {
183- Write-Host @"
184- ======================================
185- Error running TypeSpec regeneration in directory $Directory
186- ======================================
187- $ ( [String ]::Join(" `n " , $generateOutput ))
188- "@
189- throw
164+ try {
165+ $generateOutput = (& tsp- client update 2>&1 )
166+ if ($LastExitCode -ne 0 ) {
167+ Write-Host " $separatorBar `n Error running TypeSpec regeneration in directory $directory `n $ ( [String ]::Join(" `n " , $generateOutput )) `n $separatorBar "
168+ throw
169+ }
170+ } finally {
171+ Get-ChildItem - Path $directory - Filter TempTypeSpecFiles - Recurse - Directory | ForEach-Object {
172+ Remove-Item - Path $_.FullName - Recurse - Force | Out-Null
173+ }
190174 }
191175
192176 # Update code snippets before comparing the diff
193177 $mvnOutput = (& mvn -- no- transfer- progress codesnippet:update-codesnippet 2>&1 )
194178 if ($LastExitCode -ne 0 ) {
195- Write-Host @"
196- ======================================
197- Error updating TypeSpec codesnippets in directory $Directory
198- ======================================
199- $ ( [String ]::Join(" `n " , $mvnOutput ))
200- "@
179+ Write-Host " $separatorBar `n Error updating TypeSpec codesnippets in directory $directory `n $ ( [String ]::Join(" `n " , $mvnOutput )) `n $separatorBar "
201180 throw
202181 }
203182 } finally {
204183 Pop-Location
205184 }
206185
207186 # prevent warning related to EOL differences which triggers an exception for some reason
208- (& git - c core.safecrlf= false diff -- ignore- space- at- eol -- exit-code -- " $Directory /*.java" " :(exclude)**/src/test/**" " :
187+ (& git - c core.safecrlf= false diff -- ignore- space- at- eol -- exit-code -- " $directory /*.java" " :(exclude)**/src/test/**" " :
209188 (exclude)**/src/samples/**" " :(exclude)**/src/main/**/implementation/**" " :(exclude)**/src/main/**/resourcemanager/**/*Manager.java" ) | Out-Null
210189
211190 if ($LastExitCode -ne 0 ) {
212- $status = (git status - s " $Directory " | Out-String )
213- Write-Host @"
214- ======================================
215- The following TypeSpec files in directoy $Directory are out of date:
216- ======================================
217- $status
218- "@
191+ $status = (git status - s " $directory " | Out-String )
192+ Write-Host " $separatorBar `n The following TypeSpec files in directoy $directory are out of date`n $status `n $separatorBar "
219193 throw
220194 } else {
221- Write-Host @"
222- ======================================
223- Successfully ran TypeSpec update in directory with no diff $Directory
224- ======================================
225- "@
195+ Write-Host " $separatorBar `n Successfully ran TypeSpec update in directory with no diff $directory `n $separatorBar "
226196 }
227197 } else {
228- Write-Error " Unknown generation type: $ ( $_.Type ) , directory: $directory "
198+ Write-Host " $separatorBar `n Unknown generation type: $ ( $_.Type ) , directory: $directory `n $separatorBar "
229199 throw
230200 }
231201}
0 commit comments