Skip to content

Commit fdcca67

Browse files
author
naman-contentstack
committed
resolve comments
1 parent b74db1e commit fdcca67

File tree

2 files changed

+46
-10
lines changed

2 files changed

+46
-10
lines changed

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

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import { v4 as uuid } from 'uuid';
55
import isEmpty from 'lodash/isEmpty';
66
import { join, resolve } from 'path';
77
import cloneDeep from 'lodash/cloneDeep';
8-
import { cliux, sanitizePath, TableFlags, TableHeader, log } from '@contentstack/cli-utilities';
8+
import { cliux, sanitizePath, TableFlags, TableHeader } from '@contentstack/cli-utilities';
99
import { createWriteStream, existsSync, mkdirSync, readFileSync, writeFileSync, rmSync } from 'fs';
1010
import config from './config';
11+
import { print } from './util/log';
1112
import { auditMsg } from './messages';
1213
import { BaseCommand } from './base-command';
1314
import {
@@ -186,7 +187,13 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
186187

187188
let dataModuleWise: Record<string, any> = await new ModuleDataReader(cloneDeep(constructorParam)).run();
188189
for (const module of this.sharedConfig.flags.modules || this.sharedConfig.modules) {
189-
log.info(this.$t(this.messages.AUDIT_START_SPINNER, { module }));
190+
print([
191+
{
192+
bold: true,
193+
color: 'whiteBright',
194+
message: this.$t(this.messages.AUDIT_START_SPINNER, { module }),
195+
},
196+
]);
190197

191198
constructorParam['moduleName'] = module;
192199

@@ -262,7 +269,18 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
262269
break;
263270
}
264271

265-
log.info(`${this.$t(this.messages.AUDIT_START_SPINNER, { module })} done`);
272+
print([
273+
{
274+
bold: true,
275+
color: 'whiteBright',
276+
message: this.$t(this.messages.AUDIT_START_SPINNER, { module }),
277+
},
278+
{
279+
bold: true,
280+
message: ' done',
281+
color: 'whiteBright',
282+
},
283+
]);
266284
}
267285

268286
this.prepareReport('Summary', this.summaryDataToPrint);
@@ -361,7 +379,13 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
361379
this.log(''); // NOTE adding new line
362380
for (const { module, missingRefs } of allMissingRefs) {
363381
if (!isEmpty(missingRefs)) {
364-
log.info(` ${module}`);
382+
print([
383+
{
384+
bold: true,
385+
color: 'cyan',
386+
message: ` ${module}`,
387+
},
388+
]);
365389
const tableValues = Object.values(missingRefs).flat();
366390

367391
const tableHeaders: TableHeader[] = [
@@ -417,8 +441,8 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
417441
continue;
418442
}
419443

420-
log.info(` ${module}`);
421-
444+
print([{ bold: true, color: 'cyan', message: ` ${module}` }]);
445+
422446
const tableValues = Object.values(missingRefs).flat();
423447
missingRefs = Object.values(missingRefs).flat();
424448
const tableKeys = Object.keys(missingRefs[0]);

packages/contentstack-audit/test/unit/base-command.test.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,22 @@ describe('BaseCommand class', () => {
2020

2121
const createMockWinstonLogger = () => ({
2222
log: (message: any) => process.stdout.write(typeof message === 'string' ? message : JSON.stringify(message) + '\n'),
23-
error: (message: any) => process.stdout.write(`ERROR: ${typeof message === 'string' ? message : JSON.stringify(message)}\n`),
24-
info: (message: any) => process.stdout.write(`INFO: ${typeof message === 'string' ? message : JSON.stringify(message)}\n`),
25-
warn: (message: any) => process.stdout.write(`WARN: ${typeof message === 'string' ? message : JSON.stringify(message)}\n`),
26-
debug: (message: any) => process.stdout.write(`DEBUG: ${typeof message === 'string' ? message : JSON.stringify(message)}\n`),
23+
error: (message: any) => {
24+
const errorMsg = typeof message === 'string' ? message : (message?.message || JSON.stringify(message));
25+
process.stdout.write(`ERROR: ${errorMsg}\n`);
26+
},
27+
info: (message: any) => {
28+
const infoMsg = typeof message === 'string' ? message : (message?.message || JSON.stringify(message));
29+
process.stdout.write(`INFO: ${infoMsg}\n`);
30+
},
31+
warn: (message: any) => {
32+
const warnMsg = typeof message === 'string' ? message : (message?.message || JSON.stringify(message));
33+
process.stdout.write(`WARN: ${warnMsg}\n`);
34+
},
35+
debug: (message: any) => {
36+
const debugMsg = typeof message === 'string' ? message : (message?.message || JSON.stringify(message));
37+
process.stdout.write(`DEBUG: ${debugMsg}\n`);
38+
},
2739
level: 'info'
2840
});
2941

0 commit comments

Comments
 (0)