Skip to content

Commit 7e3b82f

Browse files
Upgrade chalk dependency to version 5.6.2 and refactor code to use getChalk() from @contentstack/cli-utilities for consistent color handling across multiple packages.
1 parent 61c0c0b commit 7e3b82f

25 files changed

Lines changed: 59 additions & 63 deletions

File tree

packages/contentstack-audit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"@contentstack/cli-utilities": "~2.0.0-beta.2",
2323
"@oclif/core": "^4.3.0",
2424
"@oclif/plugin-help": "^6.2.28",
25-
"chalk": "^4.1.2",
25+
"chalk": "^5.6.2",
2626
"fast-csv": "^4.3.6",
2727
"fs-extra": "^11.3.0",
2828
"lodash": "^4.17.23",

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import chalk from 'chalk';
1+
import { getChalk } from '@contentstack/cli-utilities';
22
import * as csv from 'fast-csv';
33
import { copy } from 'fs-extra';
44
import { v4 as uuid } from 'uuid';
@@ -55,7 +55,7 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
5555
minWidth: 7,
5656
header: 'Fix Status',
5757
get: (row: any) => {
58-
return row.fixStatus === 'Fixed' ? chalk.greenBright(row.fixStatus) : chalk.redBright(row.fixStatus);
58+
return row.fixStatus === 'Fixed' ? getChalk().greenBright(row.fixStatus) : getChalk().redBright(row.fixStatus);
5959
},
6060
},
6161
};
@@ -548,7 +548,7 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
548548
value: 'missingRefs',
549549
alias: 'Missing references',
550550
formatter: (cellValue: any) => {
551-
return chalk.red(typeof cellValue === 'object' ? JSON.stringify(cellValue) : cellValue);
551+
return getChalk().red(typeof cellValue === 'object' ? JSON.stringify(cellValue) : cellValue);
552552
},
553553
},
554554
{
@@ -588,7 +588,7 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
588588
value: key,
589589
formatter: (cellValue: any) => {
590590
if (key === 'fixStatus' || key === 'Fixable' || key === 'Fixed') {
591-
return chalk.green(typeof cellValue === 'object' ? JSON.stringify(cellValue) : cellValue);
591+
return getChalk().green(typeof cellValue === 'object' ? JSON.stringify(cellValue) : cellValue);
592592
} else if (
593593
key === 'content_types' ||
594594
key === 'branches' ||
@@ -598,9 +598,9 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
598598
key === 'Non-Fixable' ||
599599
key === 'Not-Fixed'
600600
) {
601-
return chalk.red(typeof cellValue === 'object' ? JSON.stringify(cellValue) : cellValue);
601+
return getChalk().red(typeof cellValue === 'object' ? JSON.stringify(cellValue) : cellValue);
602602
} else {
603-
return chalk.white(typeof cellValue === 'object' ? JSON.stringify(cellValue) : cellValue);
603+
return getChalk().white(typeof cellValue === 'object' ? JSON.stringify(cellValue) : cellValue);
604604
}
605605
},
606606
}));

packages/contentstack-audit/src/types/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Color } from "chalk";
1+
import type { ForegroundColorName } from 'chalk';
22
import { PrintOptions } from "@contentstack/cli-utilities";
33

44
import config from "../config";
@@ -26,7 +26,7 @@ export type LoggerType = "info" | "warn" | "error" | "debug" | 'hidden';
2626
export type PrintType = {
2727
message: string;
2828
bold?: boolean;
29-
color?: typeof Color;
29+
color?: ForegroundColorName;
3030
};
3131

3232
export type JSONFlagOptions = {

packages/contentstack-audit/src/util/log.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import map from 'lodash/map';
22
import winston from 'winston';
3-
import chalk, { Chalk } from 'chalk';
3+
import { getChalk, ChalkInstance } from '@contentstack/cli-utilities';
44
import replace from 'lodash/replace';
55
import isObject from 'lodash/isObject';
66
import { normalize, resolve } from 'path';
@@ -170,10 +170,11 @@ export default class Logger {
170170
* @param printInput - An array of objects with the following properties:
171171
*/
172172
export function print(printInput: Array<PrintType>): void {
173+
const chalk = getChalk();
173174
const str = map(printInput, ({ message, bold, color }: PrintType) => {
174-
let chalkFn: Chalk = chalk;
175-
if (color) chalkFn = chalkFn[color];
176-
if (bold) chalkFn = chalkFn.bold;
175+
let chalkFn: ChalkInstance = chalk;
176+
if (color) chalkFn = chalkFn[color] as ChalkInstance;
177+
if (bold) chalkFn = chalkFn.bold as ChalkInstance;
177178

178179
return chalkFn(message);
179180
}).join(' ');

packages/contentstack-branches/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"@oclif/core": "^4.3.0",
1010
"@oclif/plugin-help": "^6.2.28",
1111
"@contentstack/cli-utilities": "~2.0.0-beta.2",
12-
"chalk": "^4.1.2",
12+
"chalk": "^5.6.2",
1313
"just-diff": "^6.0.2",
1414
"lodash": "^4.17.23"
1515
},

packages/contentstack-branches/src/branch/merge-handler.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import os from 'os';
22
import path from 'path';
33
import forEach from 'lodash/forEach';
44
import { cliux } from '@contentstack/cli-utilities';
5-
import chalk from 'chalk';
5+
import { getChalk } from '@contentstack/cli-utilities';
66
import { MergeInputOptions, MergeSummary } from '../interfaces';
77
import {
88
selectMergeStrategy,
@@ -140,15 +140,15 @@ export default class MergeHandler {
140140
const strategyName = this.mergeSettings.strategy;
141141

142142
if (allEmpty) {
143-
cliux.print(chalk.red(`No items selected according to the '${strategyName}' strategy.`));
143+
cliux.print(getChalk().red(`No items selected according to the '${strategyName}' strategy.`));
144144
process.exit(1);
145145
}
146146

147147
for (const [type, { exists, empty }] of Object.entries(moduleStatus)) {
148148
if (exists && empty) {
149149
const readable = type === 'contentType' ? 'Content Types' : 'Global fields';
150150
cliux.print('\n')
151-
cliux.print(chalk.yellow(`Note: No ${readable} selected according to the '${strategyName}' strategy.`));
151+
cliux.print(getChalk().yellow(`Note: No ${readable} selected according to the '${strategyName}' strategy.`));
152152
}
153153
}
154154

packages/contentstack-branches/src/commands/cm/branches/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
TableHeader,
99
} from '@contentstack/cli-utilities';
1010
import { getbranchesList, getbranchConfig, interactive, handleErrorMsg } from '../../../utils/index';
11-
import chalk from 'chalk';
11+
import { getChalk } from '@contentstack/cli-utilities';
1212
export default class BranchListCommand extends Command {
1313
static description: string = messageHandler.parse('List the branches'); // Note: Update the description
1414

@@ -54,10 +54,10 @@ export default class BranchListCommand extends Command {
5454

5555
if (!verbose) {
5656
currentBranch[0]?.Source
57-
? cliux.print(`* ${chalk.bold(currentBranch[0].Branch)} (source: ${currentBranch[0].Source})`, {
57+
? cliux.print(`* ${getChalk().bold(currentBranch[0].Branch)} (source: ${currentBranch[0].Source})`, {
5858
color: 'blue',
5959
})
60-
: cliux.print(`* ${chalk.bold(currentBranch[0].Branch)}`, {
60+
: cliux.print(`* ${getChalk().bold(currentBranch[0].Branch)}`, {
6161
color: 'blue',
6262
});
6363

packages/contentstack-branches/src/utils/branch-diff-utility.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import chalk from 'chalk';
1+
import { getChalk } from '@contentstack/cli-utilities';
22
import forEach from 'lodash/forEach';
33
import padStart from 'lodash/padStart';
44
import startCase from 'lodash/startCase';
@@ -196,19 +196,19 @@ function printCompactTextView(branchTextRes: BranchCompactTextRes): void {
196196
cliux.print(' ');
197197
forEach(branchTextRes.added, (diff: BranchDiffRes) => {
198198
if (diff.merge_strategy !== 'ignore') {
199-
cliux.print(chalk.green(`+ '${diff.title}' ${startCase(camelCase(diff.type))}`));
199+
cliux.print(getChalk().green(`+ '${diff.title}' ${startCase(camelCase(diff.type))}`));
200200
}
201201
});
202202

203203
forEach(branchTextRes.modified, (diff: BranchDiffRes) => {
204204
if (diff.merge_strategy !== 'ignore') {
205-
cliux.print(chalk.blue(`± '${diff.title}' ${startCase(camelCase(diff.type))}`));
205+
cliux.print(getChalk().blue(`± '${diff.title}' ${startCase(camelCase(diff.type))}`));
206206
}
207207
});
208208

209209
forEach(branchTextRes.deleted, (diff: BranchDiffRes) => {
210210
if (diff.merge_strategy !== 'ignore') {
211-
cliux.print(chalk.red(`- '${diff.title}' ${startCase(camelCase(diff.type))}`));
211+
cliux.print(getChalk().red(`- '${diff.title}' ${startCase(camelCase(diff.type))}`));
212212
}
213213
});
214214
}
@@ -442,16 +442,16 @@ function printVerboseTextView(branchTextRes: BranchDiffVerboseRes): void {
442442
if (branchTextRes.modified?.length || branchTextRes.added?.length || branchTextRes.deleted?.length) {
443443
cliux.print(' ');
444444
forEach(branchTextRes.added, (diff: BranchDiffRes) => {
445-
cliux.print(chalk.green(`+ '${diff.title}' ${startCase(camelCase(diff.type))}`));
445+
cliux.print(getChalk().green(`+ '${diff.title}' ${startCase(camelCase(diff.type))}`));
446446
});
447447

448448
forEach(branchTextRes.modified, (diff: BranchModifiedDetails) => {
449-
cliux.print(chalk.blue(`± '${diff.moduleDetails.title}' ${startCase(camelCase(diff.moduleDetails.type))}`));
449+
cliux.print(getChalk().blue(`± '${diff.moduleDetails.title}' ${startCase(camelCase(diff.moduleDetails.type))}`));
450450
printModifiedFields(diff.modifiedFields);
451451
});
452452

453453
forEach(branchTextRes.deleted, (diff: BranchDiffRes) => {
454-
cliux.print(chalk.red(`- '${diff.title}' ${startCase(camelCase(diff.type))}`));
454+
cliux.print(getChalk().red(`- '${diff.title}' ${startCase(camelCase(diff.type))}`));
455455
});
456456
}
457457
}
@@ -466,17 +466,17 @@ function printModifiedFields(modfiedFields: ModifiedFieldsInput): void {
466466
forEach(modfiedFields.modified, (diff: ModifiedFieldsType) => {
467467
const field: string = diff.field ? `${diff.field}` : 'field';
468468
const fieldDetail = diff.path ? `(${diff.path}) ${field}`: `${field}`;
469-
cliux.print(` ${chalk.blue(`± "${diff.displayName}" ${fieldDetail}`)}`);
469+
cliux.print(` ${getChalk().blue(`± "${diff.displayName}" ${fieldDetail}`)}`);
470470
});
471471

472472
forEach(modfiedFields.added, (diff: ModifiedFieldsType) => {
473473
const field: string = diff.field ? `${diff.field} field` : 'field';
474-
cliux.print(` ${chalk.green(`+ "${diff.displayName}" (${diff.path}) ${field}`)}`);
474+
cliux.print(` ${getChalk().green(`+ "${diff.displayName}" (${diff.path}) ${field}`)}`);
475475
});
476476

477477
forEach(modfiedFields.deleted, (diff: ModifiedFieldsType) => {
478478
const field: string = diff.field ? `${diff.field} field` : 'field';
479-
cliux.print(` ${chalk.red(`- "${diff.displayName}" (${diff.path}) ${field}`)}`);
479+
cliux.print(` ${getChalk().red(`- "${diff.displayName}" (${diff.path}) ${field}`)}`);
480480
});
481481
}
482482
}

packages/contentstack-clone/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"@contentstack/cli-utilities": "~2.0.0-beta.2",
1313
"@oclif/core": "^4.3.0",
1414
"@oclif/plugin-help": "^6.2.28",
15-
"chalk": "^4.1.2",
15+
"chalk": "^5.6.2",
1616
"inquirer": "12.11.1",
1717
"lodash": "^4.17.23",
1818
"merge": "^2.1.1",

packages/contentstack-clone/src/core/util/clone-handler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Ora, default as ora } from 'ora';
22
import * as path from 'path';
33
import inquirer from 'inquirer';
4-
import chalk from 'chalk';
4+
import { getChalk } from '@contentstack/cli-utilities';
55
import * as fs from 'fs';
66
import { rimraf } from 'rimraf';
77
import { CustomAbortController } from './abort-controller';
@@ -170,7 +170,7 @@ export class CloneHandler {
170170
}
171171

172172
displayBackOptionMessage(): void {
173-
process.stdout.write(chalk.cyan('\nPress shift & left arrow together to undo the operation\n'));
173+
process.stdout.write(getChalk().cyan('\nPress shift & left arrow together to undo the operation\n'));
174174
}
175175

176176
setBackKeyPressHandler(backKeyPressHandler: (...args: any[]) => void): void {

0 commit comments

Comments
 (0)