@@ -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,37 +389,46 @@ export default class ContentType {
383
389
const missingRefs : string [ ] = [ ] ;
384
390
let { reference_to, display_name, data_type } = field ;
385
391
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
+ }
393
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
+ }
394
408
395
- const refExist = find ( this . ctSchema , { uid : reference } ) ;
409
+ const refExist = find ( this . ctSchema , { uid : reference } ) ;
396
410
397
- if ( ! refExist ) {
398
- missingRefs . push ( reference ) ;
411
+ if ( ! refExist ) {
412
+ missingRefs . push ( reference ) ;
413
+ }
399
414
}
400
415
}
401
416
402
417
return missingRefs . length
403
418
? [
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
+ ]
417
432
: [ ] ;
418
433
}
419
434
@@ -638,19 +653,30 @@ export default class ContentType {
638
653
let fixStatus ;
639
654
const missingRefs : string [ ] = [ ] ;
640
655
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
+ }
648
665
}
649
666
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
+ }
651
674
652
- if ( ! refExist ) {
653
- missingRefs . push ( reference ) ;
675
+ const refExist = find ( this . ctSchema , { uid : reference } ) ;
676
+
677
+ if ( ! refExist ) {
678
+ missingRefs . push ( reference ) ;
679
+ }
654
680
}
655
681
}
656
682
0 commit comments