Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@ fileignoreconfig:
checksum: a64a4d396eddd936a63b799eff58c5c6660b5dcaa3a310fd8b09a027932f1789
- filename: packages/contentstack-migration/README.md
checksum: e96006c1a948f766c88ae972b29582fa58eaf8184606bf011eebddc5a06cd7b6
- filename: packages/contentstack-asset-management/test/unit/import/base.test.ts
checksum: 5985575816f6e298c6c4e8169389d960b2a9ab3d43336e8c9e9b25302ba10353
- filename: packages/contentstack-asset-management/test/unit/export/base.test.ts
checksum: 68711c9a31e14982195efdb352903fe7782085a6a56a10b963cd0fd8db7ec668
version: ""
6 changes: 2 additions & 4 deletions packages/contentstack-asset-management/src/export/base.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { resolve as pResolve } from 'node:path';
import { writeFile } from 'node:fs/promises';
import { FsUtility, log, CLIProgressManager, configHandler } from '@contentstack/cli-utilities';
import { FsUtility, log, CLIProgressManager } from '@contentstack/cli-utilities';

import type { CSAssetsAPIConfig } from '../types/cs-assets-api';
import type { ExportContext } from '../types/export-types';
Expand Down Expand Up @@ -48,9 +48,7 @@ export class CSAssetsExportAdapter extends CSAssetsAdapter {
this.progressManager = this.parentProgressManager;
return this.parentProgressManager;
}
const logConfig = configHandler.get('log') || {};
const showConsoleLogs = logConfig.showConsoleLogs ?? false;
this.progressManager = CLIProgressManager.createNested(moduleName, showConsoleLogs);
this.progressManager = CLIProgressManager.createNested(moduleName);
return this.progressManager;
}

Expand Down
6 changes: 2 additions & 4 deletions packages/contentstack-asset-management/src/export/spaces.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { resolve as pResolve } from 'node:path';
import { mkdir } from 'node:fs/promises';
import { log, CLIProgressManager, configHandler, handleAndLogError } from '@contentstack/cli-utilities';
import { log, CLIProgressManager, handleAndLogError } from '@contentstack/cli-utilities';

import type { AssetManagementExportOptions, CSAssetsAPIConfig } from '../types/cs-assets-api';
import type { ExportContext } from '../types/export-types';
Expand Down Expand Up @@ -193,9 +193,7 @@ export class ExportSpaces {
this.progressManager = this.parentProgressManager;
return this.parentProgressManager;
}
const logConfig = configHandler.get('log') || {};
const showConsoleLogs = logConfig.showConsoleLogs ?? false;
this.progressManager = CLIProgressManager.createNested(CS_ASSETS_MAIN_PROCESS_NAME, showConsoleLogs);
this.progressManager = CLIProgressManager.createNested(CS_ASSETS_MAIN_PROCESS_NAME);
return this.progressManager;
}
}
Expand Down
6 changes: 2 additions & 4 deletions packages/contentstack-asset-management/src/import/base.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { resolve as pResolve } from 'node:path';
import { CLIProgressManager, configHandler } from '@contentstack/cli-utilities';
import { CLIProgressManager } from '@contentstack/cli-utilities';

import type { CSAssetsAPIConfig, ImportContext } from '../types/cs-assets-api';
import { CSAssetsAdapter } from '../utils/cs-assets-api-adapter';
Expand Down Expand Up @@ -46,9 +46,7 @@ export class CSAssetsImportAdapter extends CSAssetsAdapter {
this.progressManager = this.parentProgressManager;
return this.parentProgressManager;
}
const logConfig = configHandler.get('log') || {};
const showConsoleLogs = logConfig.showConsoleLogs ?? false;
this.progressManager = CLIProgressManager.createNested(moduleName, showConsoleLogs);
this.progressManager = CLIProgressManager.createNested(moduleName);
return this.progressManager;
}

Expand Down
6 changes: 2 additions & 4 deletions packages/contentstack-asset-management/src/import/spaces.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { join, resolve as pResolve } from 'node:path';
import { mkdirSync, readdirSync, statSync } from 'node:fs';
import { writeFile } from 'node:fs/promises';
import { log, CLIProgressManager, configHandler, handleAndLogError } from '@contentstack/cli-utilities';
import { log, CLIProgressManager, handleAndLogError } from '@contentstack/cli-utilities';

import type {
CSAssetsAPIConfig,
Expand Down Expand Up @@ -231,9 +231,7 @@ export class ImportSpaces {
this.progressManager = this.parentProgressManager;
return this.parentProgressManager;
}
const logConfig = configHandler.get('log') || {};
const showConsoleLogs = logConfig.showConsoleLogs ?? false;
this.progressManager = CLIProgressManager.createNested(CS_ASSETS_MAIN_PROCESS_NAME, showConsoleLogs);
this.progressManager = CLIProgressManager.createNested(CS_ASSETS_MAIN_PROCESS_NAME);
return this.progressManager;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ describe('CSAssetsExportAdapter (base)', () => {
});

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

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

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

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

expect(createNestedStub.firstCall.args[1]).to.be.false;
expect(createNestedStub.firstCall.args).to.deep.equal(['test']);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ describe('CSAssetsImportAdapter (base)', () => {

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

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

Expand Down
20 changes: 3 additions & 17 deletions packages/contentstack-audit/src/audit-base-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import {
TableFlags,
TableHeader,
log,
configHandler,
isConsoleLogEnabled,
CLIProgressManager,
clearProgressModuleSetting,
readContentTypeSchemas,
readGlobalFieldSchemas,
generateUid,
Expand Down Expand Up @@ -73,15 +72,6 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
async start(command: CommandNames): Promise<boolean> {
this.currentCommand = command;

// Set progress supported module and console logs setting BEFORE any log calls
// This ensures the logger respects the setting when it's initialized
const logConfig = configHandler.get('log') || {};
// Default to false so progress bars are shown instead of console logs
if (logConfig.showConsoleLogs === undefined) {
configHandler.set('log.showConsoleLogs', false);
}
configHandler.set('log.progressSupportedModule', 'audit');

// Initialize global summary for progress tracking
CLIProgressManager.initializeGlobalSummary('AUDIT', '', 'Auditing content...');

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

// Clear progress module setting now that audit is complete
clearProgressModuleSetting();

return (
!isEmpty(missingCtRefs) ||
!isEmpty(missingGfRefs) ||
Expand Down Expand Up @@ -263,9 +250,8 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
let dataModuleWise: Record<string, any> = await new ModuleDataReader(cloneDeep(constructorParam)).run();
log.debug(`Data module wise: ${JSON.stringify(dataModuleWise)}`, this.auditContext);

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

for (const module of this.sharedConfig.flags.modules || this.sharedConfig.modules) {
// Update audit context with current module
Expand Down
5 changes: 2 additions & 3 deletions packages/contentstack-audit/src/modules/assets.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { join, resolve } from 'path';
import { existsSync, readFileSync, readdirSync, writeFileSync } from 'fs';
import { FsUtility, sanitizePath, cliux, log, configHandler } from '@contentstack/cli-utilities';
import { FsUtility, sanitizePath, cliux, log, isConsoleLogEnabled } from '@contentstack/cli-utilities';
import { ContentTypeStruct, CtConstructorParam, ModuleConstructorParam, EntryStruct } from '../types';
import auditConfig from '../config';
import { $t, auditFixMsg, auditMsg, commonMsg } from '../messages';
Expand Down Expand Up @@ -298,8 +298,7 @@ export default class Assets extends BaseClass {
*/
async lookForReference(): Promise<void> {
log.debug('Starting asset reference validation', this.config.auditContext);
const logConfig = configHandler.get('log') || {};
const showConsoleLogs = logConfig.showConsoleLogs ?? false;
const showConsoleLogs = isConsoleLogEnabled();

if (!this.resolvedBasePaths.length) {
this.resolvedBasePaths = this.resolveAssetBasePaths();
Expand Down
17 changes: 3 additions & 14 deletions packages/contentstack-audit/src/modules/base-class.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CLIProgressManager, configHandler } from '@contentstack/cli-utilities';
import { CLIProgressManager } from '@contentstack/cli-utilities';
import { ConfigType, ModuleConstructorParam } from '../types';

export default abstract class BaseClass {
Expand All @@ -15,9 +15,7 @@ export default abstract class BaseClass {
*/
protected createSimpleProgress(moduleName: string, total?: number): CLIProgressManager {
this.currentModuleName = moduleName;
const logConfig = configHandler.get('log') || {};
const showConsoleLogs = logConfig.showConsoleLogs ?? false;
this.progressManager = CLIProgressManager.createSimple(moduleName, total, showConsoleLogs);
this.progressManager = CLIProgressManager.createSimple(moduleName, total);
return this.progressManager;
}

Expand All @@ -26,9 +24,7 @@ export default abstract class BaseClass {
*/
protected createNestedProgress(moduleName: string): CLIProgressManager {
this.currentModuleName = moduleName;
const logConfig = configHandler.get('log') || {};
const showConsoleLogs = logConfig.showConsoleLogs ?? false;
this.progressManager = CLIProgressManager.createNested(moduleName, showConsoleLogs);
this.progressManager = CLIProgressManager.createNested(moduleName);
return this.progressManager;
}

Expand All @@ -44,13 +40,6 @@ export default abstract class BaseClass {
* Execute action with loading spinner (if console logs are disabled)
*/
protected async withLoadingSpinner<T>(message: string, action: () => Promise<T>): Promise<T> {
const logConfig = configHandler.get('log') || {};
const showConsoleLogs = logConfig.showConsoleLogs ?? false;

if (showConsoleLogs) {
// If console logs are enabled, don't show spinner, just execute the action
return await action();
}
return await CLIProgressManager.withLoadingSpinner(message, action);
}
}
Expand Down
27 changes: 16 additions & 11 deletions packages/contentstack-audit/test/unit/audit-base-command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import { resolve } from 'path';
import { fancy } from 'fancy-test';
import { PassThrough } from 'stream';
import { expect } from 'chai';
import { ux, cliux, CLIProgressManager, configHandler, clearProgressModuleSetting } from '@contentstack/cli-utilities';
import { ux, cliux, CLIProgressManager, configHandler } from '@contentstack/cli-utilities';
import {
setConsoleLogPolicy,
resetConsoleLogPolicy,
} from '@contentstack/cli-utilities/lib/logger/console-policy';

import { AuditBaseCommand } from '../../src/audit-base-command';
import {
Expand Down Expand Up @@ -437,7 +441,6 @@ describe('AuditBaseCommand class', () => {

try {
CLIProgressManager.clearGlobalSummary();
clearProgressModuleSetting();
} catch (e) {
// Ignore
}
Expand Down Expand Up @@ -529,10 +532,12 @@ describe('AuditBaseCommand class', () => {
// Import print function from the correct path
const logModule = require('../../src/util/log');
printSpy = sinon.spy(logModule, 'print');
configHandlerGetStub = sinon.stub(configHandler, 'get');
configHandlerGetStub = sinon.stub(configHandler, 'get').returns({});
});

afterEach(() => {
resetConsoleLogPolicy();

try {
// Clear global summary first
CLIProgressManager.clearGlobalSummary();
Expand Down Expand Up @@ -584,15 +589,15 @@ describe('AuditBaseCommand class', () => {
.stub(FieldRule.prototype, 'run', () => ({ fr_1: {} }))
.stub(AuditBaseCommand.prototype, 'showOutputOnScreenWorkflowsAndExtension', () => {})
.stub(fs, 'createWriteStream', () => new PassThrough())
.it('should hide spinner messages when showConsoleLogs is false', async function() {
.it('should hide spinner messages when the console-log policy is off', async function() {
this.timeout(5000); // Set timeout to 5 seconds
if (!configHandlerGetStub || !printSpy) {
throw new Error('Spies not initialized');
}
configHandlerGetStub.returns({ showConsoleLogs: false });
setConsoleLogPolicy(false);
await AuditCMD.run(['--data-dir', resolve(__dirname, 'mock', 'contents')]);
// Print should not be called for spinner messages when showConsoleLogs is false

// Print should not be called for spinner messages when the console-log policy is off
const printCalls = printSpy.getCalls();
const spinnerCalls = printCalls.filter((call: any) =>
call.args[0]?.[0]?.message?.includes('scanning')
Expand Down Expand Up @@ -620,15 +625,15 @@ describe('AuditBaseCommand class', () => {
.stub(FieldRule.prototype, 'run', () => ({ fr_1: {} }))
.stub(AuditBaseCommand.prototype, 'showOutputOnScreenWorkflowsAndExtension', () => {})
.stub(fs, 'createWriteStream', () => new PassThrough())
.it('should show spinner messages when showConsoleLogs is true', async function() {
.it('should show spinner messages when the console-log policy is on', async function() {
this.timeout(5000); // Set timeout to 5 seconds
if (!configHandlerGetStub || !printSpy) {
throw new Error('Spies not initialized');
}
configHandlerGetStub.returns({ showConsoleLogs: true });
setConsoleLogPolicy(true);
await AuditCMD.run(['--data-dir', resolve(__dirname, 'mock', 'contents')]);
// Print should be called for spinner messages when showConsoleLogs is true

// Print should be called for spinner messages when the console-log policy is on
const printCalls = printSpy.getCalls();
const spinnerCalls = printCalls.filter((call: any) =>
call.args[0]?.[0]?.message?.includes('scanning')
Expand Down
Loading
Loading