@@ -53,14 +53,20 @@ export default class ContentType {
5353 this . gfSchema = gfSchema ;
5454 this . moduleName = this . validateModules ( moduleName ! , this . config . moduleConfig ) ;
5555 this . fileName = config . moduleConfig [ this . moduleName ] . fileName ;
56- this . folderPath = resolve ( sanitizePath ( config . basePath ) , sanitizePath ( config . moduleConfig [ this . moduleName ] . dirName ) ) ;
56+ this . folderPath = resolve (
57+ sanitizePath ( config . basePath ) ,
58+ sanitizePath ( config . moduleConfig [ this . moduleName ] . dirName ) ,
59+ ) ;
5760 }
5861
59- validateModules ( moduleName : keyof typeof auditConfig . moduleConfig , moduleConfig : Record < string , unknown > ) : keyof typeof auditConfig . moduleConfig {
62+ validateModules (
63+ moduleName : keyof typeof auditConfig . moduleConfig ,
64+ moduleConfig : Record < string , unknown > ,
65+ ) : keyof typeof auditConfig . moduleConfig {
6066 if ( Object . keys ( moduleConfig ) . includes ( moduleName ) ) {
6167 return moduleName ;
6268 }
63- return 'content-types'
69+ return 'content-types' ;
6470 }
6571 /**
6672 * The `run` function checks if a folder path exists, sets the schema based on the module name,
@@ -121,7 +127,7 @@ export default class ContentType {
121127 if ( existsSync ( extensionPath ) ) {
122128 try {
123129 this . extensions = Object . keys ( JSON . parse ( readFileSync ( extensionPath , 'utf8' ) ) ) ;
124- } catch ( error ) { }
130+ } catch ( error ) { }
125131 }
126132
127133 if ( existsSync ( marketplacePath ) ) {
@@ -134,7 +140,7 @@ export default class ContentType {
134140 ) as string [ ] ;
135141 this . extensions . push ( ...metaData ) ;
136142 }
137- } catch ( error ) { }
143+ } catch ( error ) { }
138144 }
139145 }
140146
@@ -270,19 +276,19 @@ export default class ContentType {
270276
271277 return missingRefs . length
272278 ? [
273- {
274- tree,
275- data_type,
276- missingRefs,
277- display_name,
278- ct_uid : this . currentUid ,
279- name : this . currentTitle ,
280- treeStr : tree
281- . map ( ( { name } ) => name )
282- . filter ( ( val ) => val )
283- . join ( ' ➜ ' ) ,
284- } ,
285- ]
279+ {
280+ tree,
281+ data_type,
282+ missingRefs,
283+ display_name,
284+ ct_uid : this . currentUid ,
285+ name : this . currentTitle ,
286+ treeStr : tree
287+ . map ( ( { name } ) => name )
288+ . filter ( ( val ) => val )
289+ . join ( ' ➜ ' ) ,
290+ } ,
291+ ]
286292 : [ ] ;
287293 }
288294
@@ -383,37 +389,46 @@ export default class ContentType {
383389 const missingRefs : string [ ] = [ ] ;
384390 let { reference_to, display_name, data_type } = field ;
385391
386- if ( ! Array . isArray ( reference_to ) ) {
387- this . log ( $t ( auditMsg . CT_REFERENCE_FIELD , { reference_to, data_type, display_name } ) , { color : 'green' } ) ;
388- }
389- for ( const reference of reference_to ?? [ ] ) {
390- // NOTE Can skip specific references keys (Ex, system defined keys can be skipped)
391- if ( this . config . skipRefs . includes ( reference ) ) {
392- continue ;
392+ if ( ! Array . isArray ( reference_to ) ) {
393+ this . log ( $t ( auditMsg . CT_REFERENCE_FIELD , { reference_to, data_type, display_name } ) , 'error' ) ;
394+ this . log ( $t ( auditMsg . CT_REFERENCE_FIELD , { reference_to, display_name } ) , 'info' ) ;
395+ if ( ! this . config . skipRefs . includes ( reference_to ) ) {
396+ const refExist = find ( this . ctSchema , { uid : reference_to } ) ;
397+
398+ if ( ! refExist ) {
399+ missingRefs . push ( reference_to ) ;
400+ }
393401 }
402+ } else {
403+ for ( const reference of reference_to ?? [ ] ) {
404+ // NOTE Can skip specific references keys (Ex, system defined keys can be skipped)
405+ if ( this . config . skipRefs . includes ( reference ) ) {
406+ continue ;
407+ }
394408
395- const refExist = find ( this . ctSchema , { uid : reference } ) ;
409+ const refExist = find ( this . ctSchema , { uid : reference } ) ;
396410
397- if ( ! refExist ) {
398- missingRefs . push ( reference ) ;
411+ if ( ! refExist ) {
412+ missingRefs . push ( reference ) ;
413+ }
399414 }
400415 }
401416
402417 return missingRefs . length
403418 ? [
404- {
405- tree,
406- data_type,
407- missingRefs,
408- display_name,
409- ct_uid : this . currentUid ,
410- name : this . currentTitle ,
411- treeStr : tree
412- . map ( ( { name } ) => name )
413- . filter ( ( val ) => val )
414- . join ( ' ➜ ' ) ,
415- } ,
416- ]
419+ {
420+ tree,
421+ data_type,
422+ missingRefs,
423+ display_name,
424+ ct_uid : this . currentUid ,
425+ name : this . currentTitle ,
426+ treeStr : tree
427+ . map ( ( { name } ) => name )
428+ . filter ( ( val ) => val )
429+ . join ( ' ➜ ' ) ,
430+ } ,
431+ ]
417432 : [ ] ;
418433 }
419434
@@ -638,19 +653,30 @@ export default class ContentType {
638653 let fixStatus ;
639654 const missingRefs : string [ ] = [ ] ;
640655 const { reference_to, data_type, display_name } = field ;
641- if ( ! Array . isArray ( reference_to ) ) {
642- this . log ( $t ( auditMsg . CT_REFERENCE_FIELD , { reference_to, data_type, display_name } ) , { color : 'green' } ) ;
643- }
644- for ( const reference of reference_to ?? [ ] ) {
645- // NOTE Can skip specific references keys (Ex, system defined keys can be skipped)
646- if ( this . config . skipRefs . includes ( reference ) ) {
647- continue ;
656+ if ( ! Array . isArray ( reference_to ) ) {
657+ this . log ( $t ( auditMsg . CT_REFERENCE_FIELD , { reference_to, display_name } ) , 'error' ) ;
658+ this . log ( $t ( auditMsg . CT_REFERENCE_FIELD , { reference_to, display_name } ) , 'info' ) ;
659+ if ( ! this . config . skipRefs . includes ( reference_to ) ) {
660+ const refExist = find ( this . ctSchema , { uid : reference_to } ) ;
661+
662+ if ( ! refExist ) {
663+ missingRefs . push ( reference_to ) ;
664+ }
648665 }
649666
650- const refExist = find ( this . ctSchema , { uid : reference } ) ;
667+ field . reference_to = [ reference_to ] ;
668+ } else {
669+ for ( const reference of reference_to ?? [ ] ) {
670+ // NOTE Can skip specific references keys (Ex, system defined keys can be skipped)
671+ if ( this . config . skipRefs . includes ( reference ) ) {
672+ continue ;
673+ }
651674
652- if ( ! refExist ) {
653- missingRefs . push ( reference ) ;
675+ const refExist = find ( this . ctSchema , { uid : reference } ) ;
676+
677+ if ( ! refExist ) {
678+ missingRefs . push ( reference ) ;
679+ }
654680 }
655681 }
656682
0 commit comments