Skip to content

Commit ac66b24

Browse files
author
naman-contentstack
committed
fix: log mode consistecny
1 parent d8ddff9 commit ac66b24

5 files changed

Lines changed: 70 additions & 22 deletions

File tree

packages/contentstack-clone/src/commands/cm/stacks/clone.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ Use this plugin to automate the process of cloning a stack in few steps.
157157
async run(): Promise<void> {
158158
try {
159159
const self = this;
160+
configHandler.set('log.progressSupportedModule', 'clone');
160161
const { flags: cloneCommandFlags } = await self.parse(StackCloneCommand);
161162
const {
162163
yes,
@@ -227,7 +228,10 @@ Use this plugin to automate the process of cloning a stack in few steps.
227228
config.source_stack = listOfTokens[sourceManagementTokenAlias].apiKey;
228229
log.debug(`Using source token alias: ${sourceManagementTokenAlias}`, cloneContext);
229230
} else if (sourceManagementTokenAlias) {
230-
log.warn(`Provided source token alias (${sourceManagementTokenAlias}) not found in your config.!`, cloneContext);
231+
log.warn(
232+
`Provided source token alias (${sourceManagementTokenAlias}) not found in your config.!`,
233+
cloneContext,
234+
);
231235
}
232236
if (destinationManagementTokenAlias && listOfTokens?.[destinationManagementTokenAlias]) {
233237
config.destination_alias = destinationManagementTokenAlias;
@@ -284,7 +288,10 @@ Use this plugin to automate the process of cloning a stack in few steps.
284288
} catch (error: any) {
285289
if (error) {
286290
await this.cleanUp(pathdir, null, this.createCloneContext('unknown'));
287-
log.error('Stack clone command failed', { ...this.createCloneContext('unknown'), error: error?.message || error });
291+
log.error('Stack clone command failed', {
292+
...this.createCloneContext('unknown'),
293+
error: error?.message || error,
294+
});
288295
}
289296
}
290297
}

packages/contentstack-import/src/import/module-importer.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { resolve } from 'path';
22
import { AuditFix } from '@contentstack/cli-audit';
33
import messages, { $t } from '@contentstack/cli-audit/lib/messages';
4-
import { addLocale, cliux, ContentstackClient, log } from '@contentstack/cli-utilities';
4+
import { addLocale, cliux, ContentstackClient, log, CLIProgressManager } from '@contentstack/cli-utilities';
55

66
import startModuleImport from './modules';
77
import { ImportConfig, Modules } from '../types';
@@ -59,6 +59,14 @@ class ModuleImporter {
5959
if (!(await this.auditImportData())) {
6060
return { noSuccessMsg: true };
6161
}
62+
// Audit overwrote the global summary with 'AUDIT'. Re-initialize for IMPORT so the final
63+
// summary shows "IMPORT completed successfully!" and only import module stats.
64+
const branchName = this.importConfig.branchName || '';
65+
CLIProgressManager.initializeGlobalSummary(
66+
branchName ? `IMPORT-${branchName}` : 'IMPORT',
67+
branchName,
68+
'Importing content...',
69+
);
6270
}
6371

6472
if (!this.importConfig.master_locale) {

packages/contentstack-utilities/src/constants/logging.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ export const levelColors = {
1616
debug: 'blue',
1717
};
1818

19-
export const PROGRESS_SUPPORTED_MODULES = ['export', 'import', 'audit', 'import-setup'] as const;
19+
export const PROGRESS_SUPPORTED_MODULES = ['export', 'import', 'audit', 'import-setup', 'clone'] as const;

packages/contentstack-utilities/src/progress-summary/cli-progress-manager.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,20 @@ export default class CLIProgressManager {
9494
}
9595

9696
/**
97-
* Print the final summary for all modules using strategies
97+
* Print the final summary for all modules using strategies.
98+
* When showConsoleLogs is enabled, skip the Progress Manager summary block
99+
* so output is pure timestamped log lines (per documentation).
98100
*/
99101
static printGlobalSummary(): void {
100102
if (!CLIProgressManager.globalSummary) {
101103
return;
102104
}
103105

106+
const showConsoleLogs = configHandler.get('log')?.showConsoleLogs;
107+
if (showConsoleLogs) {
108+
return;
109+
}
110+
104111
// Apply strategy-based corrections before printing
105112
CLIProgressManager.applyStrategyCorrections();
106113

@@ -591,6 +598,11 @@ export default class CLIProgressManager {
591598
}
592599

593600
private printSummary(): void {
601+
// In console logs mode, use only timestamped log lines (no Progress Manager blocks)
602+
if (this.showConsoleLogs) {
603+
return;
604+
}
605+
594606
if (!this.enableNestedProgress) {
595607
// Simple summary for single progress
596608
this.log('\n' + chalk.bold(`${this.moduleName} Summary:`));

packages/contentstack-utilities/test/unit/cliProgressManager.test.ts

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Module.prototype.require = function (id: string) {
5757

5858
import CLIProgressManager from '../../src/progress-summary/cli-progress-manager';
5959
import SummaryManager from '../../src/progress-summary/summary-manager';
60+
import { configHandler } from '../../src';
6061

6162
// Optimized cleanup function for fast tests
6263
function forceCleanupSpinners() {
@@ -237,11 +238,34 @@ describe('CLIProgressManager', () => {
237238
});
238239

239240
// Note: Skipping actual withLoadingSpinner tests to avoid ora spinner issues in test environment
240-
fancy.it('should print global summary when exists', () => {
241+
fancy.it('should print global summary when exists and showConsoleLogs is false', () => {
241242
const summaryStub = sinon.stub(SummaryManager.prototype, 'printFinalSummary');
242-
CLIProgressManager.initializeGlobalSummary('TEST', '');
243-
CLIProgressManager.printGlobalSummary();
244-
expect(summaryStub.calledOnce).to.be.true;
243+
const configGetStub = sinon.stub(configHandler, 'get').callThrough();
244+
configGetStub.withArgs('log').returns({ showConsoleLogs: false });
245+
246+
try {
247+
CLIProgressManager.initializeGlobalSummary('TEST', '');
248+
CLIProgressManager.printGlobalSummary();
249+
expect(summaryStub.calledOnce).to.be.true;
250+
} finally {
251+
configGetStub.restore();
252+
summaryStub.restore();
253+
}
254+
});
255+
256+
fancy.it('should skip global summary when showConsoleLogs is true (pure console log mode)', () => {
257+
const summaryStub = sinon.stub(SummaryManager.prototype, 'printFinalSummary');
258+
const configGetStub = sinon.stub(configHandler, 'get').callThrough();
259+
configGetStub.withArgs('log').returns({ showConsoleLogs: true });
260+
261+
try {
262+
CLIProgressManager.initializeGlobalSummary('SKIP_SUMMARY_TEST', '');
263+
CLIProgressManager.printGlobalSummary();
264+
expect(summaryStub.called).to.be.false;
265+
} finally {
266+
configGetStub.restore();
267+
summaryStub.restore();
268+
}
245269
});
246270
});
247271

@@ -412,30 +436,28 @@ describe('CLIProgressManager', () => {
412436
expect(consoleLogStub.called).to.be.false;
413437
});
414438

415-
fancy.it('should print summary on stop when showConsoleLogs is true', () => {
439+
fancy.it('should not print Progress Manager summary when showConsoleLogs is true (pure console log mode)', () => {
416440
progressManager.tick(true, 'item1');
417441
progressManager.tick(false, 'item2', 'error');
418442
progressManager.stop();
419443

420-
expect(consoleLogStub.called).to.be.true;
421-
// Check if summary content was logged
444+
// When showConsoleLogs is enabled, per-module summary blocks are skipped for consistent log output
422445
const logCalls = consoleLogStub.getCalls();
423-
const summaryCall = logCalls.find(call =>
446+
const summaryCall = logCalls.find(call =>
424447
call.args[0] && call.args[0].includes('TEST Summary:')
425448
);
426-
expect(summaryCall).to.not.be.undefined;
427-
428-
// Ensure progress manager is stopped
449+
expect(summaryCall).to.be.undefined;
450+
429451
progressManager = null as any;
430452
});
431453

432-
fancy.it('should print detailed summary for nested progress', () => {
454+
fancy.it('should not print Detailed Summary blocks when showConsoleLogs is true (pure console log mode)', () => {
433455
const nestedManager = new CLIProgressManager({
434456
showConsoleLogs: true,
435457
enableNestedProgress: true,
436458
moduleName: 'NESTED_TEST',
437459
});
438-
460+
439461
try {
440462
nestedManager.addProcess('process1', 5);
441463
nestedManager.startProcess('process1');
@@ -444,14 +466,13 @@ describe('CLIProgressManager', () => {
444466
nestedManager.completeProcess('process1');
445467
nestedManager.stop();
446468

447-
expect(consoleLogStub.called).to.be.true;
469+
// When showConsoleLogs is enabled, Detailed Summary blocks are skipped
448470
const logCalls = consoleLogStub.getCalls();
449-
const detailedSummaryCall = logCalls.find(call =>
471+
const detailedSummaryCall = logCalls.find(call =>
450472
call.args[0] && call.args[0].includes('NESTED_TEST Detailed Summary:')
451473
);
452-
expect(detailedSummaryCall).to.not.be.undefined;
474+
expect(detailedSummaryCall).to.be.undefined;
453475
} finally {
454-
// Ensure cleanup
455476
try {
456477
nestedManager.stop();
457478
} catch (e) {

0 commit comments

Comments
 (0)