Skip to content

Commit 0c2d054

Browse files
committed
fix: only test color depth when the stdout is TTY, fixing CI issue
1 parent f3b963d commit 0c2d054

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ import minimist from 'minimist'
77
import prompts from 'prompts'
88
import { red, green, bold } from 'kolorist'
99

10+
import * as banners from './utils/banners'
11+
1012
import renderTemplate from './utils/renderTemplate'
1113
import { postOrderDirectoryTraverse, preOrderDirectoryTraverse } from './utils/directoryTraverse'
1214
import generateReadme from './utils/generateReadme'
1315
import getCommand from './utils/getCommand'
1416
import renderEslint from './utils/renderEslint'
15-
import banner from './utils/banner'
1617

1718
function isValidPackageName(projectName) {
1819
return /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(projectName)
@@ -56,7 +57,13 @@ function emptyDir(dir) {
5657
}
5758

5859
async function init() {
59-
console.log(`\n${banner}\n`)
60+
console.log()
61+
console.log(
62+
process.stdout.isTTY && process.stdout.getColorDepth() > 8
63+
? banners.gradientBanner
64+
: banners.defaultBanner
65+
)
66+
console.log()
6067

6168
const cwd = process.cwd()
6269
// possible options:

utils/banner.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

utils/banners.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const defaultBanner = 'Vue.js - The Progressive JavaScript Framework'
2+
3+
// generated by the following code:
4+
//
5+
// require('gradient-string')([
6+
// { color: '#42d392', pos: 0 },
7+
// { color: '#42d392', pos: 0.1 },
8+
// { color: '#647eff', pos: 1 }
9+
// ])('Vue.js - The Progressive JavaScript Framework'))
10+
//
11+
// Use the output directly here to keep the bundle small.
12+
const gradientBanner =
13+
'\x1B[38;2;66;211;146mV\x1B[39m\x1B[38;2;66;211;146mu\x1B[39m\x1B[38;2;66;211;146me\x1B[39m\x1B[38;2;66;211;146m.\x1B[39m\x1B[38;2;66;211;146mj\x1B[39m\x1B[38;2;67;209;149ms\x1B[39m \x1B[38;2;68;206;152m-\x1B[39m \x1B[38;2;69;204;155mT\x1B[39m\x1B[38;2;70;201;158mh\x1B[39m\x1B[38;2;71;199;162me\x1B[39m \x1B[38;2;72;196;165mP\x1B[39m\x1B[38;2;73;194;168mr\x1B[39m\x1B[38;2;74;192;171mo\x1B[39m\x1B[38;2;75;189;174mg\x1B[39m\x1B[38;2;76;187;177mr\x1B[39m\x1B[38;2;77;184;180me\x1B[39m\x1B[38;2;78;182;183ms\x1B[39m\x1B[38;2;79;179;186ms\x1B[39m\x1B[38;2;80;177;190mi\x1B[39m\x1B[38;2;81;175;193mv\x1B[39m\x1B[38;2;82;172;196me\x1B[39m \x1B[38;2;83;170;199mJ\x1B[39m\x1B[38;2;83;167;202ma\x1B[39m\x1B[38;2;84;165;205mv\x1B[39m\x1B[38;2;85;162;208ma\x1B[39m\x1B[38;2;86;160;211mS\x1B[39m\x1B[38;2;87;158;215mc\x1B[39m\x1B[38;2;88;155;218mr\x1B[39m\x1B[38;2;89;153;221mi\x1B[39m\x1B[38;2;90;150;224mp\x1B[39m\x1B[38;2;91;148;227mt\x1B[39m \x1B[38;2;92;145;230mF\x1B[39m\x1B[38;2;93;143;233mr\x1B[39m\x1B[38;2;94;141;236ma\x1B[39m\x1B[38;2;95;138;239mm\x1B[39m\x1B[38;2;96;136;243me\x1B[39m\x1B[38;2;97;133;246mw\x1B[39m\x1B[38;2;98;131;249mo\x1B[39m\x1B[38;2;99;128;252mr\x1B[39m\x1B[38;2;100;126;255mk\x1B[39m'
14+
15+
export { defaultBanner, gradientBanner }

0 commit comments

Comments
 (0)