Skip to content

Commit f791fef

Browse files
authored
deps(create-catalyst): replace chalk with consola colorize utility function (#2591)
* deps(create-catalyst): lock chalk to 5.4.1 * deps(create-catalyst): replace chalk with consola colorize utility function
1 parent 29f2030 commit f791fef

File tree

10 files changed

+72
-50
lines changed

10 files changed

+72
-50
lines changed

.changeset/mighty-pets-dream.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@bigcommerce/create-catalyst': patch
3+
---
4+
5+
Removes `chalk` dependency in favor of `consola` "colorize" utility function (which only depends on `node:tty`)

packages/create-catalyst/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
"@inquirer/type": "^3.0.7",
2727
"@segment/analytics-node": "^2.2.1",
2828
"ansi-escapes": "^7.0.0",
29-
"chalk": "^5.4.1",
3029
"commander": "^14.0.0",
3130
"conf": "^13.1.0",
31+
"consola": "^3.4.2",
3232
"cross-spawn": "^7.0.6",
3333
"dotenv": "^16.5.0",
3434
"fs-extra": "^11.3.0",

packages/create-catalyst/src/commands/create.ts

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Command, Option } from '@commander-js/extra-typings';
22
import { input, select } from '@inquirer/prompts';
3-
import chalk from 'chalk';
43
import { execSync } from 'child_process';
4+
import { colorize } from 'consola/utils';
55
import { pathExistsSync } from 'fs-extra/esm';
66
import kebabCase from 'lodash.kebabcase';
77
import { join } from 'path';
@@ -68,7 +68,7 @@ async function handleChannelCreation(bc: Https, cliApi: CliApi) {
6868
availableLocales = await getAvailableLocales(bc);
6969
} catch (error) {
7070
if (error instanceof Error) {
71-
console.error(chalk.red(error.message));
71+
console.error(colorize('red', error.message));
7272
}
7373

7474
process.exit(1);
@@ -80,7 +80,7 @@ async function handleChannelCreation(bc: Https, cliApi: CliApi) {
8080
choices: availableLocales,
8181
theme: {
8282
style: {
83-
help: () => chalk.dim('(Select locale from the list or start typing the name)'),
83+
help: () => colorize('dim', '(Select locale from the list or start typing the name)'),
8484
},
8585
},
8686
});
@@ -101,7 +101,7 @@ async function handleChannelCreation(bc: Https, cliApi: CliApi) {
101101
message: 'Which additional languages would you like to add to your channel?',
102102
theme: {
103103
style: {
104-
help: () => chalk.dim('(Select locale from the list or start typing the name)'),
104+
help: () => colorize('dim', '(Select locale from the list or start typing the name)'),
105105
},
106106
},
107107
validate: (selections) => {
@@ -131,15 +131,18 @@ async function handleChannelCreation(bc: Https, cliApi: CliApi) {
131131

132132
if (!response.ok) {
133133
console.error(
134-
chalk.red(`\nPOST /channels/catalyst failed: ${response.status} ${response.statusText}\n`),
134+
colorize(
135+
'red',
136+
`\nPOST /channels/catalyst failed: ${response.status} ${response.statusText}\n`,
137+
),
135138
);
136139
process.exit(1);
137140
}
138141

139142
const channelData: unknown = await response.json();
140143

141144
if (!isCreateChannelResponse(channelData)) {
142-
console.error(chalk.red('\nUnexpected response format from create channel endpoint\n'));
145+
console.error(colorize('red', '\nUnexpected response format from create channel endpoint\n'));
143146
process.exit(1);
144147
}
145148

@@ -156,7 +159,8 @@ async function handleChannelSelection(bc: Https) {
156159

157160
if (!channelsResponse.ok) {
158161
console.error(
159-
chalk.red(
162+
colorize(
163+
'red',
160164
`\nGET /v3/channels failed: ${channelsResponse.status} ${channelsResponse.statusText}\n`,
161165
),
162166
);
@@ -166,7 +170,7 @@ async function handleChannelSelection(bc: Https) {
166170
const availableChannels: unknown = await channelsResponse.json();
167171

168172
if (!isChannelsResponse(availableChannels)) {
169-
console.error(chalk.red('\nUnexpected response format from channels endpoint\n'));
173+
console.error(colorize('red', '\nUnexpected response format from channels endpoint\n'));
170174
process.exit(1);
171175
}
172176

@@ -208,7 +212,8 @@ async function getChannelInit(cliApi: CliApi, channelId: number) {
208212

209213
if (!initResponse.ok) {
210214
console.error(
211-
chalk.red(
215+
colorize(
216+
'red',
212217
`\nGET /channels/${channelId}/init failed: ${initResponse.status} ${initResponse.statusText}\n`,
213218
),
214219
);
@@ -218,7 +223,7 @@ async function getChannelInit(cliApi: CliApi, channelId: number) {
218223
const initData: unknown = await initResponse.json();
219224

220225
if (!isInitResponse(initData)) {
221-
console.error(chalk.red('\nUnexpected response format from init endpoint\n'));
226+
console.error(colorize('red', '\nUnexpected response format from init endpoint\n'));
222227
process.exit(1);
223228
}
224229

@@ -235,7 +240,7 @@ async function setupProject(options: {
235240
let { projectName, projectDir } = options;
236241

237242
if (!pathExistsSync(projectDir)) {
238-
console.error(chalk.red(`Error: --projectDir ${projectDir} is not a valid path\n`));
243+
console.error(colorize('red', `Error: --projectDir ${projectDir} is not a valid path\n`));
239244
process.exit(1);
240245
}
241246

@@ -244,7 +249,7 @@ async function setupProject(options: {
244249
projectDir = join(options.projectDir, projectName);
245250

246251
if (pathExistsSync(projectDir)) {
247-
console.error(chalk.red(`Error: ${projectDir} already exists\n`));
252+
console.error(colorize('red', `Error: ${projectDir} already exists\n`));
248253
process.exit(1);
249254
}
250255
}
@@ -282,15 +287,15 @@ function checkRequiredTools() {
282287
try {
283288
execSync(getPlatformCheckCommand('git'), { stdio: 'ignore' });
284289
} catch {
285-
console.error(chalk.red('Error: git is required to create a Catalyst project\n'));
290+
console.error(colorize('red', 'Error: git is required to create a Catalyst project\n'));
286291
process.exit(1);
287292
}
288293

289294
try {
290295
execSync(getPlatformCheckCommand('pnpm'), { stdio: 'ignore' });
291296
} catch {
292-
console.error(chalk.red('Error: pnpm is required to create a Catalyst project\n'));
293-
console.error(chalk.yellow('Tip: Enable it by running `corepack enable pnpm`\n'));
297+
console.error(colorize('red', 'Error: pnpm is required to create a Catalyst project\n'));
298+
console.error('Tip: Enable it by running `corepack enable pnpm`\n');
294299
process.exit(1);
295300
}
296301
}
@@ -383,13 +388,16 @@ export const create = new Command('create')
383388

384389
console.log(
385390
[
386-
`\n${chalk.green('Success!')} Created '${projectName}' at '${projectDir}'\n`,
391+
colorize('green', `\nSuccess! Created '${projectName}' at '${projectDir}'\n`),
387392
`Next steps:`,
388393
Object.keys(envVars).length > 0
389-
? chalk.yellow(`\n- cd ${projectName} && pnpm run dev\n`)
394+
? colorize('yellow', `\n- cd ${projectName} && pnpm run dev\n`)
390395
: [
391-
chalk.yellow(`\n- cd ${projectName} && cp .env.example .env.local`),
392-
chalk.yellow(`\n- Populate .env.local with your BigCommerce API credentials\n`),
396+
colorize('yellow', `\n- cd ${projectName} && cp .env.example .env.local`),
397+
colorize(
398+
'yellow',
399+
`\n- Populate .env.local with your BigCommerce API credentials\n`,
400+
),
393401
].join(''),
394402
].join('\n'),
395403
);
@@ -423,7 +431,8 @@ export const create = new Command('create')
423431

424432
if (!eligibilityResponse.ok) {
425433
console.error(
426-
chalk.red(
434+
colorize(
435+
'red',
427436
`\nGET /channels/catalyst/eligibility failed: ${eligibilityResponse.status} ${eligibilityResponse.statusText}\n`,
428437
),
429438
);
@@ -433,12 +442,14 @@ export const create = new Command('create')
433442
const eligibilityData: unknown = await eligibilityResponse.json();
434443

435444
if (!isEligibilityResponse(eligibilityData)) {
436-
console.error(chalk.red('\nUnexpected response format from eligibility endpoint\n'));
445+
console.error(
446+
colorize('red', '\nUnexpected response format from eligibility endpoint\n'),
447+
);
437448
process.exit(1);
438449
}
439450

440451
if (!eligibilityData.data.eligible) {
441-
console.warn(chalk.yellow(eligibilityData.data.message));
452+
console.warn(colorize('yellow', eligibilityData.data.message));
442453
}
443454

444455
let shouldCreateChannel;
@@ -460,9 +471,10 @@ export const create = new Command('create')
460471
storefrontToken = channelData.storefrontToken;
461472
envVars = { ...channelData.envVars };
462473

463-
console.log(chalk.green(`Channel created successfully`));
474+
console.log(colorize('green', `Channel created successfully`));
464475
console.warn(
465-
chalk.yellow(
476+
colorize(
477+
'yellow',
466478
'\nNote: A preview storefront has been deployed in your BigCommerce control panel. This preview may look different from your local environment as it may be running different code.',
467479
),
468480
);
@@ -525,9 +537,9 @@ export const create = new Command('create')
525537
}
526538

527539
console.log(
528-
`\n${chalk.green('Success!')} Created '${projectName}' at '${projectDir}'\n`,
540+
colorize('green', `\nSuccess! Created '${projectName}' at '${projectDir}'\n`),
529541
'\nNext steps:\n',
530-
chalk.yellow(`\ncd ${projectName} && pnpm run dev\n`),
542+
colorize('yellow', `\ncd ${projectName} && pnpm run dev\n`),
531543
);
532544
});
533545

packages/create-catalyst/src/commands/init.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Command, Option } from '@commander-js/extra-typings';
22
import { select } from '@inquirer/prompts';
3-
import chalk from 'chalk';
3+
import { colorize } from 'consola/utils';
44

55
import { CliApi } from '../utils/cli-api';
66
import { Config } from '../utils/config';
@@ -116,7 +116,8 @@ export const init = new Command('init')
116116

117117
if (!channelsResponse.ok) {
118118
console.error(
119-
chalk.red(
119+
colorize(
120+
'red',
120121
`\nGET /v3/channels failed: ${channelsResponse.status} ${channelsResponse.statusText}\n`,
121122
),
122123
);
@@ -126,7 +127,7 @@ export const init = new Command('init')
126127
const availableChannels: unknown = await channelsResponse.json();
127128

128129
if (!isChannelsResponse(availableChannels)) {
129-
console.error(chalk.red('\nUnexpected response format from channels endpoint\n'));
130+
console.error(colorize('red', '\nUnexpected response format from channels endpoint\n'));
130131
process.exit(1);
131132
}
132133

@@ -155,7 +156,8 @@ export const init = new Command('init')
155156

156157
if (!initResponse.ok) {
157158
console.error(
158-
chalk.red(
159+
colorize(
160+
'red',
159161
`\nGET /channels/${channelId}/init failed: ${initResponse.status} ${initResponse.statusText}\n`,
160162
),
161163
);
@@ -165,7 +167,7 @@ export const init = new Command('init')
165167
const initData: unknown = await initResponse.json();
166168

167169
if (!isInitResponse(initData)) {
168-
console.error(chalk.red('\nUnexpected response format from init endpoint\n'));
170+
console.error(colorize('red', '\nUnexpected response format from init endpoint\n'));
169171
process.exit(1);
170172
}
171173

@@ -188,7 +190,9 @@ export const init = new Command('init')
188190

189191
writeEnv(projectDir, envVars);
190192

191-
console.log(chalk.green(`\n.env.local file created for channel ${existingChannel.name}!\n`));
192-
console.log(chalk.green(`\nNext steps:\n`));
193-
console.log(chalk.yellow(`\npnpm run dev\n`));
193+
console.log(
194+
colorize('green', `\n.env.local file created for channel ${existingChannel.name}!\n`),
195+
);
196+
console.log(colorize('green', `\nNext steps:\n`));
197+
console.log(colorize('yellow', `\npnpm run dev\n`));
194198
});

packages/create-catalyst/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22

33
import { program } from '@commander-js/extra-typings';
4-
import chalk from 'chalk';
4+
import { colorize } from 'consola/utils';
55

66
import PACKAGE_INFO from '../package.json';
77

@@ -11,7 +11,7 @@ import { integration } from './commands/integration';
1111
import { telemetry } from './commands/telemetry';
1212
import { telemetryPostHook, telemetryPreHook } from './hooks/telemetry';
1313

14-
console.log(chalk.cyanBright(`\n◢ ${PACKAGE_INFO.name} v${PACKAGE_INFO.version}\n`));
14+
console.log(colorize('cyanBright', `\n◢ ${PACKAGE_INFO.name} v${PACKAGE_INFO.version}\n`));
1515

1616
program
1717
.name(PACKAGE_INFO.name)

packages/create-catalyst/src/prompts/multi-select/helpers.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import { Separator } from '@inquirer/core';
22
import figures from '@inquirer/figures';
3-
import chalk from 'chalk';
3+
import { colorize } from 'consola/utils';
44

55
import { Choice, Item, NormalizedChoice, SelectTheme } from './types';
66

77
export const selectTheme: SelectTheme = {
88
helpMode: 'auto',
99
icon: {
10-
checked: chalk.green(figures.circleFilled),
10+
checked: colorize('green', figures.circleFilled),
1111
unchecked: figures.circle,
1212
cursor: figures.pointer,
1313
},
1414
style: {
15-
description: (text: string) => chalk.cyan(text),
16-
disabledChoice: (text: string) => chalk.dim(`- ${text}`),
15+
description: (text: string) => colorize('cyan', text),
16+
disabledChoice: (text: string) => colorize('dim', `- ${text}`),
1717
renderSelectedChoices: (selectedChoices) =>
1818
selectedChoices.map((choice) => choice.short).join(', '),
1919
},

packages/create-catalyst/src/utils/install-dependencies.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import chalk from 'chalk';
1+
import { colorize } from 'consola/utils';
22
import { installDependencies as installDeps } from 'nypm';
33

44
import { spinner } from './spinner';
@@ -11,5 +11,5 @@ export const installDependencies = async (projectDir: string) =>
1111
spinner(installAllDeps(projectDir), {
1212
text: `Installing dependencies. This could take a minute...`,
1313
successText: `Dependencies installed successfully`,
14-
failText: (err) => chalk.red(`Failed to install dependencies: ${err.message}`),
14+
failText: (err) => colorize('red', `Failed to install dependencies: ${err.message}`),
1515
});

packages/create-catalyst/src/utils/login.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import chalk from 'chalk';
1+
import { colorize } from 'consola/utils';
22
import open from 'open';
33
import { createInterface } from 'readline';
44

@@ -83,7 +83,8 @@ export async function login(baseUrl: string): Promise<LoginResult> {
8383
const deviceCode = await auth.getDeviceCode();
8484

8585
console.log(
86-
chalk.yellow('\n! First copy your one-time code: ') + chalk.bold(deviceCode.user_code),
86+
colorize('yellow', '\n! First copy your one-time code: ') +
87+
colorize('bold', deviceCode.user_code),
8788
);
8889
console.log(`Press Enter to open ${deviceCode.verification_uri} in your browser...`);
8990

packages/create-catalyst/src/utils/telemetry/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import chalk from 'chalk';
1+
import { colorize } from 'consola/utils';
22

33
import { Telemetry } from './telemetry';
44

@@ -31,7 +31,7 @@ const catalystTelemetry = (options: CatalystTelemetryOptions, arg: string | unde
3131
}
3232

3333
console.log(
34-
`\nStatus: ${chalk.bold(isEnabled ? chalk.green('Enabled') : chalk.red('Disabled'))}`,
34+
`\nStatus: ${colorize('bold', isEnabled ? colorize('green', 'Enabled') : colorize('red', 'Disabled'))}`,
3535
);
3636

3737
if (!isEnabled) {

pnpm-lock.yaml

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)