@@ -30,10 +30,10 @@ export class GradleKotlinTemplateComponent {
3030 form : FormGroup ;
3131
3232 // Java version options for the radio buttons
33- javaVersionOptions : FormFieldOption [ ] = [
34- { value : '8' , label : 'Java 8' } ,
35- { value : '11' , label : 'Java 11' } ,
36- { value : '17' , label : 'Java 17' } ,
33+ javaVersionOptions : FormFieldOption [ ] = [
34+ { value : '8' , label : 'Java 8' } ,
35+ { value : '11' , label : 'Java 11' } ,
36+ { value : '17' , label : 'Java 17' } ,
3737 { value : '24' , label : 'Java 24' }
3838 ] ;
3939
@@ -95,26 +95,20 @@ export class GradleKotlinTemplateComponent {
9595 // Get form values
9696 const projectName = this . form . get ( 'projectName' ) ?. value || 'MyGdxGame' ;
9797
98- // Update package name
99- await this . updatePackageName ( zip ) ;
100-
101- // Update main class
98+ // 1. update file content without structural changes
99+ await this . updateVersionCatalog ( zip ) ;
100+ await this . updateDependencies ( zip ) ;
102101 await this . updateMainClass ( zip ) ;
103102
104- // Update the root folder name
103+ // 2. update structure
104+ await this . updatePackageName ( zip ) ;
105105 await this . updateRootFolderName ( zip , projectName ) ;
106106
107- // Update version catalog
108- await this . updateVersionCatalog ( zip ) ;
109-
110- // Update dependencies
111- await this . updateDependencies ( zip ) ;
112-
113107 // Generate a filename based on the project name
114108 const filename = `${ projectName } .zip` ;
115109
116110 // Generate the modified zip
117- const modifiedZipBlob = await zip . generateAsync ( { type : 'blob' } ) ;
111+ const modifiedZipBlob = await zip . generateAsync ( { type : 'blob' } ) ;
118112
119113 // Download the modified zip file
120114 await this . downloadService . downloadZip ( modifiedZipBlob , filename ) ;
@@ -223,23 +217,27 @@ export class GradleKotlinTemplateComponent {
223217
224218 const defaultPackagePath = defaultPackage . replace ( / \. / g, '/' ) ;
225219 const newPackagePath = packageName . replace ( / \. / g, '/' ) ;
226- const filesToRemove = [ ] ;
220+ const foldersToRemove = [ ] ;
221+ const filesToProcess = [ ] ;
227222
228223 // Find and update files that reference the default package name
229224 for ( const filePath in zip . files ) {
230225 if ( zip . files [ filePath ] . dir ) {
231226 if ( filePath . includes ( `/kotlin/io/` ) ) {
232227 // remove original io.github folders
233- filesToRemove . push ( filePath ) ;
228+ foldersToRemove . push ( filePath ) ;
234229 }
235230 continue ;
236231 }
237232
238233 const extension = filePath . split ( '.' ) . pop ( ) ?. toLowerCase ( ) ;
239- if ( ! ( extension && FILES_TO_UPDATE . includes ( extension ) ) ) {
240- continue ;
234+ if ( extension && FILES_TO_UPDATE . includes ( extension ) ) {
235+ filesToProcess . push ( filePath ) ;
241236 }
237+ }
242238
239+ const filesToRemove = [ ] ;
240+ for ( const filePath of filesToProcess ) {
243241 try {
244242 const content = await zip . files [ filePath ] . async ( 'text' ) ;
245243
@@ -249,7 +247,6 @@ export class GradleKotlinTemplateComponent {
249247 modifiedContent = content . replace ( new RegExp ( `package\\s+${ defaultPackage } ` , 'g' ) , `package ${ packageName } ` ) ;
250248 modifiedContent = modifiedContent . replace ( new RegExp ( `import\\s+${ defaultPackage } \\.` , 'g' ) , `import ${ packageName } .` ) ;
251249 modifiedContent = modifiedContent . replace ( new RegExp ( `"${ defaultPackage } ` , 'g' ) , `"${ packageName } ` ) ;
252- zip . file ( filePath , modifiedContent ) ;
253250 }
254251
255252 // Rename package directories if they match the pattern
@@ -274,14 +271,17 @@ export class GradleKotlinTemplateComponent {
274271 if ( newPath !== filePath ) {
275272 filesToRemove . push ( filePath ) ;
276273 }
274+ } else {
275+ // update existing file in place
276+ zip . file ( filePath , modifiedContent ) ;
277277 }
278278 } catch ( e ) {
279279 throw new Error ( `Skipping file ${ filePath } : ${ e } ` ) ;
280280 }
281281 }
282282
283283 // Remove the old files and folders
284- for ( const filePath of filesToRemove ) {
284+ for ( const filePath of [ ... filesToRemove , ... foldersToRemove ] ) {
285285 zip . remove ( filePath ) ;
286286 }
287287 }
@@ -413,6 +413,7 @@ export class GradleKotlinTemplateComponent {
413413 . filter ( line =>
414414 ! line . startsWith ( 'gretty' ) &&
415415 ! line . startsWith ( 'gdxTeaVm' ) &&
416+ ! line . startsWith ( 'gdxBox2dGwt' ) &&
416417 ! line . startsWith ( 'teaVm' ) &&
417418 ! line . startsWith ( '# teavm' ) &&
418419 ! line . startsWith ( '[plugins]' ) )
0 commit comments