@@ -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,38 +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 } ) , 'error' ) ;
392+ if ( ! Array . isArray ( reference_to ) ) {
393+ this . log ( $t ( auditMsg . CT_REFERENCE_FIELD , { reference_to, data_type, display_name } ) , 'error' ) ;
388394 this . log ( $t ( auditMsg . CT_REFERENCE_FIELD , { reference_to, display_name } ) , 'info' ) ;
389- }
390- for ( const reference of reference_to ?? [ ] ) {
391- // NOTE Can skip specific references keys (Ex, system defined keys can be skipped)
392- if ( this . config . skipRefs . includes ( reference ) ) {
393- continue ;
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+ }
394401 }
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+ }
395408
396- const refExist = find ( this . ctSchema , { uid : reference } ) ;
409+ const refExist = find ( this . ctSchema , { uid : reference } ) ;
397410
398- if ( ! refExist ) {
399- missingRefs . push ( reference ) ;
411+ if ( ! refExist ) {
412+ missingRefs . push ( reference ) ;
413+ }
400414 }
401415 }
402416
403417 return missingRefs . length
404418 ? [
405- {
406- tree,
407- data_type,
408- missingRefs,
409- display_name,
410- ct_uid : this . currentUid ,
411- name : this . currentTitle ,
412- treeStr : tree
413- . map ( ( { name } ) => name )
414- . filter ( ( val ) => val )
415- . join ( ' ➜ ' ) ,
416- } ,
417- ]
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+ ]
418432 : [ ] ;
419433 }
420434
@@ -639,20 +653,30 @@ export default class ContentType {
639653 let fixStatus ;
640654 const missingRefs : string [ ] = [ ] ;
641655 const { reference_to, data_type, display_name } = field ;
642- if ( ! Array . isArray ( reference_to ) ) {
656+ if ( ! Array . isArray ( reference_to ) ) {
643657 this . log ( $t ( auditMsg . CT_REFERENCE_FIELD , { reference_to, display_name } ) , 'error' ) ;
644658 this . log ( $t ( auditMsg . CT_REFERENCE_FIELD , { reference_to, display_name } ) , 'info' ) ;
645- }
646- for ( const reference of reference_to ?? [ ] ) {
647- // NOTE Can skip specific references keys (Ex, system defined keys can be skipped)
648- if ( this . config . skipRefs . includes ( reference ) ) {
649- continue ;
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+ }
650665 }
651666
652- 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+ }
653674
654- if ( ! refExist ) {
655- missingRefs . push ( reference ) ;
675+ const refExist = find ( this . ctSchema , { uid : reference } ) ;
676+
677+ if ( ! refExist ) {
678+ missingRefs . push ( reference ) ;
679+ }
656680 }
657681 }
658682
0 commit comments