@@ -149,7 +149,7 @@ export default class ContentType {
149149 */
150150 async writeFixContent ( ) {
151151 let canWrite = true ;
152-
152+
153153 if ( ! this . inMemoryFix && this . fix ) {
154154 if ( ! this . config . flags [ 'copy-dir' ] && ! this . config . flags [ 'external-config' ] ?. skipConfirm ) {
155155 canWrite = this . config . flags . yes ?? ( await cliux . confirm ( commonMsg . FIX_CONFIRMATION ) ) ;
@@ -301,18 +301,35 @@ export default class ContentType {
301301 */
302302 async validateGlobalField ( tree : Record < string , unknown > [ ] , field : GlobalFieldDataType ) : Promise < void > {
303303 // NOTE Any GlobalField related logic can be added here
304- if ( ! field . schema && ! this . fix ) {
305- this . missingRefs [ this . currentUid ] . push ( {
306- tree,
307- ct_uid : this . currentUid ,
308- name : this . currentTitle ,
309- data_type : field . data_type ,
310- display_name : field . display_name ,
311- missingRefs : 'Empty schema found' ,
312- treeStr : tree . map ( ( { name } ) => name ) . join ( ' ➜ ' ) ,
313- } ) ;
304+ if ( this . moduleName === 'global-fields' ) {
305+ let { reference_to } = field ;
306+ const refExist = find ( this . schema , { uid : reference_to } ) ;
307+ if ( ! refExist ) {
308+ this . missingRefs [ this . currentUid ] . push ( {
309+ tree,
310+ ct : this . currentUid ,
311+ name : this . currentTitle ,
312+ data_type : field . data_type ,
313+ display_name : field . display_name ,
314+ missingRefs : 'Referred Global Field Does not Exist' ,
315+ treeStr : tree . map ( ( { name } ) => name ) . join ( ' ➜ ' ) ,
316+ } ) ;
317+ return void 0 ;
318+ }
319+ } else if ( this . moduleName === 'content-types' ) {
320+ if ( ! field . schema && ! this . fix ) {
321+ this . missingRefs [ this . currentUid ] . push ( {
322+ tree,
323+ ct_uid : this . currentUid ,
324+ name : this . currentTitle ,
325+ data_type : field . data_type ,
326+ display_name : field . display_name ,
327+ missingRefs : 'Empty schema found' ,
328+ treeStr : tree . map ( ( { name } ) => name ) . join ( ' ➜ ' ) ,
329+ } ) ;
314330
315- return void 0 ;
331+ return void 0 ;
332+ }
316333 }
317334
318335 await this . lookForReference ( tree , field ) ;
@@ -443,7 +460,7 @@ export default class ContentType {
443460 runFixOnSchema ( tree : Record < string , unknown > [ ] , schema : ContentTypeSchemaType [ ] ) {
444461 // NOTE Global field Fix
445462 return schema
446- . map ( ( field ) => {
463+ ? .map ( ( field ) => {
447464 const { data_type } = field ;
448465 const fixTypes = this . config . flags [ 'fix-only' ] ?? this . config [ 'fix-fields' ] ;
449466
@@ -524,12 +541,11 @@ export default class ContentType {
524541 missingRefs : [ reference_to ] ,
525542 treeStr : tree . map ( ( { name } ) => name ) . join ( ' ➜ ' ) ,
526543 } ) ;
527- } else if ( ! field . schema ) {
544+ } else if ( ! field . schema && this . moduleName === 'content-types' ) {
528545 const gfSchema = find ( this . gfSchema , { uid : field . reference_to } ) ?. schema ;
529-
530546 if ( gfSchema ) {
531547 field . schema = gfSchema as GlobalFieldSchemaTypes [ ] ;
532-
548+ } else {
533549 this . missingRefs [ this . currentUid ] . push ( {
534550 tree,
535551 data_type,
@@ -541,8 +557,27 @@ export default class ContentType {
541557 treeStr : tree . map ( ( { name } ) => name ) . join ( ' ➜ ' ) ,
542558 } ) ;
543559 }
560+ } else if ( ! field . schema && this . moduleName === 'global-fields' ) {
561+ const gfSchema = find ( this . gfSchema , { uid : field . reference_to } ) ?. schema ;
562+ if ( gfSchema ) {
563+ field . schema = gfSchema as GlobalFieldSchemaTypes [ ] ;
564+ } else {
565+ this . missingRefs [ this . currentUid ] . push ( {
566+ tree,
567+ data_type,
568+ display_name,
569+ fixStatus : 'Fixed' ,
570+ ct_uid : this . currentUid ,
571+ name : this . currentTitle ,
572+ missingRefs : 'Referred Global Field Does not exist' ,
573+ treeStr : tree . map ( ( { name } ) => name ) . join ( ' ➜ ' ) ,
574+ } ) ;
575+ }
544576 }
545577
578+ if ( field . schema && ! isEmpty ( field . schema ) ) {
579+ field . schema = this . runFixOnSchema ( tree , field . schema as ContentTypeSchemaType [ ] ) ;
580+ }
546581 return refExist ? field : null ;
547582 }
548583
@@ -559,7 +594,7 @@ export default class ContentType {
559594 */
560595 fixModularBlocksReferences ( tree : Record < string , unknown > [ ] , blocks : ModularBlockType [ ] ) {
561596 return blocks
562- . map ( ( block ) => {
597+ ? .map ( ( block ) => {
563598 const { reference_to, schema, title : display_name } = block ;
564599 tree = [ ...tree , { uid : block . uid , name : block . title } ] ;
565600 const refErrorObj = {
@@ -572,7 +607,7 @@ export default class ContentType {
572607 treeStr : tree . map ( ( { name } ) => name ) . join ( ' ➜ ' ) ,
573608 } ;
574609
575- if ( ! schema ) {
610+ if ( ! schema && this . moduleName === 'content-types' ) {
576611 this . missingRefs [ this . currentUid ] . push ( refErrorObj ) ;
577612
578613 return false ;
@@ -581,7 +616,11 @@ export default class ContentType {
581616 // NOTE Global field section
582617 if ( reference_to ) {
583618 const refExist = find ( this . gfSchema , { uid : reference_to } ) ;
619+ if ( ! refExist ) {
620+ this . missingRefs [ this . currentUid ] . push ( refErrorObj ) ;
584621
622+ return false ;
623+ }
585624 if ( ! refExist ) {
586625 this . missingRefs [ this . currentUid ] . push ( refErrorObj ) ;
587626
@@ -591,7 +630,7 @@ export default class ContentType {
591630
592631 block . schema = this . runFixOnSchema ( tree , block . schema as ContentTypeSchemaType [ ] ) ;
593632
594- if ( isEmpty ( block . schema ) ) {
633+ if ( isEmpty ( block . schema ) && this . moduleName === 'content-types' ) {
595634 this . missingRefs [ this . currentUid ] . push ( {
596635 ...refErrorObj ,
597636 missingRefs : 'Empty schema found' ,
0 commit comments