Skip to content

Commit 6a58601

Browse files
committed
swap out chalk — bye bye ESM only!
1 parent d48c46f commit 6a58601

File tree

3 files changed

+42
-42
lines changed

3 files changed

+42
-42
lines changed

packages/inquirerer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"test:watch": "jest --watch"
3030
},
3131
"dependencies": {
32-
"chalk": "^4.1.0",
32+
"yanse": "workspace:*",
3333
"deepmerge": "^4.3.1",
3434
"js-yaml": "^4.1.0",
3535
"minimist": "^1.2.8"

packages/inquirerer/src/prompt.ts

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import chalk from 'chalk';
1+
import yanse, { red, whiteBright, yellow, gray, dim, green, cyan, white, blue } from 'yanse';
22
import readline from 'readline';
33
import { Readable, Writable } from 'stream';
44

@@ -62,16 +62,16 @@ const validationMessage = (question: Question, ctx: PromptContext): string => {
6262
}
6363

6464
if (ctx.validation.reason) {
65-
return chalk.red(`The field "${question.name}" is invalid: ${ctx.validation.reason}\n`);
65+
return red(`The field "${question.name}" is invalid: ${ctx.validation.reason}\n`);
6666
}
6767

6868
switch (ctx.validation.type) {
6969
case 'required':
70-
return chalk.red(`The field "${question.name}" is required. Please provide a value.\n`);
70+
return red(`The field "${question.name}" is required. Please provide a value.\n`);
7171
case 'pattern':
72-
return chalk.red(`The field "${question.name}" does not match the pattern: ${question.pattern}.\n`);
72+
return red(`The field "${question.name}" does not match the pattern: ${question.pattern}.\n`);
7373
default:
74-
return chalk.red(`The field "${question.name}" is invalid. Please try again.\n`);
74+
return red(`The field "${question.name}" is invalid. Please try again.\n`);
7575
}
7676
};
7777
class PromptContext {
@@ -124,7 +124,7 @@ function generatePromptMessageSuccinct(question: Question, ctx: PromptContext):
124124
const lines: string[] = [];
125125

126126
// 1. Main prompt label
127-
lines.push(chalk.whiteBright.bold(message || `${name}?`));
127+
lines.push(whiteBright.bold(message || `${name}?`));
128128

129129
// 2. Validation message if applicable
130130
const validation = validationMessage(question, ctx);
@@ -139,14 +139,14 @@ function generatePromptMessageSuccinct(question: Question, ctx: PromptContext):
139139
case 'confirm':
140140
inline = '(y/n)';
141141
if (def !== undefined) {
142-
inline += ` ${chalk.yellow(`[${def ? 'y' : 'n'}]`)}`;
142+
inline += ` ${yellow(`[${def ? 'y' : 'n'}]`)}`;
143143
}
144144
break;
145145

146146
case 'text':
147147
case 'number':
148148
if (def !== undefined) {
149-
inline += `${chalk.yellow(`[${def}]`)}`;
149+
inline += `${yellow(`[${def}]`)}`;
150150
}
151151
break;
152152

@@ -155,8 +155,8 @@ function generatePromptMessageSuccinct(question: Question, ctx: PromptContext):
155155
case 'checkbox':
156156
if (def !== undefined) {
157157
const defaults = Array.isArray(def) ? def : [def];
158-
const rendered = defaults.map(d => chalk.yellow(d)).join(chalk.gray(', '));
159-
inline += `${chalk.yellow(`[${rendered}]`)}`;
158+
const rendered = defaults.map(d => yellow(d)).join(gray(', '));
159+
inline += `${yellow(`[${rendered}]`)}`;
160160
}
161161
break;
162162
}
@@ -184,11 +184,11 @@ function generatePromptMessage(question: Question, ctx: PromptContext): string {
184184
const lines: string[] = [];
185185

186186
// 1. Title Message
187-
lines.push(chalk.whiteBright.bold(message || `${name}?`));
187+
lines.push(whiteBright.bold(message || `${name}?`));
188188

189189
// 2. Optional description below title
190190
if (description) {
191-
lines.push(chalk.dim(description));
191+
lines.push(dim(description));
192192
}
193193

194194
// 3. Validation warning (if failed before)
@@ -199,7 +199,7 @@ function generatePromptMessage(question: Question, ctx: PromptContext): string {
199199

200200
// 4. Metadata (name/type)
201201
lines.push(
202-
`${chalk.dim('Argument')} ${chalk.green(`--${name}`)} ${chalk.dim('type')} ${chalk.cyan(`[${type}]`)}`
202+
`${dim('Argument')} ${green(`--${name}`)} ${dim('type')} ${cyan(`[${type}]`)}`
203203
);
204204

205205
// 5. Default value or guidance
@@ -209,14 +209,14 @@ function generatePromptMessage(question: Question, ctx: PromptContext): string {
209209
case 'confirm':
210210
guidance = '(y/n)';
211211
if (def !== undefined) {
212-
guidance += ` ${chalk.yellow(`[default: ${def ? 'y' : 'n'}]`)}`;
212+
guidance += ` ${yellow(`[default: ${def ? 'y' : 'n'}]`)}`;
213213
}
214214
break;
215215

216216
case 'text':
217217
case 'number':
218218
if (def !== undefined) {
219-
guidance = chalk.yellow(`[default: ${def}]`);
219+
guidance = yellow(`[default: ${def}]`);
220220
}
221221
break;
222222

@@ -225,8 +225,8 @@ function generatePromptMessage(question: Question, ctx: PromptContext): string {
225225
case 'checkbox':
226226
if (def !== undefined) {
227227
const defaults = Array.isArray(def) ? def : [def];
228-
const rendered = defaults.map(d => chalk.yellow(d)).join(chalk.gray(', '));
229-
guidance += `${chalk.yellow(`[default: ${rendered}]`)}`;
228+
const rendered = defaults.map(d => yellow(d)).join(gray(', '));
229+
guidance += `${yellow(`[default: ${rendered}]`)}`;
230230
}
231231
break;
232232
}
@@ -236,7 +236,7 @@ function generatePromptMessage(question: Question, ctx: PromptContext): string {
236236
}
237237

238238
// 6. Final input prompt
239-
lines.push(chalk.white('> ') + chalk.dim('Your input:'));
239+
lines.push(white('> ') + dim('Your input:'));
240240

241241
return lines.join('\n') + '\n';
242242
}
@@ -309,7 +309,7 @@ export class Inquirerer {
309309
}
310310

311311
private getInput(input: string) {
312-
return `${chalk.white.bold('$')} ${input}`;
312+
return `${white.bold('$')} ${input}`;
313313
}
314314

315315
private getPrompt(question: Question, ctx: PromptContext, input: string) {
@@ -322,51 +322,51 @@ export class Inquirerer {
322322
}
323323

324324
public generateManPage(opts: ManPageInfo): string {
325-
let manPage = `${chalk.white('NAME')}\n\t${chalk.white(opts.commandName)} ${opts.description ?? ''}\n\n`;
325+
let manPage = `${white('NAME')}\n\t${white(opts.commandName)} ${opts.description ?? ''}\n\n`;
326326

327327
// Constructing the SYNOPSIS section with required and optional arguments
328328
let requiredArgs = '';
329329
let optionalArgs = '';
330330

331331
opts.questions.forEach(question => {
332332
if (question.required) {
333-
requiredArgs += ` ${chalk.white('--' + question.name)} <${chalk.gray(question.name)}>`;
333+
requiredArgs += ` ${white('--' + question.name)} <${gray(question.name)}>`;
334334
} else {
335-
optionalArgs += ` [${chalk.white('--' + question.name)}${question.default ? `=${chalk.gray(String(question.default))}` : ''}]`;
335+
optionalArgs += ` [${white('--' + question.name)}${question.default ? `=${gray(String(question.default))}` : ''}]`;
336336
}
337337
});
338338

339-
manPage += `${chalk.white('SYNOPSIS')}\n\t${chalk.white(opts.commandName)}${chalk.gray(requiredArgs)}${chalk.gray(optionalArgs)}\n\n`;
340-
manPage += `${chalk.white('DESCRIPTION')}\n\tUse this command to interact with the application. It supports the following options:\n\n`;
339+
manPage += `${white('SYNOPSIS')}\n\t${white(opts.commandName)}${gray(requiredArgs)}${gray(optionalArgs)}\n\n`;
340+
manPage += `${white('DESCRIPTION')}\n\tUse this command to interact with the application. It supports the following options:\n\n`;
341341

342342
opts.questions.forEach(question => {
343-
manPage += `${chalk.white(question.name.toUpperCase())}\n`;
344-
manPage += `\t${chalk.white('Type:')} ${chalk.gray(question.type)}\n`;
343+
manPage += `${white(question.name.toUpperCase())}\n`;
344+
manPage += `\t${white('Type:')} ${gray(question.type)}\n`;
345345
if (question.message) {
346-
manPage += `\t${chalk.white('Summary:')} ${chalk.gray(question.message)}\n`;
346+
manPage += `\t${white('Summary:')} ${gray(question.message)}\n`;
347347
}
348348
if (question.description) {
349-
manPage += `\t${chalk.white('Description:')} ${chalk.gray(question.description)}\n`;
349+
manPage += `\t${white('Description:')} ${gray(question.description)}\n`;
350350
}
351351
if ('options' in question) {
352352
const optionsList = Array.isArray(question.options)
353-
? question.options.map(opt => typeof opt === 'string' ? chalk.gray(opt) : `${chalk.gray(opt.name)} (${chalk.gray(opt.value)})`).join(', ')
353+
? question.options.map(opt => typeof opt === 'string' ? gray(opt) : `${gray(opt.name)} (${gray(opt.value)})`).join(', ')
354354
: '';
355-
manPage += `\t${chalk.white('Options:')} ${chalk.gray(optionsList)}\n`;
355+
manPage += `\t${white('Options:')} ${gray(optionsList)}\n`;
356356
}
357357
if (question.default !== undefined) {
358-
manPage += `\t${chalk.white('Default:')} ${chalk.gray(JSON.stringify(question.default))}\n`;
358+
manPage += `\t${white('Default:')} ${gray(JSON.stringify(question.default))}\n`;
359359
}
360360
if (question.required) {
361-
manPage += `\t${chalk.white('Required:')} ${chalk.gray('Yes')}\n`;
361+
manPage += `\t${white('Required:')} ${gray('Yes')}\n`;
362362
} else {
363-
manPage += `\t${chalk.white('Required:')} ${chalk.gray('No')}\n`;
363+
manPage += `\t${white('Required:')} ${gray('No')}\n`;
364364
}
365365
manPage += '\n';
366366
});
367367

368-
manPage += `${chalk.white('EXAMPLES')}\n\tExample usage of \`${chalk.white(opts.commandName)}\`.\n\t$ ${chalk.white(opts.commandName)}${chalk.gray(requiredArgs)}${chalk.gray(optionalArgs)}\n\n`;
369-
manPage += opts.author ? `${chalk.white('AUTHOR')}\n\t${chalk.white(opts.author)}\n` : '';
368+
manPage += `${white('EXAMPLES')}\n\tExample usage of \`${white(opts.commandName)}\`.\n\t$ ${white(opts.commandName)}${gray(requiredArgs)}${gray(optionalArgs)}\n\n`;
369+
manPage += opts.author ? `${white('AUTHOR')}\n\t${white(opts.author)}\n` : '';
370370
return manPage;
371371
}
372372

@@ -812,7 +812,7 @@ export class Inquirerer {
812812
if (index >= 0) {
813813
const isChecked = selections[index] ? '◉' : '○'; // Use the original index in options
814814
const line = `${marker} ${isChecked} ${option.name}`;
815-
this.log(isSelected ? chalk.blue(line) : line);
815+
this.log(isSelected ? blue(line) : line);
816816
} else {
817817
this.log('No options'); // sometimes user searches and there are no options...
818818
}
@@ -924,7 +924,7 @@ export class Inquirerer {
924924
if (!option) {
925925
this.log('No options'); // sometimes user searches and there are no options...
926926
} else if (i === selectedIndex) {
927-
this.log(chalk.blue('> ' + option.name)); // Highlight the selected option with chalk
927+
this.log(blue('> ' + option.name)); // Highlight the selected option with yanse
928928
} else {
929929
this.log(' ' + option.name);
930930
}
@@ -1020,7 +1020,7 @@ export class Inquirerer {
10201020
if (!option) {
10211021
this.log('No options'); // sometimes user searches and there are no options...
10221022
} else if (i === selectedIndex) {
1023-
this.log(chalk.blue('> ' + option.name)); // Highlight the selected option with chalk
1023+
this.log(blue('> ' + option.name)); // Highlight the selected option with yanse
10241024
} else {
10251025
this.log(' ' + option.name);
10261026
}

packages/inquirerer/src/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import chalk from 'chalk';
1+
import { green, blue } from 'yanse';
22

33
import { readAndParsePackageJson } from "./package";
44

55
// Function to display the version information
66
export function displayVersion(): any {
77
const pkg = readAndParsePackageJson();
8-
console.log(chalk.green(`Name: ${pkg.name}`));
9-
console.log(chalk.blue(`Version: ${pkg.version}`));
8+
console.log(green(`Name: ${pkg.name}`));
9+
console.log(blue(`Version: ${pkg.version}`));
1010
}
1111

1212

0 commit comments

Comments
 (0)