1
1
import { Command , Option } from '@commander-js/extra-typings' ;
2
2
import { input , select } from '@inquirer/prompts' ;
3
- import chalk from 'chalk' ;
4
3
import { execSync } from 'child_process' ;
4
+ import { colorize } from 'consola/utils' ;
5
5
import { pathExistsSync } from 'fs-extra/esm' ;
6
6
import kebabCase from 'lodash.kebabcase' ;
7
7
import { join } from 'path' ;
@@ -68,7 +68,7 @@ async function handleChannelCreation(bc: Https, cliApi: CliApi) {
68
68
availableLocales = await getAvailableLocales ( bc ) ;
69
69
} catch ( error ) {
70
70
if ( error instanceof Error ) {
71
- console . error ( chalk . red ( error . message ) ) ;
71
+ console . error ( colorize ( 'red' , error . message ) ) ;
72
72
}
73
73
74
74
process . exit ( 1 ) ;
@@ -80,7 +80,7 @@ async function handleChannelCreation(bc: Https, cliApi: CliApi) {
80
80
choices : availableLocales ,
81
81
theme : {
82
82
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)' ) ,
84
84
} ,
85
85
} ,
86
86
} ) ;
@@ -101,7 +101,7 @@ async function handleChannelCreation(bc: Https, cliApi: CliApi) {
101
101
message : 'Which additional languages would you like to add to your channel?' ,
102
102
theme : {
103
103
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)' ) ,
105
105
} ,
106
106
} ,
107
107
validate : ( selections ) => {
@@ -131,15 +131,18 @@ async function handleChannelCreation(bc: Https, cliApi: CliApi) {
131
131
132
132
if ( ! response . ok ) {
133
133
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
+ ) ,
135
138
) ;
136
139
process . exit ( 1 ) ;
137
140
}
138
141
139
142
const channelData : unknown = await response . json ( ) ;
140
143
141
144
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' ) ) ;
143
146
process . exit ( 1 ) ;
144
147
}
145
148
@@ -156,7 +159,8 @@ async function handleChannelSelection(bc: Https) {
156
159
157
160
if ( ! channelsResponse . ok ) {
158
161
console . error (
159
- chalk . red (
162
+ colorize (
163
+ 'red' ,
160
164
`\nGET /v3/channels failed: ${ channelsResponse . status } ${ channelsResponse . statusText } \n` ,
161
165
) ,
162
166
) ;
@@ -166,7 +170,7 @@ async function handleChannelSelection(bc: Https) {
166
170
const availableChannels : unknown = await channelsResponse . json ( ) ;
167
171
168
172
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' ) ) ;
170
174
process . exit ( 1 ) ;
171
175
}
172
176
@@ -208,7 +212,8 @@ async function getChannelInit(cliApi: CliApi, channelId: number) {
208
212
209
213
if ( ! initResponse . ok ) {
210
214
console . error (
211
- chalk . red (
215
+ colorize (
216
+ 'red' ,
212
217
`\nGET /channels/${ channelId } /init failed: ${ initResponse . status } ${ initResponse . statusText } \n` ,
213
218
) ,
214
219
) ;
@@ -218,7 +223,7 @@ async function getChannelInit(cliApi: CliApi, channelId: number) {
218
223
const initData : unknown = await initResponse . json ( ) ;
219
224
220
225
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' ) ) ;
222
227
process . exit ( 1 ) ;
223
228
}
224
229
@@ -235,7 +240,7 @@ async function setupProject(options: {
235
240
let { projectName, projectDir } = options ;
236
241
237
242
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` ) ) ;
239
244
process . exit ( 1 ) ;
240
245
}
241
246
@@ -244,7 +249,7 @@ async function setupProject(options: {
244
249
projectDir = join ( options . projectDir , projectName ) ;
245
250
246
251
if ( pathExistsSync ( projectDir ) ) {
247
- console . error ( chalk . red ( `Error: ${ projectDir } already exists\n` ) ) ;
252
+ console . error ( colorize ( 'red' , `Error: ${ projectDir } already exists\n` ) ) ;
248
253
process . exit ( 1 ) ;
249
254
}
250
255
}
@@ -282,15 +287,15 @@ function checkRequiredTools() {
282
287
try {
283
288
execSync ( getPlatformCheckCommand ( 'git' ) , { stdio : 'ignore' } ) ;
284
289
} 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' ) ) ;
286
291
process . exit ( 1 ) ;
287
292
}
288
293
289
294
try {
290
295
execSync ( getPlatformCheckCommand ( 'pnpm' ) , { stdio : 'ignore' } ) ;
291
296
} 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' ) ;
294
299
process . exit ( 1 ) ;
295
300
}
296
301
}
@@ -383,13 +388,16 @@ export const create = new Command('create')
383
388
384
389
console . log (
385
390
[
386
- `\n ${ chalk . green ( 'Success!' ) } Created '${ projectName } ' at '${ projectDir } '\n`,
391
+ colorize ( 'green' , `\nSuccess! Created '${ projectName } ' at '${ projectDir } '\n`) ,
387
392
`Next steps:` ,
388
393
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` )
390
395
: [
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
+ ) ,
393
401
] . join ( '' ) ,
394
402
] . join ( '\n' ) ,
395
403
) ;
@@ -423,7 +431,8 @@ export const create = new Command('create')
423
431
424
432
if ( ! eligibilityResponse . ok ) {
425
433
console . error (
426
- chalk . red (
434
+ colorize (
435
+ 'red' ,
427
436
`\nGET /channels/catalyst/eligibility failed: ${ eligibilityResponse . status } ${ eligibilityResponse . statusText } \n` ,
428
437
) ,
429
438
) ;
@@ -433,12 +442,14 @@ export const create = new Command('create')
433
442
const eligibilityData : unknown = await eligibilityResponse . json ( ) ;
434
443
435
444
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
+ ) ;
437
448
process . exit ( 1 ) ;
438
449
}
439
450
440
451
if ( ! eligibilityData . data . eligible ) {
441
- console . warn ( chalk . yellow ( eligibilityData . data . message ) ) ;
452
+ console . warn ( colorize ( 'yellow' , eligibilityData . data . message ) ) ;
442
453
}
443
454
444
455
let shouldCreateChannel ;
@@ -460,9 +471,10 @@ export const create = new Command('create')
460
471
storefrontToken = channelData . storefrontToken ;
461
472
envVars = { ...channelData . envVars } ;
462
473
463
- console . log ( chalk . green ( `Channel created successfully` ) ) ;
474
+ console . log ( colorize ( 'green' , `Channel created successfully` ) ) ;
464
475
console . warn (
465
- chalk . yellow (
476
+ colorize (
477
+ 'yellow' ,
466
478
'\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.' ,
467
479
) ,
468
480
) ;
@@ -525,9 +537,9 @@ export const create = new Command('create')
525
537
}
526
538
527
539
console . log (
528
- `\n ${ chalk . green ( 'Success!' ) } Created '${ projectName } ' at '${ projectDir } '\n`,
540
+ colorize ( 'green' , `\nSuccess! Created '${ projectName } ' at '${ projectDir } '\n`) ,
529
541
'\nNext steps:\n' ,
530
- chalk . yellow ( `\ncd ${ projectName } && pnpm run dev\n` ) ,
542
+ colorize ( 'yellow' , `\ncd ${ projectName } && pnpm run dev\n` ) ,
531
543
) ;
532
544
} ) ;
533
545
0 commit comments