@@ -72,23 +72,7 @@ export default class Entries {
7272 }
7373
7474 await this . prepareEntryMetaData ( ) ;
75-
76- this . ctSchema = ( await new ContentType ( {
77- fix : true ,
78- log : ( ) => { } ,
79- config : this . config ,
80- moduleName : 'content-types' ,
81- ctSchema : this . ctSchema ,
82- gfSchema : this . gfSchema ,
83- } ) . run ( true ) ) as ContentTypeStruct [ ] ;
84- this . gfSchema = ( await new ContentType ( {
85- fix : true ,
86- log : ( ) => { } ,
87- config : this . config ,
88- moduleName : 'entries' ,
89- ctSchema : this . ctSchema ,
90- gfSchema : this . gfSchema ,
91- } ) . run ( true ) ) as ContentTypeStruct [ ] ;
75+ await this . fixPrerequisiteData ( ) ;
9276
9377 for ( const { code } of this . locales ) {
9478 for ( const ctSchema of this . ctSchema ) {
@@ -125,13 +109,43 @@ export default class Entries {
125109 }
126110 this . log ( '' , 'info' ) ; // Adding empty line
127111
112+ this . removeEmptyVal ( ) ;
113+
114+ return this . missingRefs ;
115+ }
116+
117+ /**
118+ * The function removes any properties from the `missingRefs` object that have an empty array value.
119+ */
120+ removeEmptyVal ( ) {
128121 for ( let propName in this . missingRefs ) {
129122 if ( ! this . missingRefs [ propName ] . length ) {
130123 delete this . missingRefs [ propName ] ;
131124 }
132125 }
126+ }
133127
134- return this . missingRefs ;
128+ /**
129+ * The function `fixPrerequisiteData` fixes the prerequisite data by updating the `ctSchema` and
130+ * `gfSchema` properties using the `ContentType` class.
131+ */
132+ async fixPrerequisiteData ( ) {
133+ this . ctSchema = ( await new ContentType ( {
134+ fix : true ,
135+ log : ( ) => { } ,
136+ config : this . config ,
137+ moduleName : 'content-types' ,
138+ ctSchema : this . ctSchema ,
139+ gfSchema : this . gfSchema ,
140+ } ) . run ( true ) ) as ContentTypeStruct [ ] ;
141+ this . gfSchema = ( await new ContentType ( {
142+ fix : true ,
143+ log : ( ) => { } ,
144+ config : this . config ,
145+ moduleName : 'entries' ,
146+ ctSchema : this . ctSchema ,
147+ gfSchema : this . gfSchema ,
148+ } ) . run ( true ) ) as ContentTypeStruct [ ] ;
135149 }
136150
137151 /**
@@ -449,13 +463,14 @@ export default class Entries {
449463 if ( data_type === 'json' ) {
450464 if ( field . field_metadata . extension ) {
451465 // NOTE Custom field type
452- return field ;
466+ break ;
453467 } else if ( field . field_metadata . allow_json_rte ) {
454- return this . fixJsonRteMissingReferences (
468+ this . fixJsonRteMissingReferences (
455469 [ ...tree , { uid : field . uid , name : field . display_name , data_type : field . data_type } ] ,
456470 field as JsonRTEFieldDataType ,
457471 entry [ uid ] as EntryJsonRTEFieldDataType ,
458472 ) ;
473+ break ;
459474 }
460475 }
461476
@@ -464,7 +479,7 @@ export default class Entries {
464479 [ ...tree , { uid : field . uid , name : field . display_name , data_type : field . data_type } ] ,
465480 field as ReferenceFieldDataType ,
466481 entry [ uid ] as EntryReferenceFieldDataType [ ] ,
467- ) as EntryReferenceFieldDataType [ ] ;
482+ ) ;
468483 break ;
469484 case 'blocks' :
470485 entry [ uid ] = this . fixModularBlocksReferences (
@@ -541,7 +556,7 @@ export default class Entries {
541556
542557 return eBlock ;
543558 } )
544- . filter ( ( val ) => ! isEmpty ( val ) ) as EntryModularBlocksDataType [ ] ;
559+ . filter ( ( val ) => ! isEmpty ( val ) ) ;
545560 } ) ;
546561
547562 return entry ;
@@ -604,11 +619,7 @@ export default class Entries {
604619 ) {
605620 if ( Array . isArray ( entry ) ) {
606621 entry = entry . map ( ( child : any , index ) => {
607- return this . fixJsonRteMissingReferences (
608- [ ...tree , { index, type : ( child as any ) ?. type , uid : child ?. uid } ] ,
609- field ,
610- child ,
611- ) ;
622+ return this . fixJsonRteMissingReferences ( [ ...tree , { index, type : child ?. type , uid : child ?. uid } ] , field , child ) ;
612623 } ) as EntryJsonRTEFieldDataType [ ] ;
613624 } else {
614625 entry . children = entry . children
@@ -669,7 +680,7 @@ export default class Entries {
669680 data_type : field . data_type ,
670681 display_name : field . display_name ,
671682 treeStr : tree
672- . map ( ( { name, index } ) => ( index || index === 0 ? `[${ index } ].${ name } ` : name ) )
683+ . map ( ( { name, index } ) => ( index || index === 0 ? `[${ + index } ].${ name } ` : name ) )
673684 . filter ( ( val ) => val )
674685 . join ( ' ➜ ' ) ,
675686 missingRefs,
@@ -697,7 +708,7 @@ export default class Entries {
697708 tree : Record < string , unknown > [ ] ,
698709 blocks : ModularBlockType [ ] ,
699710 entryBlock : EntryModularBlocksDataType ,
700- index : Number ,
711+ index : number ,
701712 ) {
702713 const validBlockUid = blocks . map ( ( block ) => block . uid ) ;
703714 const invalidKeys = Object . keys ( entryBlock ) . filter ( ( key ) => ! validBlockUid . includes ( key ) ) ;
@@ -715,7 +726,7 @@ export default class Entries {
715726 fixStatus : this . fix ? 'Fixed' : undefined ,
716727 tree : [ ...tree , { index, uid : key , name : key } ] ,
717728 treeStr : [ ...tree , { index, uid : key , name : key } ]
718- . map ( ( { name, index } ) => ( index || index === 0 ? `[${ index } ].${ name } ` : name ) )
729+ . map ( ( { name, index } ) => ( index || index === 0 ? `[${ + index } ].${ name } ` : name ) )
719730 . filter ( ( val ) => val )
720731 . join ( ' ➜ ' ) ,
721732 missingRefs : [ key ] ,
@@ -775,8 +786,8 @@ export default class Entries {
775786 const localesFolderPath = resolve ( this . config . basePath , this . config . moduleConfig . locales . dirName ) ;
776787 const localesPath = join ( localesFolderPath , this . config . moduleConfig . locales . fileName ) ;
777788 const masterLocalesPath = join ( localesFolderPath , 'master-locale.json' ) ;
778- this . locales = values ( JSON . parse ( readFileSync ( masterLocalesPath , 'utf-8 ' ) ) ) ;
779- this . locales . push ( ...values ( JSON . parse ( readFileSync ( localesPath , 'utf-8 ' ) ) ) ) ;
789+ this . locales = values ( JSON . parse ( readFileSync ( masterLocalesPath , 'utf8 ' ) ) ) ;
790+ this . locales . push ( ...values ( JSON . parse ( readFileSync ( localesPath , 'utf8 ' ) ) ) ) ;
780791
781792 for ( const { code } of this . locales ) {
782793 for ( const { uid } of this . ctSchema ) {
0 commit comments