@@ -254,7 +254,7 @@ export async function updateResourceConfig(resourceId, columnName, fieldType, co
254254}
255255
256256
257- export async function injectLoginComponent ( indexFilePath , componentPath ) {
257+ export async function injectLoginComponent ( indexFilePath , componentPath , injectionType ) {
258258 console . log ( chalk . dim ( `Reading file: ${ indexFilePath } ` ) ) ;
259259 const content = await fs . readFile ( indexFilePath , 'utf-8' ) ;
260260 const ast = recast . parse ( content , {
@@ -263,6 +263,7 @@ export async function injectLoginComponent(indexFilePath, componentPath) {
263263
264264 let updated = false ;
265265 let injectionLine = null ;
266+ let targetProperty = null ;
266267
267268 recast . visit ( ast , {
268269 visitNewExpression ( path ) {
@@ -293,20 +294,23 @@ export async function injectLoginComponent(indexFilePath, componentPath) {
293294 const loginPageInjections = getOrCreateProp ( customization , 'loginPageInjections' ) ;
294295 if ( ! n . ObjectExpression . check ( loginPageInjections ) ) return false ;
295296
296- let underInputsProp = loginPageInjections . properties . find (
297- p => n . ObjectProperty . check ( p ) && n . Identifier . check ( p . key ) && p . key . name === 'underInputs'
297+ // Determine target property based on injection type
298+ targetProperty = injectionType === 'beforeLogin' ? 'panelHeader' : 'underInputs' ;
299+
300+ let targetProp = loginPageInjections . properties . find (
301+ p => n . ObjectProperty . check ( p ) && n . Identifier . check ( p . key ) && p . key . name === targetProperty
298302 ) ;
299303
300- if ( underInputsProp ) {
301- const currentVal = underInputsProp . value ;
302- injectionLine = underInputsProp . loc ?. start . line ?? null ;
304+ if ( targetProp ) {
305+ const currentVal = targetProp . value ;
306+ injectionLine = targetProp . loc ?. start . line ?? null ;
303307 if ( n . StringLiteral . check ( currentVal ) ) {
304308 if ( currentVal . value !== componentPath ) {
305- underInputsProp . value = b . arrayExpression ( [
309+ targetProp . value = b . arrayExpression ( [
306310 b . stringLiteral ( currentVal . value ) ,
307311 b . stringLiteral ( componentPath ) ,
308312 ] ) ;
309- console . log ( chalk . dim ( `Converted 'underInputs ' to array with existing + new path.` ) ) ;
313+ console . log ( chalk . dim ( `Converted '${ targetProperty } ' to array with existing + new path.` ) ) ;
310314 } else {
311315 console . log ( chalk . dim ( `Component path already present as string. Skipping.` ) ) ;
312316 }
@@ -316,26 +320,26 @@ export async function injectLoginComponent(indexFilePath, componentPath) {
316320 ) ;
317321 if ( ! exists ) {
318322 currentVal . elements . push ( b . stringLiteral ( componentPath ) ) ;
319- console . log ( chalk . dim ( `Appended new component path to existing 'underInputs ' array.` ) ) ;
323+ console . log ( chalk . dim ( `Appended new component path to existing '${ targetProperty } ' array.` ) ) ;
320324 } else {
321325 console . log ( chalk . dim ( `Component path already present in array. Skipping.` ) ) ;
322326 }
323327 } else {
324- console . warn ( chalk . yellow ( `⚠️ 'underInputs ' is not a string or array. Skipping.` ) ) ;
328+ console . warn ( chalk . yellow ( `⚠️ '${ targetProperty } ' is not a string or array. Skipping.` ) ) ;
325329 return false ;
326330 }
327331 } else {
328332 const newProperty = b . objectProperty (
329- b . identifier ( 'underInputs' ) ,
330- b . stringLiteral ( componentPath )
331- ) ;
332-
333- if ( newProperty . loc ) {
334- console . log ( chalk . dim ( `Adding 'underInputs ' at line: ${ newProperty . loc . start . line } ` ) ) ;
335- }
336-
337- loginPageInjections . properties . push ( newProperty ) ;
338- console . log ( chalk . dim ( `Added 'underInputs ': ${ componentPath } ` ) ) ;
333+ b . identifier ( targetProperty ) ,
334+ b . stringLiteral ( componentPath )
335+ ) ;
336+
337+ if ( newProperty . loc ) {
338+ console . log ( chalk . dim ( `Adding '${ targetProperty } ' at line: ${ newProperty . loc . start . line } ` ) ) ;
339+ }
340+
341+ loginPageInjections . properties . push ( newProperty ) ;
342+ console . log ( chalk . dim ( `Added '${ targetProperty } ': ${ componentPath } ` ) ) ;
339343 }
340344
341345 updated = true ;
@@ -353,7 +357,7 @@ export async function injectLoginComponent(indexFilePath, componentPath) {
353357 await fs . writeFile ( indexFilePath , outputCode , 'utf-8' ) ;
354358 console . log (
355359 chalk . green (
356- `✅ Successfully updated CRUD injection in resource file : ${ indexFilePath } ` +
360+ `✅ Successfully updated login ${ targetProperty } injection in: ${ indexFilePath } ` +
357361 ( injectionLine !== null ? `:${ injectionLine } ` : '' )
358362 )
359363 ) ;
0 commit comments