@@ -202,7 +202,12 @@ export async function updateResourceConfig(resourceId, columnName, fieldType, co
202
202
const outputCode = recast . print ( ast ) . code ;
203
203
204
204
await fs . writeFile ( filePath , outputCode , 'utf-8' ) ;
205
- console . log ( chalk . dim ( `Successfully updated resource configuration file (preserving formatting): ${ filePath } :${ injectionLine } ` ) ) ;
205
+ console . log (
206
+ chalk . green (
207
+ `✅ Successfully updated CRUD injection in resource file: ${ filePath } ` +
208
+ ( injectionLine !== null ? `:${ injectionLine } ` : '' )
209
+ )
210
+ ) ;
206
211
207
212
} catch ( error ) {
208
213
console . error ( chalk . red ( `❌ Error processing resource file: ${ filePath } ` ) ) ;
@@ -309,7 +314,12 @@ export async function injectLoginComponent(indexFilePath, componentPath) {
309
314
310
315
const outputCode = recast . print ( ast ) . code ;
311
316
await fs . writeFile ( indexFilePath , outputCode , 'utf-8' ) ;
312
- console . log ( chalk . green ( `✅ Successfully updated login injection in: ${ indexFilePath } :${ injectionLine } ` ) ) ;
317
+ console . log (
318
+ chalk . green (
319
+ `✅ Successfully updated CRUD injection in resource file: ${ indexFilePath } ` +
320
+ ( injectionLine !== null ? `:${ injectionLine } ` : '' )
321
+ )
322
+ ) ;
313
323
}
314
324
315
325
@@ -402,7 +412,12 @@ export async function injectGlobalComponent(indexFilePath, injectionType, compon
402
412
403
413
const outputCode = recast . print ( ast ) . code ;
404
414
await fs . writeFile ( indexFilePath , outputCode , 'utf-8' ) ;
405
- console . log ( chalk . green ( `✅ Successfully updated global injection '${ injectionType } ' in: ${ indexFilePath } :${ injectionLine } ` ) ) ;
415
+ console . log (
416
+ chalk . green (
417
+ `✅ Successfully updated CRUD injection in resource file: ${ indexFilePath } ` +
418
+ ( injectionLine !== null ? `:${ injectionLine } ` : '' )
419
+ )
420
+ ) ;
406
421
}
407
422
408
423
export async function updateCrudInjectionConfig ( resourceId , crudType , injectionPosition , componentPathForConfig , isThin ) {
@@ -487,11 +502,23 @@ export async function updateCrudInjectionConfig(resourceId, crudType, injectionP
487
502
] ) ;
488
503
489
504
if ( injectionProp ) {
490
- injectionProp . value = newInjectionObject ;
491
- console . log ( chalk . dim ( `Updated '${ injectionPosition } ' injection for '${ crudType } '.` ) ) ;
505
+ if ( n . ArrayExpression . check ( injectionProp . value ) ) {
506
+ injectionProp . value . elements . push ( newInjectionObject ) ;
507
+ console . log ( chalk . dim ( `Appended new injection to array at '${ injectionPosition } ' for '${ crudType } '.` ) ) ;
508
+ }
509
+ else if ( n . ObjectExpression . check ( injectionProp . value ) ) {
510
+ injectionProp . value = b . arrayExpression ( [ injectionProp . value , newInjectionObject ] ) ;
511
+ console . log ( chalk . dim ( `Converted to array and added new injection at '${ injectionPosition } ' for '${ crudType } '.` ) ) ;
512
+ }
513
+ else {
514
+ injectionProp . value = b . arrayExpression ( [ newInjectionObject ] ) ;
515
+ console . log ( chalk . yellow ( `⚠️ Replaced invalid injection at '${ injectionPosition } ' with array.` ) ) ;
516
+ }
492
517
} else {
493
- crudValue . properties . push ( b . objectProperty ( b . identifier ( injectionPosition ) , newInjectionObject ) ) ;
494
- console . log ( chalk . dim ( `Added '${ injectionPosition } ' injection for '${ crudType } '.` ) ) ;
518
+ crudValue . properties . push (
519
+ b . objectProperty ( b . identifier ( injectionPosition ) , b . arrayExpression ( [ newInjectionObject ] ) )
520
+ ) ;
521
+ console . log ( chalk . dim ( `Added new array of injections at '${ injectionPosition } ' for '${ crudType } '.` ) ) ;
495
522
}
496
523
497
524
updateApplied = true ;
@@ -506,7 +533,12 @@ export async function updateCrudInjectionConfig(resourceId, crudType, injectionP
506
533
507
534
const outputCode = recast . print ( ast ) . code ;
508
535
await fs . writeFile ( filePath , outputCode , 'utf-8' ) ;
509
- console . log ( chalk . dim ( `✅ Successfully updated CRUD injection in resource file: ${ filePath } :${ injectionLine } ` ) ) ;
536
+ console . log (
537
+ chalk . green (
538
+ `✅ Successfully updated CRUD injection in resource file: ${ filePath } ` +
539
+ ( injectionLine !== null ? `:${ injectionLine } ` : '' )
540
+ )
541
+ ) ;
510
542
511
543
} catch ( error ) {
512
544
console . error ( chalk . red ( `❌ Error processing resource file: ${ filePath } ` ) ) ;
0 commit comments