@@ -53,14 +53,20 @@ export default class ContentType {
53
53
this . gfSchema = gfSchema ;
54
54
this . moduleName = this . validateModules ( moduleName ! , this . config . moduleConfig ) ;
55
55
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
+ ) ;
57
60
}
58
61
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 {
60
66
if ( Object . keys ( moduleConfig ) . includes ( moduleName ) ) {
61
67
return moduleName ;
62
68
}
63
- return 'content-types'
69
+ return 'content-types' ;
64
70
}
65
71
/**
66
72
* 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 {
121
127
if ( existsSync ( extensionPath ) ) {
122
128
try {
123
129
this . extensions = Object . keys ( JSON . parse ( readFileSync ( extensionPath , 'utf8' ) ) ) ;
124
- } catch ( error ) { }
130
+ } catch ( error ) { }
125
131
}
126
132
127
133
if ( existsSync ( marketplacePath ) ) {
@@ -134,7 +140,7 @@ export default class ContentType {
134
140
) as string [ ] ;
135
141
this . extensions . push ( ...metaData ) ;
136
142
}
137
- } catch ( error ) { }
143
+ } catch ( error ) { }
138
144
}
139
145
}
140
146
@@ -270,19 +276,19 @@ export default class ContentType {
270
276
271
277
return missingRefs . length
272
278
? [
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
+ ]
286
292
: [ ] ;
287
293
}
288
294
@@ -383,34 +389,46 @@ export default class ContentType {
383
389
const missingRefs : string [ ] = [ ] ;
384
390
let { reference_to, display_name, data_type } = field ;
385
391
386
- for ( const reference of reference_to ?? [ ] ) {
387
- // NOTE Can skip specific references keys (Ex, system defined keys can be skipped)
388
- if ( this . config . skipRefs . includes ( reference ) ) {
389
- 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
+ }
390
401
}
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
+ }
391
408
392
- const refExist = find ( this . ctSchema , { uid : reference } ) ;
409
+ const refExist = find ( this . ctSchema , { uid : reference } ) ;
393
410
394
- if ( ! refExist ) {
395
- missingRefs . push ( reference ) ;
411
+ if ( ! refExist ) {
412
+ missingRefs . push ( reference ) ;
413
+ }
396
414
}
397
415
}
398
416
399
417
return missingRefs . length
400
418
? [
401
- {
402
- tree,
403
- data_type,
404
- missingRefs,
405
- display_name,
406
- ct_uid : this . currentUid ,
407
- name : this . currentTitle ,
408
- treeStr : tree
409
- . map ( ( { name } ) => name )
410
- . filter ( ( val ) => val )
411
- . join ( ' ➜ ' ) ,
412
- } ,
413
- ]
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
+ ]
414
432
: [ ] ;
415
433
}
416
434
@@ -635,19 +653,34 @@ export default class ContentType {
635
653
let fixStatus ;
636
654
const missingRefs : string [ ] = [ ] ;
637
655
const { reference_to, data_type, display_name } = field ;
638
- if ( ! Array . isArray ( reference_to ) ) {
639
- this . log ( $t ( auditMsg . CT_REFERENCE_FIELD , { reference_to, data_type, display_name } ) , { color : 'green' } ) ;
640
- }
641
- for ( const reference of reference_to ?? [ ] ) {
642
- // NOTE Can skip specific references keys (Ex, system defined keys can be skipped)
643
- if ( this . config . skipRefs . includes ( reference ) ) {
644
- 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
+ }
665
+ }
666
+
667
+ field . reference_to = [ reference_to ] ;
668
+ field . field_metadata = {
669
+ ...field . field_metadata ,
670
+ ref_multiple_content_types : true
645
671
}
672
+ } else {
673
+ for ( const reference of reference_to ?? [ ] ) {
674
+ // NOTE Can skip specific references keys (Ex, system defined keys can be skipped)
675
+ if ( this . config . skipRefs . includes ( reference ) ) {
676
+ continue ;
677
+ }
646
678
647
- const refExist = find ( this . ctSchema , { uid : reference } ) ;
679
+ const refExist = find ( this . ctSchema , { uid : reference } ) ;
648
680
649
- if ( ! refExist ) {
650
- missingRefs . push ( reference ) ;
681
+ if ( ! refExist ) {
682
+ missingRefs . push ( reference ) ;
683
+ }
651
684
}
652
685
}
653
686
0 commit comments