@@ -237,7 +237,7 @@ function getLastSegmentNew(str: string, separator: string): string {
237237 return segments [ segments . length - 1 ] . trim ( ) ;
238238}
239239
240- export function buildSchemaTree ( fields : any [ ] , parentUid = '' , parentType = '' ) : any [ ] {
240+ export function buildSchemaTree ( fields : any [ ] , parentUid = '' , parentType = '' , oldPrentUid = '' ) : any [ ] {
241241
242242 if ( ! Array . isArray ( fields ) ) {
243243 console . warn ( 'buildSchemaTree called with invalid fields:' , fields ) ;
@@ -261,10 +261,10 @@ export function buildSchemaTree(fields: any[], parentUid = '', parentType = ''):
261261 }
262262
263263 // Check if direct child of parent
264- if ( ! fieldUid . startsWith ( parentUid + '.' ) ) return false ;
264+ // if (!fieldUid.startsWith(parentUid + '.')) return false;
265265
266266 // Verify it's exactly one level deeper
267- const remainder = fieldUid . substring ( parentUid . length + 1 ) ;
267+ const remainder = fieldUid . startsWith ( parentUid ) ? fieldUid . substring ( parentUid . length + 1 ) : fieldUid . substring ( oldPrentUid . length + 1 ) ;
268268 return remainder && ! remainder . includes ( '.' ) ;
269269 } ) ;
270270
@@ -282,11 +282,12 @@ export function buildSchemaTree(fields: any[], parentUid = '', parentType = ''):
282282 // Determine if field should have nested schema
283283 const fieldUid = field . contentstackFieldUid ;
284284 const fieldType = field . contentstackFieldType ;
285+ const oldFieldtUid = field ?. backupFieldUid || '' ;
285286
286287 // Check if this field has children
287288 const hasChildren = fields . some ( f =>
288289 f . contentstackFieldUid &&
289- f . contentstackFieldUid . startsWith ( fieldUid + '.' )
290+ ( f . contentstackFieldUid . startsWith ( fieldUid + '.' ) || f . contentstackFieldUid . startsWith ( oldFieldtUid + '.' ) )
290291 ) ;
291292
292293 if ( hasChildren ) {
@@ -307,13 +308,14 @@ export function buildSchemaTree(fields: any[], parentUid = '', parentType = ''):
307308 ...child ,
308309 uid : childUid ,
309310 display_name : childDisplay ,
310- schema : buildSchemaTree ( fields , child . contentstackFieldUid , 'modular_blocks_child' )
311+ schema : buildSchemaTree ( fields , child . contentstackFieldUid , 'modular_blocks_child' , field ?. backupFieldUid || '' )
311312 } ;
312313 } ) ;
313314 } else if ( fieldType === 'group' ||
314315 ( fieldType === 'modular_blocks_child' && hasChildren ) ) {
316+ //console.info(`Building schema for group/modular_blocks_child: ${fieldUid}`);
315317 // Recursively build schema for groups and modular block children with nested content
316- result . schema = buildSchemaTree ( fields , fieldUid , fieldType ) ;
318+ result . schema = buildSchemaTree ( fields , fieldUid , fieldType , field ?. backupFieldUid ) ;
317319 }
318320 }
319321
@@ -1026,7 +1028,7 @@ export const contenTypeMaker = async ({ contentType, destinationStackId, project
10261028 // Use the deep converter that properly handles groups & modular blocks
10271029 for ( const item of ctData ) {
10281030 if ( item ?. isDeleted === true ) continue ;
1029-
1031+ //console.info("item --> ", item)
10301032 const fieldSchema = buildFieldSchema ( item , marketPlacePath , '' ) ;
10311033 if ( fieldSchema ) {
10321034 ct ?. schema . push ( fieldSchema ) ;
@@ -1037,6 +1039,7 @@ export const contenTypeMaker = async ({ contentType, destinationStackId, project
10371039 ct . schema = removeDuplicateFields ( ct . schema || [ ] ) ;
10381040
10391041 if ( currentCt ?. uid ) {
1042+ console . info ( 'Merging with existing content type:' , ctData ) ;
10401043 ct = await mergeTwoCts ( ct , currentCt ) ;
10411044 }
10421045 if ( ct ?. uid && Array . isArray ( ct ?. schema ) && ct ?. schema . length ) {
0 commit comments