Skip to content

Commit be22c11

Browse files
authored
refactor: change to colorette from chalk (#54)
* refactor: change to colorette from chalk * update lock file
1 parent f46fcad commit be22c11

File tree

6 files changed

+58
-56
lines changed

6 files changed

+58
-56
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"@intlify/core": "beta",
3232
"@intlify/shared": "beta",
3333
"@vue/compiler-sfc": "^3.2.20",
34-
"chalk": "^4.1.0",
34+
"colorette": "^2.0.16",
3535
"cosmiconfig": "^7.0.1",
3636
"debug": "^4.3.2",
3737
"diff-match-patch": "^1.0.5",

pnpm-lock.yaml

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

src/commands/annotate.ts

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { promises as fs } from 'fs'
2-
import chalk from 'chalk'
2+
import { green, white, yellow, red, yellowBright, bold } from 'colorette'
33
import createDebug from 'debug'
44
import { t } from '../i18n'
55
import { hasDiff } from '../utils'
@@ -90,7 +90,7 @@ export default function defineCommand() {
9090

9191
if (dryRun) {
9292
console.log()
93-
console.log(chalk.bold.yellowBright(`${t('dry run mode')}:`))
93+
console.log(yellowBright(bold(`${t('dry run mode')}:`)))
9494
console.log()
9595
}
9696

@@ -105,28 +105,24 @@ export default function defineCommand() {
105105
function printStats() {
106106
console.log('')
107107
console.log(
108-
chalk.bold.white(t('{count} annotateable files ', { count: counter }))
108+
white(bold(t('{count} annotateable files ', { count: counter })))
109109
)
110110
console.log(
111-
chalk.bold.green(t('{count} annotated files', { count: fineCounter }))
111+
green(bold(t('{count} annotated files', { count: fineCounter })))
112112
)
113113
if (details) {
114114
console.log(
115-
chalk.white(t('{count} passed files', { count: passCounter }))
115+
white(bold(t('{count} passed files', { count: passCounter })))
116116
)
117117
}
118-
console.log(
119-
chalk.yellow(t('{count} warned files', { count: warnCounter }))
120-
)
118+
console.log(yellow(t('{count} warned files', { count: warnCounter })))
121119
if (details) {
120+
console.log(yellow(t('{count} forced files', { count: forceCounter })))
122121
console.log(
123-
chalk.yellow(t('{count} forced files', { count: forceCounter }))
124-
)
125-
console.log(
126-
chalk.yellow(t('{count} ignored files', { count: ignoreCounter }))
122+
yellow(t('{count} ignored files', { count: ignoreCounter }))
127123
)
128124
}
129-
console.log(chalk.red(t('{count} error files', { count: errorCounter })))
125+
console.log(red(t('{count} error files', { count: errorCounter })))
130126
console.log('')
131127
}
132128

@@ -161,38 +157,38 @@ export default function defineCommand() {
161157

162158
if (status === 'fine') {
163159
fineCounter++
164-
console.log(chalk.green(`${file}: ${t('annotate')}`))
160+
console.log(green(`${file}: ${t('annotate')}`))
165161
if (!dryRun) {
166162
await fs.writeFile(file, annotated, 'utf8')
167163
}
168164
} else if (status === 'none') {
169165
passCounter++
170-
console.log(chalk.white(`${file}: ${t('pass annotate')}`))
166+
console.log(white(`${file}: ${t('pass annotate')}`))
171167
} else if (status === 'warn') {
172168
warnCounter++
173169
if (force) {
174170
forceCounter++
175-
console.log(chalk.yellow(`${file}: ${t('force annotate')}`))
171+
console.log(yellow(`${file}: ${t('force annotate')}`))
176172
if (!dryRun) {
177173
await fs.writeFile(file, annotated, 'utf8')
178174
}
179175
} else {
180176
ignoreCounter++
181-
console.log(chalk.yellow(`${file}: ${t('ignore annotate')}`))
177+
console.log(yellow(`${file}: ${t('ignore annotate')}`))
182178
}
183179
}
184180
} catch (e: unknown) {
185181
status = 'error'
186182
errorCounter++
187183
if (isSFCParserError(e)) {
188-
console.error(chalk.bold.red(`${e.message} at ${e.filepath}`))
189-
e.erorrs.forEach(err => console.error(chalk.red(` ${err.message}`)))
184+
console.error(red(bold(`${e.message} at ${e.filepath}`)))
185+
e.erorrs.forEach(err => console.error(red(` ${err.message}`)))
190186
} else if (e instanceof SFCAnnotateError) {
191187
console.error(
192-
chalk.red(`${e.filepath}: ${t(e.message as any)}`) // eslint-disable-line @typescript-eslint/no-explicit-any, @intlify/vue-i18n/no-dynamic-keys
188+
red(`${e.filepath}: ${t(e.message as any)}`) // eslint-disable-line @typescript-eslint/no-explicit-any, @intlify/vue-i18n/no-dynamic-keys
193189
)
194190
} else {
195-
console.error(chalk.red((e as Error).message))
191+
console.error(red((e as Error).message))
196192
}
197193
if (!dryRun) {
198194
throw e
@@ -220,13 +216,11 @@ function warnHnadler(cb: () => void) {
220216
switch (code) {
221217
case AnnotateWarningCodes.NOT_SUPPORTED_TYPE:
222218
console.log(
223-
chalk.yellow(
224-
t(`Unsupported '{type}' block content type: {actual}`, args)
225-
)
219+
yellow(t(`Unsupported '{type}' block content type: {actual}`, args))
226220
)
227221
case AnnotateWarningCodes.LANG_MISMATCH_IN_ATTR_AND_CONTENT:
228222
console.log(
229-
chalk.yellow(
223+
yellow(
230224
t(
231225
"Detected lang mismatch in `lang` attr ('{lang}') and block content ('{content}')",
232226
args
@@ -235,7 +229,7 @@ function warnHnadler(cb: () => void) {
235229
)
236230
case AnnotateWarningCodes.LANG_MISMATCH_IN_OPTION_AND_CONTENT:
237231
console.log(
238-
chalk.yellow(
232+
yellow(
239233
t(
240234
"Detected lang mismatch in `lang` option ('{lang}') and block content ('{content}')",
241235
args
@@ -244,7 +238,7 @@ function warnHnadler(cb: () => void) {
244238
)
245239
case AnnotateWarningCodes.LANG_MISMATCH_IN_SRC_AND_CONTENT:
246240
console.log(
247-
chalk.yellow(
241+
yellow(
248242
t(
249243
"Detected lang mismatch in block `src` ('{src}') and block content ('{content}')",
250244
args

src/commands/compile.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import path from 'pathe'
2-
import chalk from 'chalk'
2+
import { green, yellow } from 'colorette'
33
import createDebug from 'debug'
44
import { CompileErrorCodes, compile } from '../api'
55
import { t } from '../i18n'
@@ -52,7 +52,7 @@ export default function defineCommand() {
5252
mode: args.mode as DevEnv,
5353
onCompile: (source: string, output: string): void => {
5454
console.log(
55-
chalk.green(
55+
green(
5656
t('Success compilation: {source} -> {output}', { source, output })
5757
)
5858
)
@@ -67,7 +67,7 @@ export default function defineCommand() {
6767
case CompileErrorCodes.NOT_SUPPORTED_FORMAT:
6868
const parsed = path.parse(source)
6969
console.warn(
70-
chalk.yellow(
70+
yellow(
7171
t("{source}: Ignore compilation due to not supported '{ext}'", {
7272
named: { ext: parsed.ext }
7373
})
@@ -76,7 +76,7 @@ export default function defineCommand() {
7676
break
7777
case CompileErrorCodes.INTERNAL_COMPILE_WARNING:
7878
console.log(
79-
chalk.yellow(
79+
yellow(
8080
t('Warning compilation: {source} -> {output}, {msg}', {
8181
named: { source, output, msg }
8282
})
@@ -85,7 +85,7 @@ export default function defineCommand() {
8585
break
8686
case CompileErrorCodes.INTERNAL_COMPILE_ERROR:
8787
console.log(
88-
chalk.green(
88+
green(
8989
t('Error compilation: {source} -> {output}, {msg}', {
9090
named: { source, output, msg }
9191
})

src/commands/fail.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import chalk from 'chalk'
1+
import { bold, red, yellow } from 'colorette'
22

33
// eslint-disable-next-line @typescript-eslint/no-explicit-any
44
type Constructor<T> = { new (...args: any[]): T }
@@ -16,11 +16,11 @@ export function defineFail(userError: any) {
1616
if (msg) {
1717
// TODO: should refactor console message
1818
console.error(msg)
19-
console.warn(chalk.bold.red(msg))
19+
console.warn(red(bold(msg)))
2020
process.exit(1)
2121
} else {
2222
if (typeGuard(err, userError)) {
23-
console.warn(chalk.bold.yellow(err.message))
23+
console.warn(yellow(bold(err.message)))
2424
process.exit(0)
2525
} else {
2626
// preserve statck! see the https://github.com/yargs/yargs/blob/master/docs/api.md#failfn

src/commands/format.ts

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
import { promises as fs } from 'fs'
2-
import chalk from 'chalk'
2+
import {
3+
green,
4+
blue,
5+
red,
6+
whiteBright,
7+
greenBright,
8+
redBright,
9+
blueBright,
10+
yellowBright,
11+
bold
12+
} from 'colorette'
313
import path from 'pathe'
414
import createDebug from 'debug'
515
import { t } from '../i18n'
@@ -76,7 +86,7 @@ export default function defineCommand() {
7686

7787
if (dryRun) {
7888
console.log()
79-
console.log(chalk.bold.yellowBright(`${t('dry run mode')}:`))
89+
console.log(yellowBright(bold(`${t('dry run mode')}:`)))
8090
console.log()
8191
}
8292

@@ -99,10 +109,10 @@ export default function defineCommand() {
99109
})
100110
if (hasDiff(formatted, data)) {
101111
formattedCounter++
102-
console.log(chalk.green(`${file}: ${t('formatted')}`))
112+
console.log(green(`${file}: ${t('formatted')}`))
103113
} else {
104114
noChangeCounter++
105-
console.log(chalk.blue(`${file}: ${t('no change')}`))
115+
console.log(blue(`${file}: ${t('no change')}`))
106116
}
107117
if (!dryRun) {
108118
await fs.writeFile(file, formatted, 'utf8')
@@ -111,13 +121,13 @@ export default function defineCommand() {
111121
errorCounter++
112122
if (e instanceof FormatLangNotFoundError) {
113123
console.error(
114-
chalk.red(`${e.filepath}: ${t(e.message as any)}`) // eslint-disable-line @typescript-eslint/no-explicit-any, @intlify/vue-i18n/no-dynamic-keys
124+
red(`${e.filepath}: ${t(e.message as any)}`) // eslint-disable-line @typescript-eslint/no-explicit-any, @intlify/vue-i18n/no-dynamic-keys
115125
)
116126
} else if (isSFCParserError(e)) {
117-
console.error(chalk.red(`${e.message} at ${e.filepath}`))
118-
e.erorrs.forEach(err => console.error(chalk.red(` ${err.message}`)))
127+
console.error(red(`${e.message} at ${e.filepath}`))
128+
e.erorrs.forEach(err => console.error(red(` ${err.message}`)))
119129
} else {
120-
console.error(chalk.red((e as Error).message))
130+
console.error(red((e as Error).message))
121131
}
122132

123133
if (!dryRun) {
@@ -128,23 +138,19 @@ export default function defineCommand() {
128138

129139
console.log('')
130140
console.log(
131-
chalk.bold.whiteBright(
132-
t('{count} formattable files', { count: files.length })
133-
)
141+
whiteBright(bold(t('{count} formattable files', { count: files.length })))
134142
)
135143
console.log(
136-
chalk.bold.greenBright(
137-
t('{count} formatted files', { count: formattedCounter })
144+
greenBright(
145+
bold(t('{count} formatted files', { count: formattedCounter }))
138146
)
139147
)
140148
console.log(
141-
chalk.bold.blueBright(
142-
t('{count} no change files', { count: noChangeCounter })
143-
)
149+
blueBright(bold(t('{count} no change files', { count: noChangeCounter })))
144150
)
145151
if (dryRun) {
146152
console.log(
147-
chalk.bold.redBright(t('{count} error files', { count: errorCounter }))
153+
redBright(bold(t('{count} error files', { count: errorCounter })))
148154
)
149155
}
150156
console.log('')

0 commit comments

Comments
 (0)