Skip to content

Commit a62b4c5

Browse files
authored
Replace chalk with picocolors (#846)
1 parent 760dda5 commit a62b4c5

File tree

5 files changed

+24
-52
lines changed

5 files changed

+24
-52
lines changed

.changeset/heavy-waves-thank.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@codama/errors': patch
3+
---
4+
5+
Replace chalk with picocolors in CLI

packages/cli/src/utils/logs.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,10 @@ function logItems(items: string[], color?: (text: string) => string): void {
4949
}
5050

5151
export function logBanner(): void {
52-
console.log(getBanner());
52+
console.log(pico.bold(codamaColor('Welcome to Codama!')));
5353
}
5454

55-
function getBanner(): string {
56-
const textBanner = 'Welcome to Codama!';
57-
const gradientBanner = pico.bold(`\x1b[38;2;231;171;97m${textBanner}\x1b[0m`);
58-
return process.stdout.isTTY && process.stdout.getColorDepth() > 8 ? gradientBanner : textBanner;
55+
function codamaColor(text: string): string {
56+
if (!pico.isColorSupported) return text;
57+
return `\x1b[38;2;231;171;97m${text}\x1b[0m`;
5958
}

packages/errors/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"dependencies": {
5151
"@codama/node-types": "workspace:*",
5252
"commander": "^14.0.0",
53-
"chalk": "^5.6.2"
53+
"picocolors": "^1.1.1"
5454
},
5555
"license": "MIT",
5656
"repository": {

packages/errors/src/cli/index.ts

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* @see https://github.com/anza-xyz/kit/blob/main/packages/errors
44
*/
55

6-
import chalk from 'chalk';
76
import { Command, InvalidArgumentError } from 'commander';
7+
import pico from 'picocolors';
88

99
import { version } from '../../package.json';
1010
import { CodamaErrorCode } from '../codes';
@@ -37,29 +37,21 @@ program
3737
}
3838
})
3939
.action((code: number, context: object | undefined) => {
40+
const header = codamaColor(pico.bold('[Decoded]') + ` Codama error code #${code}`);
4041
const message = getHumanReadableErrorMessage(code as CodamaErrorCode, context);
41-
console.log(`
42-
${
43-
chalk.bold(
44-
chalk.rgb(154, 71, 255)('[') +
45-
chalk.rgb(144, 108, 244)('D') +
46-
chalk.rgb(134, 135, 233)('e') +
47-
chalk.rgb(122, 158, 221)('c') +
48-
chalk.rgb(110, 178, 209)('o') +
49-
chalk.rgb(95, 195, 196)('d') +
50-
chalk.rgb(79, 212, 181)('e') +
51-
chalk.rgb(57, 227, 166)('d') +
52-
chalk.rgb(19, 241, 149)(']'),
53-
) + chalk.rgb(19, 241, 149)(' Codama error code #' + code)
54-
}
55-
- ${message}`);
42+
console.log(`\n${header}\n ${message}`);
5643
if (context) {
57-
console.log(`
58-
${chalk.yellowBright(chalk.bold('[Context]'))}
59-
${JSON.stringify(context, null, 4).split('\n').join('\n ')}`);
44+
const contextHeader = pico.blue(pico.bold('[Context]'));
45+
const contextString = JSON.stringify(context, null, 4).split('\n').join('\n ');
46+
console.log(`\n${contextHeader}\n ${contextString}`);
6047
}
6148
});
6249

6350
export function run(argv: readonly string[]) {
6451
program.parse(argv);
6552
}
53+
54+
function codamaColor(text: string): string {
55+
if (!pico.isColorSupported) return text;
56+
return `\x1b[38;2;231;171;97m${text}\x1b[0m`;
57+
}

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)