@@ -5,15 +5,7 @@ import { v4 as uuid } from 'uuid';
55import isEmpty from 'lodash/isEmpty' ;
66import { join , resolve } from 'path' ;
77import cloneDeep from 'lodash/cloneDeep' ;
8- import {
9- cliux ,
10- sanitizePath ,
11- TableFlags ,
12- TableHeader ,
13- log ,
14- configHandler ,
15- createLogContext ,
16- } from '@contentstack/cli-utilities' ;
8+ import { cliux , sanitizePath , TableFlags , TableHeader , log , configHandler , CLIProgressManager , clearProgressModuleSetting } from '@contentstack/cli-utilities' ;
179import { createWriteStream , existsSync , mkdirSync , readFileSync , writeFileSync , rmSync } from 'fs' ;
1810import config from './config' ;
1911import { print } from './util/log' ;
@@ -67,12 +59,19 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
6759 */
6860 async start ( command : CommandNames ) : Promise < boolean > {
6961 this . currentCommand = command ;
70- // Initialize audit context (reused, no need to call again in scanAndFix)
71- createLogContext ( this . context ?. info ?. command , '' , configHandler . get ( 'authenticationMethod' ) ) ;
72- this . auditContext = { module : 'audit' } ;
73- log . debug ( `Starting audit command: ${ command } ` , this . auditContext ) ;
74- log . info ( `Starting audit command: ${ command } ` , this . auditContext ) ;
75-
62+
63+ // Set progress supported module and console logs setting BEFORE any log calls
64+ // This ensures the logger respects the setting when it's initialized
65+ const logConfig = configHandler . get ( 'log' ) || { } ;
66+ // Default to false so progress bars are shown instead of console logs
67+ if ( logConfig . showConsoleLogs === undefined ) {
68+ configHandler . set ( 'log.showConsoleLogs' , false ) ;
69+ }
70+ configHandler . set ( 'log.progressSupportedModule' , 'audit' ) ;
71+
72+ // Initialize global summary for progress tracking
73+ CLIProgressManager . initializeGlobalSummary ( 'AUDIT' , '' , 'Auditing content...' ) ;
74+
7675 await this . promptQueue ( ) ;
7776 await this . createBackUp ( ) ;
7877 this . sharedConfig . reportPath = resolve ( this . flags [ 'report-path' ] || process . cwd ( ) , 'audit-report' ) ;
@@ -165,6 +164,12 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
165164 }
166165 }
167166
167+ // Print comprehensive summary at the end
168+ CLIProgressManager . printGlobalSummary ( ) ;
169+
170+ // Clear progress module setting now that audit is complete
171+ clearProgressModuleSetting ( ) ;
172+
168173 return (
169174 ! isEmpty ( missingCtRefs ) ||
170175 ! isEmpty ( missingGfRefs ) ||
@@ -229,26 +234,35 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
229234
230235 let dataModuleWise : Record < string , any > = await new ModuleDataReader ( cloneDeep ( constructorParam ) ) . run ( ) ;
231236 log . debug ( `Data module wise: ${ JSON . stringify ( dataModuleWise ) } ` , this . auditContext ) ;
237+
238+ // Extract logConfig and showConsoleLogs once before the loop to reuse throughout
239+ const logConfig = configHandler . get ( 'log' ) || { } ;
240+ const showConsoleLogs = logConfig . showConsoleLogs ?? true ;
241+
232242 for ( const module of this . sharedConfig . flags . modules || this . sharedConfig . modules ) {
233243 // Update audit context with current module
234244 this . auditContext = { module : module } ;
235245 log . debug ( `Starting audit for module: ${ module } ` , this . auditContext ) ;
236246 log . info ( `Starting audit for module: ${ module } ` , this . auditContext ) ;
237247
238- print ( [
239- {
240- bold : true ,
241- color : 'whiteBright' ,
242- message : this . $t ( this . messages . AUDIT_START_SPINNER , { module } ) ,
243- } ,
244- ] ) ;
248+ // Only show spinner message if console logs are enabled (compatible with line-by-line logs)
249+ if ( showConsoleLogs ) {
250+ print ( [
251+ {
252+ bold : true ,
253+ color : 'whiteBright' ,
254+ message : this . $t ( this . messages . AUDIT_START_SPINNER , { module } ) ,
255+ } ,
256+ ] ) ;
257+ }
245258
246259 constructorParam [ 'moduleName' ] = module ;
247260
248261 switch ( module ) {
249262 case 'assets' :
250263 log . info ( 'Executing assets audit' , this . auditContext ) ;
251- missingEnvLocalesInAssets = await new Assets ( cloneDeep ( constructorParam ) ) . run ( ) ;
264+ const assetsTotalCount = dataModuleWise [ 'assets' ] ?. Total || 0 ;
265+ missingEnvLocalesInAssets = await new Assets ( cloneDeep ( constructorParam ) ) . run ( false , assetsTotalCount ) ;
252266 await this . prepareReport ( module , missingEnvLocalesInAssets ) ;
253267 this . getAffectedData ( 'assets' , dataModuleWise [ 'assets' ] , missingEnvLocalesInAssets ) ;
254268 log . success (
@@ -258,7 +272,8 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
258272 break ;
259273 case 'content-types' :
260274 log . info ( 'Executing content-types audit' , this . auditContext ) ;
261- missingCtRefs = await new ContentType ( cloneDeep ( constructorParam ) ) . run ( ) ;
275+ const contentTypesTotalCount = dataModuleWise [ 'content-types' ] ?. Total || 0 ;
276+ missingCtRefs = await new ContentType ( cloneDeep ( constructorParam ) ) . run ( false , contentTypesTotalCount ) ;
262277 await this . prepareReport ( module , missingCtRefs ) ;
263278 this . getAffectedData ( 'content-types' , dataModuleWise [ 'content-types' ] , missingCtRefs ) ;
264279 log . success (
@@ -268,7 +283,8 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
268283 break ;
269284 case 'global-fields' :
270285 log . info ( 'Executing global-fields audit' , this . auditContext ) ;
271- missingGfRefs = await new GlobalField ( cloneDeep ( constructorParam ) ) . run ( ) ;
286+ const globalFieldsTotalCount = dataModuleWise [ 'global-fields' ] ?. Total || 0 ;
287+ missingGfRefs = await new GlobalField ( cloneDeep ( constructorParam ) ) . run ( false , globalFieldsTotalCount ) ;
272288 await this . prepareReport ( module , missingGfRefs ) ;
273289 this . getAffectedData ( 'global-fields' , dataModuleWise [ 'global-fields' ] , missingGfRefs ) ;
274290 log . success (
@@ -278,7 +294,8 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
278294 break ;
279295 case 'entries' :
280296 log . info ( 'Executing entries audit' , this . auditContext ) ;
281- missingEntry = await new Entries ( cloneDeep ( constructorParam ) ) . run ( ) ;
297+ const entriesTotalCount = dataModuleWise [ 'entries' ] ?. Total || 0 ;
298+ missingEntry = await new Entries ( cloneDeep ( constructorParam ) ) . run ( entriesTotalCount ) ;
282299 missingEntryRefs = missingEntry . missingEntryRefs ?? { } ;
283300 missingSelectFeild = missingEntry . missingSelectFeild ?? { } ;
284301 missingMandatoryFields = missingEntry . missingMandatoryFields ?? { } ;
@@ -305,12 +322,13 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
305322 break ;
306323 case 'workflows' :
307324 log . info ( 'Executing workflows audit' , this . auditContext ) ;
325+ const workflowsTotalCount = dataModuleWise [ 'workflows' ] ?. Total || 0 ;
308326 missingCtRefsInWorkflow = await new Workflows ( {
309327 ctSchema,
310328 moduleName : module ,
311329 config : this . sharedConfig ,
312330 fix : this . currentCommand === 'cm:stacks:audit:fix' ,
313- } ) . run ( ) ;
331+ } ) . run ( workflowsTotalCount ) ;
314332 await this . prepareReport ( module , missingCtRefsInWorkflow ) ;
315333 this . getAffectedData ( 'workflows' , dataModuleWise [ 'workflows' ] , missingCtRefsInWorkflow ) ;
316334 log . success (
@@ -321,7 +339,8 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
321339 break ;
322340 case 'extensions' :
323341 log . info ( 'Executing extensions audit' , this . auditContext ) ;
324- missingCtRefsInExtensions = await new Extensions ( cloneDeep ( constructorParam ) ) . run ( ) ;
342+ const extensionsTotalCount = dataModuleWise [ 'extensions' ] ?. Total || 0 ;
343+ missingCtRefsInExtensions = await new Extensions ( cloneDeep ( constructorParam ) ) . run ( extensionsTotalCount ) ;
325344 await this . prepareReport ( module , missingCtRefsInExtensions ) ;
326345 this . getAffectedData ( 'extensions' , dataModuleWise [ 'extensions' ] , missingCtRefsInExtensions ) ;
327346 log . success (
@@ -331,7 +350,8 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
331350 break ;
332351 case 'custom-roles' :
333352 log . info ( 'Executing custom-roles audit' , this . auditContext ) ;
334- missingRefInCustomRoles = await new CustomRoles ( cloneDeep ( constructorParam ) ) . run ( ) ;
353+ const customRolesTotalCount = dataModuleWise [ 'custom-roles' ] ?. Total || 0 ;
354+ missingRefInCustomRoles = await new CustomRoles ( cloneDeep ( constructorParam ) ) . run ( customRolesTotalCount ) ;
335355 await this . prepareReport ( module , missingRefInCustomRoles ) ;
336356 this . getAffectedData ( 'custom-roles' , dataModuleWise [ 'custom-roles' ] , missingRefInCustomRoles ) ;
337357 log . success (
@@ -346,7 +366,8 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
346366 const data = this . getCtAndGfSchema ( ) ;
347367 constructorParam . ctSchema = data . ctSchema ;
348368 constructorParam . gfSchema = data . gfSchema ;
349- missingFieldRules = await new FieldRule ( cloneDeep ( constructorParam ) ) . run ( ) ;
369+ const fieldRulesTotalCount = dataModuleWise [ 'content-types' ] ?. Total || 0 ;
370+ missingFieldRules = await new FieldRule ( cloneDeep ( constructorParam ) ) . run ( fieldRulesTotalCount ) ;
350371 await this . prepareReport ( module , missingFieldRules ) ;
351372 this . getAffectedData ( 'field-rules' , dataModuleWise [ 'content-types' ] , missingFieldRules ) ;
352373 log . success (
@@ -372,18 +393,21 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
372393 break ;
373394 }
374395
375- print ( [
376- {
377- bold : true ,
378- color : 'whiteBright' ,
379- message : this . $t ( this . messages . AUDIT_START_SPINNER , { module } ) ,
380- } ,
381- {
382- bold : true ,
383- message : ' done' ,
384- color : 'whiteBright' ,
385- } ,
386- ] ) ;
396+ // Only show completion message if console logs are enabled
397+ if ( showConsoleLogs ) {
398+ print ( [
399+ {
400+ bold : true ,
401+ color : 'whiteBright' ,
402+ message : this . $t ( this . messages . AUDIT_START_SPINNER , { module } ) ,
403+ } ,
404+ {
405+ bold : true ,
406+ message : ' done' ,
407+ color : 'whiteBright' ,
408+ } ,
409+ ] ) ;
410+ }
387411 }
388412
389413 log . debug ( 'Scan and fix process completed' , this . auditContext ) ;
0 commit comments