Skip to content

Commit 5bd434c

Browse files
committed
refactor(cli): standardize color function names
1 parent b36ee0a commit 5bd434c

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

packages/cli/index.ts

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import languagePlugins = require('./lib/languagePlugins.js');
1111
process.env.TSSLINT_CLI = '1';
1212

1313
const _reset = '\x1b[0m';
14-
const darkGray = (s: string) => '\x1b[90m' + s + _reset;
15-
const lightRed = (s: string) => '\x1b[91m' + s + _reset;
16-
const lightGreen = (s: string) => '\x1b[92m' + s + _reset;
17-
const lightYellow = (s: string) => '\x1b[93m' + s + _reset;
18-
const lightBlue = (s: string) => '\x1b[94m' + s + _reset;
14+
const gray = (s: string) => '\x1b[90m' + s + _reset;
15+
const red = (s: string) => '\x1b[91m' + s + _reset;
16+
const green = (s: string) => '\x1b[92m' + s + _reset;
17+
const yellow = (s: string) => '\x1b[93m' + s + _reset;
18+
const blue = (s: string) => '\x1b[94m' + s + _reset;
1919
const purple = (s: string) => '\x1b[95m' + s + _reset;
2020
const cyan = (s: string) => '\x1b[96m' + s + _reset;
2121

@@ -33,7 +33,7 @@ if (process.argv.includes('--threads')) {
3333
const threadsIndex = process.argv.indexOf('--threads');
3434
const threadsArg = process.argv[threadsIndex + 1];
3535
if (!threadsArg || threadsArg.startsWith('-')) {
36-
console.error(lightRed(`Missing argument for --threads.`));
36+
console.error(red(`Missing argument for --threads.`));
3737
process.exit(1);
3838
}
3939
threads = Math.min(os.availableParallelism(), Number(threadsArg));
@@ -81,10 +81,10 @@ class Project {
8181
}
8282
}
8383

84-
const label = labels.join(darkGray(' | '));
84+
const label = labels.join(gray(' | '));
8585

8686
if (!this.configFile) {
87-
clack.log.error(`${label} ${path.relative(process.cwd(), this.tsconfig)} ${darkGray('(No tsslint.config.ts found)')}`);
87+
clack.log.error(`${label} ${path.relative(process.cwd(), this.tsconfig)} ${gray('(No tsslint.config.ts found)')}`);
8888
return this;
8989
}
9090

@@ -94,11 +94,11 @@ class Project {
9494
this.options = commonLine.options;
9595

9696
if (!this.fileNames.length) {
97-
clack.log.warn(`${label} ${path.relative(process.cwd(), this.tsconfig)} ${darkGray('(No included files)')}`);
97+
clack.log.warn(`${label} ${path.relative(process.cwd(), this.tsconfig)} ${gray('(No included files)')}`);
9898
return this;
9999
}
100100

101-
clack.log.info(`${label} ${path.relative(process.cwd(), this.tsconfig)} ${darkGray(`(${this.fileNames.length})`)}`);
101+
clack.log.info(`${label} ${path.relative(process.cwd(), this.tsconfig)} ${gray(`(${this.fileNames.length})`)}`);
102102

103103
if (!process.argv.includes('--force')) {
104104
this.cache = cache.loadCache(this.tsconfig, this.configFile, ts.sys.createHash);
@@ -133,7 +133,7 @@ class Project {
133133
const write = process.stdout.write.bind(process.stdout);
134134
process.stdout.write = (...args) => {
135135
if (spinnerStopingWarn && typeof args[0] === 'string') {
136-
args[0] = args[0].replace('▲', lightYellow('▲'));
136+
args[0] = args[0].replace('▲', yellow('▲'));
137137
}
138138
// @ts-ignore
139139
return write(...args);
@@ -211,7 +211,7 @@ class Project {
211211
}
212212

213213
if (!options.length) {
214-
clack.log.error(lightRed('No projects found.'));
214+
clack.log.error(red('No projects found.'));
215215
process.exit(1);
216216
}
217217

@@ -234,7 +234,7 @@ class Project {
234234
command += ` --${language}-project ` + selectedTsconfigs.join(' ');
235235
}
236236

237-
clack.log.info(`${darkGray('Command:')} ${purple(command)}`);
237+
clack.log.info(`${gray('Command:')} ${purple(command)}`);
238238

239239
for (let tsconfig of selectedTsconfigs) {
240240
tsconfig = resolvePath(tsconfig);
@@ -283,7 +283,7 @@ class Project {
283283
const searchGlob = process.argv[i];
284284
const tsconfigs = glob.sync(searchGlob);
285285
if (!tsconfigs.length) {
286-
clack.log.error(lightRed(`No projects found for ${projectFlag} ${searchGlob}.`));
286+
clack.log.error(red(`No projects found for ${projectFlag} ${searchGlob}.`));
287287
process.exit(1);
288288
}
289289
for (let tsconfig of tsconfigs) {
@@ -297,7 +297,7 @@ class Project {
297297
}
298298
}
299299
if (!foundArg) {
300-
clack.log.error(lightRed(`Missing argument for ${projectFlag}.`));
300+
clack.log.error(red(`Missing argument for ${projectFlag}.`));
301301
process.exit(1);
302302
}
303303
}
@@ -320,7 +320,7 @@ class Project {
320320
}
321321

322322
if (allFilesNum === 0) {
323-
(spinner?.stop ?? clack.log.message)(lightYellow('No input files.'));
323+
(spinner?.stop ?? clack.log.message)(yellow('No input files.'));
324324
process.exit(1);
325325
}
326326

@@ -334,39 +334,39 @@ class Project {
334334

335335
(spinner?.stop ?? clack.log.message)(
336336
cached
337-
? darkGray(`Processed ${processed} files with cache. (Use `) + cyan(`--force`) + darkGray(` to ignore cache.)`)
338-
: darkGray(`Processed ${processed} files.`)
337+
? gray(`Processed ${processed} files with cache. (Use `) + cyan(`--force`) + gray(` to ignore cache.)`)
338+
: gray(`Processed ${processed} files.`)
339339
);
340340

341341
const projectsFlag = process.argv.find(arg => arg.endsWith('-projects'));
342342
if (projectsFlag) {
343343
clack.log.warn(
344-
darkGray(`Please use `)
344+
gray(`Please use `)
345345
+ cyan(`${projectsFlag.slice(0, -1)}`)
346-
+ darkGray(` instead of `)
346+
+ gray(` instead of `)
347347
+ cyan(`${projectsFlag}`)
348-
+ darkGray(` starting from version 1.5.0.`)
348+
+ gray(` starting from version 1.5.0.`)
349349
);
350350
}
351351

352352
const data = [
353-
[passed, 'passed', lightGreen] as const,
354-
[errors, 'errors', lightRed] as const,
355-
[warnings, 'warnings', lightYellow] as const,
356-
[messages, 'messages', lightBlue] as const,
357-
[suggestions, 'suggestions', darkGray] as const,
358-
[excluded, 'excluded', darkGray] as const,
353+
[passed, 'passed', green] as const,
354+
[errors, 'errors', red] as const,
355+
[warnings, 'warnings', yellow] as const,
356+
[messages, 'messages', blue] as const,
357+
[suggestions, 'suggestions', gray] as const,
358+
[excluded, 'excluded', gray] as const,
359359
];
360360

361361
let summary = data
362362
.filter(([count]) => count)
363363
.map(([count, label, color]) => color(`${count} ${label}`))
364-
.join(darkGray(' | '));
364+
.join(gray(' | '));
365365

366366
if (hasFix) {
367-
summary += darkGray(` (Use `) + cyan(`--fix`) + darkGray(` to apply automatic fixes.)`);
367+
summary += gray(` (Use `) + cyan(`--fix`) + gray(` to apply automatic fixes.)`);
368368
} else if (errors || warnings || messages) {
369-
summary += darkGray(` (No fixes available.)`);
369+
summary += gray(` (No fixes available.)`);
370370
}
371371

372372
clack.outro(summary);
@@ -502,7 +502,7 @@ class Project {
502502

503503
async function getBuiltConfig(configFile: string) {
504504
if (!builtConfigs.has(configFile)) {
505-
builtConfigs.set(configFile, core.buildConfig(configFile, ts.sys.createHash, spinner, (s, code) => log(darkGray(s), code)));
505+
builtConfigs.set(configFile, core.buildConfig(configFile, ts.sys.createHash, spinner, (s, code) => log(gray(s), code)));
506506
}
507507
return await builtConfigs.get(configFile);
508508
}
@@ -521,13 +521,13 @@ class Project {
521521
let msg: string | undefined;
522522
if (processFiles.size === 0) {
523523
if (nextFileName) {
524-
msg = darkGray(`[${processed + processFiles.size}/${allFilesNum}] ${path.relative(process.cwd(), nextFileName)}`);
524+
msg = gray(`[${processed + processFiles.size}/${allFilesNum}] ${path.relative(process.cwd(), nextFileName)}`);
525525
}
526526
}
527527
else if (processFiles.size === 1) {
528-
msg = darkGray(`[${processed + processFiles.size}/${allFilesNum}] ${path.relative(process.cwd(), [...processFiles][0])}`);
528+
msg = gray(`[${processed + processFiles.size}/${allFilesNum}] ${path.relative(process.cwd(), [...processFiles][0])}`);
529529
} else {
530-
msg = darkGray(`[${processed + processFiles.size}/${allFilesNum}] Processing ${processFiles.size} files`);
530+
msg = gray(`[${processed + processFiles.size}/${allFilesNum}] Processing ${processFiles.size} files`);
531531
}
532532
if (!spinner && isTTY) {
533533
spinner = clack.spinner();
@@ -567,7 +567,7 @@ class Project {
567567
try {
568568
return require.resolve(p, { paths: [process.cwd()] });
569569
} catch {
570-
clack.log.error(lightRed(`No such file: ${p}`));
570+
clack.log.error(red(`No such file: ${p}`));
571571
process.exit(1);
572572
}
573573
}

0 commit comments

Comments
 (0)