Skip to content

Commit fb502ce

Browse files
Merge remote-tracking branch 'origin/fix/console-log-policy-plugins' into fix/DX-10224-bulk-error-visibility
2 parents e93b7bd + 7fcf49c commit fb502ce

33 files changed

Lines changed: 128 additions & 276 deletions

File tree

.talismanrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,8 @@ fileignoreconfig:
3939
checksum: a64a4d396eddd936a63b799eff58c5c6660b5dcaa3a310fd8b09a027932f1789
4040
- filename: packages/contentstack-migration/README.md
4141
checksum: e96006c1a948f766c88ae972b29582fa58eaf8184606bf011eebddc5a06cd7b6
42+
- filename: packages/contentstack-asset-management/test/unit/import/base.test.ts
43+
checksum: 5985575816f6e298c6c4e8169389d960b2a9ab3d43336e8c9e9b25302ba10353
44+
- filename: packages/contentstack-asset-management/test/unit/export/base.test.ts
45+
checksum: 68711c9a31e14982195efdb352903fe7782085a6a56a10b963cd0fd8db7ec668
4246
version: ""

packages/contentstack-asset-management/src/export/base.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { resolve as pResolve } from 'node:path';
22
import { writeFile } from 'node:fs/promises';
3-
import { FsUtility, log, CLIProgressManager, configHandler } from '@contentstack/cli-utilities';
3+
import { FsUtility, log, CLIProgressManager } from '@contentstack/cli-utilities';
44

55
import type { CSAssetsAPIConfig } from '../types/cs-assets-api';
66
import type { ExportContext } from '../types/export-types';
@@ -48,9 +48,7 @@ export class CSAssetsExportAdapter extends CSAssetsAdapter {
4848
this.progressManager = this.parentProgressManager;
4949
return this.parentProgressManager;
5050
}
51-
const logConfig = configHandler.get('log') || {};
52-
const showConsoleLogs = logConfig.showConsoleLogs ?? false;
53-
this.progressManager = CLIProgressManager.createNested(moduleName, showConsoleLogs);
51+
this.progressManager = CLIProgressManager.createNested(moduleName);
5452
return this.progressManager;
5553
}
5654

packages/contentstack-asset-management/src/export/spaces.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { resolve as pResolve } from 'node:path';
22
import { mkdir } from 'node:fs/promises';
3-
import { log, CLIProgressManager, configHandler, handleAndLogError } from '@contentstack/cli-utilities';
3+
import { log, CLIProgressManager, handleAndLogError } from '@contentstack/cli-utilities';
44

55
import type { AssetManagementExportOptions, CSAssetsAPIConfig } from '../types/cs-assets-api';
66
import type { ExportContext } from '../types/export-types';
@@ -193,9 +193,7 @@ export class ExportSpaces {
193193
this.progressManager = this.parentProgressManager;
194194
return this.parentProgressManager;
195195
}
196-
const logConfig = configHandler.get('log') || {};
197-
const showConsoleLogs = logConfig.showConsoleLogs ?? false;
198-
this.progressManager = CLIProgressManager.createNested(CS_ASSETS_MAIN_PROCESS_NAME, showConsoleLogs);
196+
this.progressManager = CLIProgressManager.createNested(CS_ASSETS_MAIN_PROCESS_NAME);
199197
return this.progressManager;
200198
}
201199
}

packages/contentstack-asset-management/src/import/base.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { resolve as pResolve } from 'node:path';
2-
import { CLIProgressManager, configHandler } from '@contentstack/cli-utilities';
2+
import { CLIProgressManager } from '@contentstack/cli-utilities';
33

44
import type { CSAssetsAPIConfig, ImportContext } from '../types/cs-assets-api';
55
import { CSAssetsAdapter } from '../utils/cs-assets-api-adapter';
@@ -46,9 +46,7 @@ export class CSAssetsImportAdapter extends CSAssetsAdapter {
4646
this.progressManager = this.parentProgressManager;
4747
return this.parentProgressManager;
4848
}
49-
const logConfig = configHandler.get('log') || {};
50-
const showConsoleLogs = logConfig.showConsoleLogs ?? false;
51-
this.progressManager = CLIProgressManager.createNested(moduleName, showConsoleLogs);
49+
this.progressManager = CLIProgressManager.createNested(moduleName);
5250
return this.progressManager;
5351
}
5452

packages/contentstack-asset-management/src/import/spaces.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { join, resolve as pResolve } from 'node:path';
22
import { mkdirSync, readdirSync, statSync } from 'node:fs';
33
import { writeFile } from 'node:fs/promises';
4-
import { log, CLIProgressManager, configHandler, handleAndLogError } from '@contentstack/cli-utilities';
4+
import { log, CLIProgressManager, handleAndLogError } from '@contentstack/cli-utilities';
55

66
import type {
77
CSAssetsAPIConfig,
@@ -231,9 +231,7 @@ export class ImportSpaces {
231231
this.progressManager = this.parentProgressManager;
232232
return this.parentProgressManager;
233233
}
234-
const logConfig = configHandler.get('log') || {};
235-
const showConsoleLogs = logConfig.showConsoleLogs ?? false;
236-
this.progressManager = CLIProgressManager.createNested(CS_ASSETS_MAIN_PROCESS_NAME, showConsoleLogs);
234+
this.progressManager = CLIProgressManager.createNested(CS_ASSETS_MAIN_PROCESS_NAME);
237235
return this.progressManager;
238236
}
239237
}

packages/contentstack-asset-management/test/unit/export/base.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ describe('CSAssetsExportAdapter (base)', () => {
105105
});
106106

107107
describe('createNestedProgress', () => {
108-
it('should create a new CLIProgressManager with the given name and showConsoleLogs flag', () => {
109-
sinon.stub(configHandler, 'get').returns({ showConsoleLogs: true });
108+
it('should create a new CLIProgressManager with the given name', () => {
110109
const fakeProgress = { tick: sinon.stub() } as any;
111110
const createNestedStub = sinon.stub(CLIProgressManager, 'createNested').returns(fakeProgress);
112111

@@ -126,15 +125,14 @@ describe('CSAssetsExportAdapter (base)', () => {
126125
expect(result).to.equal(fakeParent);
127126
});
128127

129-
it('should default showConsoleLogs to false when log config is missing', () => {
130-
sinon.stub(configHandler, 'get').returns(null);
128+
it('should not pass a showConsoleLogs argument — the manager resolves the policy itself', () => {
131129
const fakeProgress = { tick: sinon.stub() } as any;
132130
const createNestedStub = sinon.stub(CLIProgressManager, 'createNested').returns(fakeProgress);
133131

134132
const adapter = new TestAdapter(apiConfig, exportContext);
135133
adapter.callCreateNestedProgress('test');
136134

137-
expect(createNestedStub.firstCall.args[1]).to.be.false;
135+
expect(createNestedStub.firstCall.args).to.deep.equal(['test']);
138136
});
139137
});
140138

packages/contentstack-asset-management/test/unit/import/base.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ describe('CSAssetsImportAdapter (base)', () => {
7575

7676
describe('createNestedProgress', () => {
7777
it('creates a CLIProgressManager when no parent is set', () => {
78-
sinon.stub(configHandler, 'get').returns({ showConsoleLogs: true });
7978
const fakeProgress = { tick: sinon.stub() } as any;
8079
const createNestedStub = sinon.stub(CLIProgressManager, 'createNested').returns(fakeProgress);
8180
const adapter = new TestImportAdapter(apiConfig, importContext);
@@ -92,13 +91,12 @@ describe('CSAssetsImportAdapter (base)', () => {
9291
expect(result).to.equal(fakeParent);
9392
});
9493

95-
it('defaults showConsoleLogs to false when log config is missing', () => {
96-
sinon.stub(configHandler, 'get').returns(null);
94+
it('passes no showConsoleLogs argument — the manager resolves the policy itself', () => {
9795
const fakeProgress = { tick: sinon.stub() } as any;
9896
const createNestedStub = sinon.stub(CLIProgressManager, 'createNested').returns(fakeProgress);
9997
const adapter = new TestImportAdapter(apiConfig, importContext);
10098
adapter.callCreateNestedProgress('test');
101-
expect(createNestedStub.firstCall.args[1]).to.be.false;
99+
expect(createNestedStub.firstCall.args).to.deep.equal(['test']);
102100
});
103101
});
104102

packages/contentstack-audit/src/audit-base-command.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ import {
1010
TableFlags,
1111
TableHeader,
1212
log,
13-
configHandler,
13+
isConsoleLogEnabled,
1414
CLIProgressManager,
15-
clearProgressModuleSetting,
1615
readContentTypeSchemas,
1716
readGlobalFieldSchemas,
1817
generateUid,
@@ -73,15 +72,6 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
7372
async start(command: CommandNames): Promise<boolean> {
7473
this.currentCommand = command;
7574

76-
// Set progress supported module and console logs setting BEFORE any log calls
77-
// This ensures the logger respects the setting when it's initialized
78-
const logConfig = configHandler.get('log') || {};
79-
// Default to false so progress bars are shown instead of console logs
80-
if (logConfig.showConsoleLogs === undefined) {
81-
configHandler.set('log.showConsoleLogs', false);
82-
}
83-
configHandler.set('log.progressSupportedModule', 'audit');
84-
8575
// Initialize global summary for progress tracking
8676
CLIProgressManager.initializeGlobalSummary('AUDIT', '', 'Auditing content...');
8777

@@ -190,9 +180,6 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
190180
// Print comprehensive summary at the end (commented out - Summary table above has the counts; progress bars show completion)
191181
// CLIProgressManager.printGlobalSummary();
192182

193-
// Clear progress module setting now that audit is complete
194-
clearProgressModuleSetting();
195-
196183
return (
197184
!isEmpty(missingCtRefs) ||
198185
!isEmpty(missingGfRefs) ||
@@ -263,9 +250,8 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
263250
let dataModuleWise: Record<string, any> = await new ModuleDataReader(cloneDeep(constructorParam)).run();
264251
log.debug(`Data module wise: ${JSON.stringify(dataModuleWise)}`, this.auditContext);
265252

266-
// Extract logConfig and showConsoleLogs once before the loop to reuse throughout
267-
const logConfig = configHandler.get('log') || {};
268-
const showConsoleLogs = logConfig.showConsoleLogs ?? false;
253+
// Resolve the console-log policy once before the loop to reuse throughout
254+
const showConsoleLogs = isConsoleLogEnabled();
269255

270256
for (const module of this.sharedConfig.flags.modules || this.sharedConfig.modules) {
271257
// Update audit context with current module

packages/contentstack-audit/src/modules/assets.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { join, resolve } from 'path';
22
import { existsSync, readFileSync, readdirSync, writeFileSync } from 'fs';
3-
import { FsUtility, sanitizePath, cliux, log, configHandler } from '@contentstack/cli-utilities';
3+
import { FsUtility, sanitizePath, cliux, log, isConsoleLogEnabled } from '@contentstack/cli-utilities';
44
import { ContentTypeStruct, CtConstructorParam, ModuleConstructorParam, EntryStruct } from '../types';
55
import auditConfig from '../config';
66
import { $t, auditFixMsg, auditMsg, commonMsg } from '../messages';
@@ -298,8 +298,7 @@ export default class Assets extends BaseClass {
298298
*/
299299
async lookForReference(): Promise<void> {
300300
log.debug('Starting asset reference validation', this.config.auditContext);
301-
const logConfig = configHandler.get('log') || {};
302-
const showConsoleLogs = logConfig.showConsoleLogs ?? false;
301+
const showConsoleLogs = isConsoleLogEnabled();
303302

304303
if (!this.resolvedBasePaths.length) {
305304
this.resolvedBasePaths = this.resolveAssetBasePaths();

packages/contentstack-audit/src/modules/base-class.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CLIProgressManager, configHandler } from '@contentstack/cli-utilities';
1+
import { CLIProgressManager } from '@contentstack/cli-utilities';
22
import { ConfigType, ModuleConstructorParam } from '../types';
33

44
export default abstract class BaseClass {
@@ -15,9 +15,7 @@ export default abstract class BaseClass {
1515
*/
1616
protected createSimpleProgress(moduleName: string, total?: number): CLIProgressManager {
1717
this.currentModuleName = moduleName;
18-
const logConfig = configHandler.get('log') || {};
19-
const showConsoleLogs = logConfig.showConsoleLogs ?? false;
20-
this.progressManager = CLIProgressManager.createSimple(moduleName, total, showConsoleLogs);
18+
this.progressManager = CLIProgressManager.createSimple(moduleName, total);
2119
return this.progressManager;
2220
}
2321

@@ -26,9 +24,7 @@ export default abstract class BaseClass {
2624
*/
2725
protected createNestedProgress(moduleName: string): CLIProgressManager {
2826
this.currentModuleName = moduleName;
29-
const logConfig = configHandler.get('log') || {};
30-
const showConsoleLogs = logConfig.showConsoleLogs ?? false;
31-
this.progressManager = CLIProgressManager.createNested(moduleName, showConsoleLogs);
27+
this.progressManager = CLIProgressManager.createNested(moduleName);
3228
return this.progressManager;
3329
}
3430

@@ -44,13 +40,6 @@ export default abstract class BaseClass {
4440
* Execute action with loading spinner (if console logs are disabled)
4541
*/
4642
protected async withLoadingSpinner<T>(message: string, action: () => Promise<T>): Promise<T> {
47-
const logConfig = configHandler.get('log') || {};
48-
const showConsoleLogs = logConfig.showConsoleLogs ?? false;
49-
50-
if (showConsoleLogs) {
51-
// If console logs are enabled, don't show spinner, just execute the action
52-
return await action();
53-
}
5443
return await CLIProgressManager.withLoadingSpinner(message, action);
5544
}
5645
}

0 commit comments

Comments
 (0)