@@ -30,11 +30,10 @@ import {
3030 RefErrorReturnType ,
3131 WorkflowExtensionsRefErrorReturnType ,
3232} from './types' ;
33- import { size } from 'lodash' ;
3433
3534export abstract class AuditBaseCommand extends BaseCommand < typeof AuditBaseCommand > {
3635 private currentCommand ! : CommandNames ;
37- private summaryDataToPrint : Record < string , any > = [ ] ;
36+ private readonly summaryDataToPrint : Record < string , any > = [ ] ;
3837 get fixStatus ( ) {
3938 return {
4039 fixStatus : {
@@ -202,17 +201,17 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
202201 case 'assets' :
203202 missingEnvLocalesInAssets = await new Assets ( cloneDeep ( constructorParam ) ) . run ( ) ;
204203 await this . prepareReport ( module , missingEnvLocalesInAssets ) ;
205- await this . getAffectedData ( 'assets' , DataModuleWise [ 'assets' ] , missingEnvLocalesInAssets ) ;
204+ this . getAffectedData ( 'assets' , DataModuleWise [ 'assets' ] , missingEnvLocalesInAssets ) ;
206205 break ;
207206 case 'content-types' :
208207 missingCtRefs = await new ContentType ( cloneDeep ( constructorParam ) ) . run ( ) ;
209208 await this . prepareReport ( module , missingCtRefs ) ;
210- await this . getAffectedData ( 'content-types' , DataModuleWise [ 'content-types' ] , missingCtRefs ) ;
209+ this . getAffectedData ( 'content-types' , DataModuleWise [ 'content-types' ] , missingCtRefs ) ;
211210 break ;
212211 case 'global-fields' :
213212 missingGfRefs = await new GlobalField ( cloneDeep ( constructorParam ) ) . run ( ) ;
214213 await this . prepareReport ( module , missingGfRefs ) ;
215- await this . getAffectedData ( 'global-fields' , DataModuleWise [ 'global-fields' ] , missingGfRefs ) ;
214+ this . getAffectedData ( 'global-fields' , DataModuleWise [ 'global-fields' ] , missingGfRefs ) ;
216215 break ;
217216 case 'entries' :
218217 missingEntry = await new Entries ( cloneDeep ( constructorParam ) ) . run ( ) ;
@@ -233,7 +232,7 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
233232 await this . prepareReport ( 'Entry_Missing_Locale_and_Env_in_Publish_Details' , missingEnvLocalesInEntries ) ;
234233
235234 await this . prepareReport ( 'Entry_Multiple_Fields' , missingMultipleFields ) ;
236- await this . getAffectedData ( 'entries' , DataModuleWise [ 'entries' ] , missingEntry ) ;
235+ this . getAffectedData ( 'entries' , DataModuleWise [ 'entries' ] , missingEntry ) ;
237236
238237 break ;
239238 case 'workflows' :
@@ -245,26 +244,27 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
245244 fix : this . currentCommand === 'cm:stacks:audit:fix' ,
246245 } ) . run ( ) ;
247246 await this . prepareReport ( module , missingCtRefsInWorkflow ) ;
248- await this . getAffectedData ( 'workflows' , DataModuleWise [ 'workflows' ] , missingCtRefsInWorkflow ) ;
247+ this . getAffectedData ( 'workflows' , DataModuleWise [ 'workflows' ] , missingCtRefsInWorkflow ) ;
249248
250249 break ;
251250 case 'extensions' :
252251 missingCtRefsInExtensions = await new Extensions ( cloneDeep ( constructorParam ) ) . run ( ) ;
253252 await this . prepareReport ( module , missingCtRefsInExtensions ) ;
254- await this . getAffectedData ( 'extensions' , DataModuleWise [ 'extensions' ] , missingCtRefsInExtensions ) ;
253+ this . getAffectedData ( 'extensions' , DataModuleWise [ 'extensions' ] , missingCtRefsInExtensions ) ;
255254 break ;
256255 case 'custom-roles' :
257256 missingRefInCustomRoles = await new CustomRoles ( cloneDeep ( constructorParam ) ) . run ( ) ;
258257 await this . prepareReport ( module , missingRefInCustomRoles ) ;
259- await this . getAffectedData ( 'custom-roles' , DataModuleWise [ 'custom-roles' ] , missingRefInCustomRoles ) ;
258+ this . getAffectedData ( 'custom-roles' , DataModuleWise [ 'custom-roles' ] , missingRefInCustomRoles ) ;
260259
261260 break ;
262261 case 'field-rules' :
263262 missingFieldRules = await new FieldRule ( cloneDeep ( constructorParam ) ) . run ( ) ;
264263 await this . prepareReport ( module , missingFieldRules ) ;
265- await this . getAffectedData ( 'field-rules' , DataModuleWise [ 'content-types' ] , missingFieldRules ) ;
264+ this . getAffectedData ( 'field-rules' , DataModuleWise [ 'content-types' ] , missingFieldRules ) ;
266265 break ;
267266 }
267+
268268 print ( [
269269 {
270270 bold : true ,
@@ -574,58 +574,44 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
574574 }
575575 }
576576
577- async getAffectedData (
578- Module : string ,
579- dataExported : any ,
577+ getAffectedData (
578+ module : string ,
579+ dataExported : Record < string , any > ,
580580 listOfMissingRefs : Record < string , any > ,
581581 isFixable : boolean = true ,
582- ) {
583- if ( Module === 'entries' ) {
584- const key = Object . keys ( listOfMissingRefs ) ;
585- const uidSet = new Set ( ) ;
586- const nonFixable = new Set ( ) ;
587- key . forEach ( ( k ) => {
588- if ( k != 'missingTitleFields' ) Object . keys ( listOfMissingRefs [ k ] ) . forEach ( ( kv2 ) => uidSet . add ( kv2 ) ) ;
589- else
590- Object . keys ( listOfMissingRefs [ k ] ) . forEach ( ( kv ) => {
591- if ( uidSet . has ( kv ) ) {
592- uidSet . delete ( kv ) ;
593- nonFixable . add ( kv ) ;
582+ ) : void {
583+ const result : Record < string , any > = { Module : module , ...dataExported } ;
584+
585+ if ( module === 'entries' ) {
586+ const missingRefs = Object . entries ( listOfMissingRefs ) ;
587+ const uidSet = new Set < string > ( ) ;
588+ const nonFixable = new Set < string > ( ) ;
589+
590+ for ( const [ key , refs ] of missingRefs ) {
591+ const uids = Object . keys ( refs ) ;
592+ if ( key !== 'missingTitleFields' ) {
593+ uids . forEach ( ( uid ) => uidSet . add ( uid ) ) ;
594+ } else {
595+ uids . forEach ( ( uid ) => {
596+ if ( uidSet . has ( uid ) ) {
597+ uidSet . delete ( uid ) ;
598+ nonFixable . add ( uid ) ;
594599 }
595600 } ) ;
596- } ) ;
597- dataExported = {
598- Module,
599- ...dataExported ,
600- Passed : dataExported [ 'Total' ] - size ( uidSet ) ,
601- Fixable : size ( uidSet ) - size ( nonFixable ) ,
602- 'Non-Fixable' : size ( nonFixable ) ,
603- } ;
604- } else {
605- if ( Object . keys ( listOfMissingRefs ) . length ) {
606- const uidSet = new Set ( Object . keys ( listOfMissingRefs ) ) ;
607- dataExported = {
608- Module,
609- ...dataExported ,
610- Passed : dataExported [ 'Total' ] - size ( uidSet ) ,
611- } ;
612- if ( isFixable ) {
613- dataExported [ 'Fixable' ] = size ( uidSet ) ;
614- dataExported [ 'Non-Fixable' ] = 0 ;
615- } else {
616- dataExported [ 'Fixable' ] = 0 ;
617- dataExported [ 'Non-Fixable' ] = size ( uidSet ) ;
618601 }
619- } else {
620- dataExported = {
621- Module,
622- ...dataExported ,
623- Passed : dataExported [ 'Total' ] ,
624- } ;
625- ( dataExported [ 'Fixable' ] = 0 ) , ( dataExported [ 'Non-Fixable' ] = 0 ) ;
626602 }
603+
604+ result . Passed = dataExported . Total - uidSet . size ;
605+ result . Fixable = uidSet . size - nonFixable . size ;
606+ result [ 'Non-Fixable' ] = nonFixable . size ;
607+ } else {
608+ const missingCount = Object . keys ( listOfMissingRefs ) . length ;
609+ result . Passed = dataExported . Total - missingCount ;
610+
611+ result . Fixable = missingCount > 0 && isFixable ? missingCount : 0 ;
612+ result [ 'Non-Fixable' ] = missingCount > 0 && ! isFixable ? missingCount : 0 ;
627613 }
628614
629- this . summaryDataToPrint . push ( dataExported ) ;
615+ this . summaryDataToPrint . push ( result ) ;
630616 }
631617}
0 commit comments