@@ -5,7 +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 { cliux , sanitizePath , TableFlags , TableHeader , log , configHandler } from '@contentstack/cli-utilities' ;
8+ import { cliux , sanitizePath , TableFlags , TableHeader , log , configHandler , CLIProgressManager , clearProgressModuleSetting } from '@contentstack/cli-utilities' ;
99import { createWriteStream , existsSync , mkdirSync , readFileSync , writeFileSync , rmSync } from 'fs' ;
1010import config from './config' ;
1111import { print } from './util/log' ;
@@ -71,11 +71,23 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
7171 */
7272 async start ( command : CommandNames ) : Promise < boolean > {
7373 this . currentCommand = command ;
74+
75+ // Set progress supported module and console logs setting BEFORE any log calls
76+ // This ensures the logger respects the setting when it's initialized
77+ const logConfig = configHandler . get ( 'log' ) || { } ;
78+ // Default to false so progress bars are shown instead of console logs
79+ if ( logConfig . showConsoleLogs === undefined ) {
80+ configHandler . set ( 'log.showConsoleLogs' , false ) ;
81+ }
82+ configHandler . set ( 'log.progressSupportedModule' , 'audit' ) ;
83+
7484 // Initialize audit context
7585 this . auditContext = this . createAuditContext ( ) ;
7686 log . debug ( `Starting audit command: ${ command } ` , this . auditContext ) ;
7787 log . info ( `Starting audit command: ${ command } ` , this . auditContext ) ;
78-
88+
89+ // Initialize global summary for progress tracking
90+ CLIProgressManager . initializeGlobalSummary ( 'AUDIT' , '' , 'Auditing content...' ) ;
7991
8092 await this . promptQueue ( ) ;
8193 await this . createBackUp ( ) ;
@@ -163,6 +175,12 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
163175 }
164176 }
165177
178+ // Print comprehensive summary at the end
179+ CLIProgressManager . printGlobalSummary ( ) ;
180+
181+ // Clear progress module setting now that audit is complete
182+ clearProgressModuleSetting ( ) ;
183+
166184 return (
167185 ! isEmpty ( missingCtRefs ) ||
168186 ! isEmpty ( missingGfRefs ) ||
@@ -222,47 +240,59 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
222240
223241 let dataModuleWise : Record < string , any > = await new ModuleDataReader ( cloneDeep ( constructorParam ) ) . run ( ) ;
224242 log . debug ( `Data module wise: ${ JSON . stringify ( dataModuleWise ) } ` , this . auditContext ) ;
243+
244+ // Extract logConfig and showConsoleLogs once before the loop to reuse throughout
245+ const logConfig = configHandler . get ( 'log' ) || { } ;
246+ const showConsoleLogs = logConfig . showConsoleLogs ?? true ;
247+
225248 for ( const module of this . sharedConfig . flags . modules || this . sharedConfig . modules ) {
226249 // Update audit context with current module
227250 this . auditContext = this . createAuditContext ( module ) ;
228251 log . debug ( `Starting audit for module: ${ module } ` , this . auditContext ) ;
229252 log . info ( `Starting audit for module: ${ module } ` , this . auditContext ) ;
230253
231- print ( [
232- {
233- bold : true ,
234- color : 'whiteBright' ,
235- message : this . $t ( this . messages . AUDIT_START_SPINNER , { module } ) ,
236- } ,
237- ] ) ;
254+ // Only show spinner message if console logs are enabled (compatible with line-by-line logs)
255+ if ( showConsoleLogs ) {
256+ print ( [
257+ {
258+ bold : true ,
259+ color : 'whiteBright' ,
260+ message : this . $t ( this . messages . AUDIT_START_SPINNER , { module } ) ,
261+ } ,
262+ ] ) ;
263+ }
238264
239265 constructorParam [ 'moduleName' ] = module ;
240266
241267 switch ( module ) {
242268 case 'assets' :
243269 log . info ( 'Executing assets audit' , this . auditContext ) ;
244- missingEnvLocalesInAssets = await new Assets ( cloneDeep ( constructorParam ) ) . run ( ) ;
270+ const assetsTotalCount = dataModuleWise [ 'assets' ] ?. Total || 0 ;
271+ missingEnvLocalesInAssets = await new Assets ( cloneDeep ( constructorParam ) ) . run ( false , assetsTotalCount ) ;
245272 await this . prepareReport ( module , missingEnvLocalesInAssets ) ;
246273 this . getAffectedData ( 'assets' , dataModuleWise [ 'assets' ] , missingEnvLocalesInAssets ) ;
247274 log . success ( `Assets audit completed. Found ${ Object . keys ( missingEnvLocalesInAssets || { } ) . length } issues` , this . auditContext ) ;
248275 break ;
249276 case 'content-types' :
250277 log . info ( 'Executing content-types audit' , this . auditContext ) ;
251- missingCtRefs = await new ContentType ( cloneDeep ( constructorParam ) ) . run ( ) ;
278+ const contentTypesTotalCount = dataModuleWise [ 'content-types' ] ?. Total || 0 ;
279+ missingCtRefs = await new ContentType ( cloneDeep ( constructorParam ) ) . run ( false , contentTypesTotalCount ) ;
252280 await this . prepareReport ( module , missingCtRefs ) ;
253281 this . getAffectedData ( 'content-types' , dataModuleWise [ 'content-types' ] , missingCtRefs ) ;
254282 log . success ( `Content-types audit completed. Found ${ Object . keys ( missingCtRefs || { } ) . length } issues` , this . auditContext ) ;
255283 break ;
256284 case 'global-fields' :
257285 log . info ( 'Executing global-fields audit' , this . auditContext ) ;
258- 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 ) ;
259288 await this . prepareReport ( module , missingGfRefs ) ;
260289 this . getAffectedData ( 'global-fields' , dataModuleWise [ 'global-fields' ] , missingGfRefs ) ;
261290 log . success ( `Global-fields audit completed. Found ${ Object . keys ( missingGfRefs || { } ) . length } issues` , this . auditContext ) ;
262291 break ;
263292 case 'entries' :
264293 log . info ( 'Executing entries audit' , this . auditContext ) ;
265- missingEntry = await new Entries ( cloneDeep ( constructorParam ) ) . run ( ) ;
294+ const entriesTotalCount = dataModuleWise [ 'entries' ] ?. Total || 0 ;
295+ missingEntry = await new Entries ( cloneDeep ( constructorParam ) ) . run ( entriesTotalCount ) ;
266296 missingEntryRefs = missingEntry . missingEntryRefs ?? { } ;
267297 missingSelectFeild = missingEntry . missingSelectFeild ?? { } ;
268298 missingMandatoryFields = missingEntry . missingMandatoryFields ?? { } ;
@@ -286,27 +316,30 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
286316 break ;
287317 case 'workflows' :
288318 log . info ( 'Executing workflows audit' , this . auditContext ) ;
319+ const workflowsTotalCount = dataModuleWise [ 'workflows' ] ?. Total || 0 ;
289320 missingCtRefsInWorkflow = await new Workflows ( {
290321 ctSchema,
291322 moduleName : module ,
292323 config : this . sharedConfig ,
293324 fix : this . currentCommand === 'cm:stacks:audit:fix' ,
294- } ) . run ( ) ;
325+ } ) . run ( workflowsTotalCount ) ;
295326 await this . prepareReport ( module , missingCtRefsInWorkflow ) ;
296327 this . getAffectedData ( 'workflows' , dataModuleWise [ 'workflows' ] , missingCtRefsInWorkflow ) ;
297328 log . success ( `Workflows audit completed. Found ${ Object . keys ( missingCtRefsInWorkflow || { } ) . length } issues` , this . auditContext ) ;
298329
299330 break ;
300331 case 'extensions' :
301332 log . info ( 'Executing extensions audit' , this . auditContext ) ;
302- missingCtRefsInExtensions = await new Extensions ( cloneDeep ( constructorParam ) ) . run ( ) ;
333+ const extensionsTotalCount = dataModuleWise [ 'extensions' ] ?. Total || 0 ;
334+ missingCtRefsInExtensions = await new Extensions ( cloneDeep ( constructorParam ) ) . run ( extensionsTotalCount ) ;
303335 await this . prepareReport ( module , missingCtRefsInExtensions ) ;
304336 this . getAffectedData ( 'extensions' , dataModuleWise [ 'extensions' ] , missingCtRefsInExtensions ) ;
305337 log . success ( `Extensions audit completed. Found ${ Object . keys ( missingCtRefsInExtensions || { } ) . length } issues` , this . auditContext ) ;
306338 break ;
307339 case 'custom-roles' :
308340 log . info ( 'Executing custom-roles audit' , this . auditContext ) ;
309- missingRefInCustomRoles = await new CustomRoles ( cloneDeep ( constructorParam ) ) . run ( ) ;
341+ const customRolesTotalCount = dataModuleWise [ 'custom-roles' ] ?. Total || 0 ;
342+ missingRefInCustomRoles = await new CustomRoles ( cloneDeep ( constructorParam ) ) . run ( customRolesTotalCount ) ;
310343 await this . prepareReport ( module , missingRefInCustomRoles ) ;
311344 this . getAffectedData ( 'custom-roles' , dataModuleWise [ 'custom-roles' ] , missingRefInCustomRoles ) ;
312345 log . success ( `Custom-roles audit completed. Found ${ Object . keys ( missingRefInCustomRoles || { } ) . length } issues` , this . auditContext ) ;
@@ -318,25 +351,29 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
318351 const data = this . getCtAndGfSchema ( ) ;
319352 constructorParam . ctSchema = data . ctSchema ;
320353 constructorParam . gfSchema = data . gfSchema ;
321- missingFieldRules = await new FieldRule ( cloneDeep ( constructorParam ) ) . run ( ) ;
354+ const fieldRulesTotalCount = dataModuleWise [ 'content-types' ] ?. Total || 0 ;
355+ missingFieldRules = await new FieldRule ( cloneDeep ( constructorParam ) ) . run ( fieldRulesTotalCount ) ;
322356 await this . prepareReport ( module , missingFieldRules ) ;
323357 this . getAffectedData ( 'field-rules' , dataModuleWise [ 'content-types' ] , missingFieldRules ) ;
324358 log . success ( `Field-rules audit completed. Found ${ Object . keys ( missingFieldRules || { } ) . length } issues` , this . auditContext ) ;
325359 break ;
326360 }
327361
328- print ( [
329- {
330- bold : true ,
331- color : 'whiteBright' ,
332- message : this . $t ( this . messages . AUDIT_START_SPINNER , { module } ) ,
333- } ,
334- {
335- bold : true ,
336- message : ' done' ,
337- color : 'whiteBright' ,
338- } ,
339- ] ) ;
362+ // Only show completion message if console logs are enabled
363+ if ( showConsoleLogs ) {
364+ print ( [
365+ {
366+ bold : true ,
367+ color : 'whiteBright' ,
368+ message : this . $t ( this . messages . AUDIT_START_SPINNER , { module } ) ,
369+ } ,
370+ {
371+ bold : true ,
372+ message : ' done' ,
373+ color : 'whiteBright' ,
374+ } ,
375+ ] ) ;
376+ }
340377 }
341378
342379 log . debug ( 'Scan and fix process completed' , this . auditContext ) ;
0 commit comments