Skip to content

Commit 4ddaf28

Browse files
committed
Add picocolors
1 parent 5a88cbf commit 4ddaf28

File tree

3 files changed

+40
-27
lines changed

3 files changed

+40
-27
lines changed

packages/create-vue-lib/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"copyfiles": "^2.4.1",
3232
"ejs": "^3.1.10",
3333
"npm-run-all2": "^7.0.2",
34+
"picocolors": "^1.1.1",
3435
"prompts": "^2.4.2",
3536
"publint": "^0.3.8",
3637
"rimraf": "^6.0.1",

packages/create-vue-lib/src/index.ts

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as path from 'node:path'
55
import { parseArgs } from 'node:util'
66
import prompts, { type PromptObject } from 'prompts'
77
import ejs from 'ejs'
8+
import { bgGreen, bgMagenta, bgRed, bgYellowBright, black, blue, bold, cyan, green, red, yellowBright } from 'picocolors'
89
import packageJson from '../package.json'
910

1011
async function prompt(options: Omit<PromptObject, 'name'>) {
@@ -24,7 +25,7 @@ async function prompt(options: Omit<PromptObject, 'name'>) {
2425
return result.name
2526
}
2627
catch (cancelled) {
27-
console.log((cancelled as { message: string }).message)
28+
console.log(red(`${(cancelled as { message: string }).message}`))
2829
process.exit(1)
2930
}
3031
}
@@ -90,17 +91,17 @@ type Args = {
9091
extended: boolean
9192
}
9293

93-
const helpMessage = `\
94-
Usage: create-vue-lib [OPTIONS...]
94+
const helpMessage = `
95+
${bold('Usage:')} ${bold(green('create-vue-lib'))} ${green('[OPTIONS...]')}
9596
9697
Create a new Vite project to build a Vue-based library.
9798
98-
Options:
99-
--extended, -x
99+
${bold('Options:')}
100+
${cyan('--extended')}, ${cyan('-x')}
100101
Prompt for extra configuration options.
101-
--help, -h
102+
${cyan('--help')}, ${cyan('-h')}
102103
Display this help message.
103-
--version, -v
104+
${cyan('--version')}, ${cyan('-v')}
104105
Display the version number for create-vue-lib.
105106
106107
Full documentation at https://skirtles-code.github.io/create-vue-lib/
@@ -133,8 +134,8 @@ function processArgs(): Args {
133134
}
134135
catch (err) {
135136
if ((err as { code: string }).code === 'ERR_PARSE_ARGS_UNKNOWN_OPTION') {
136-
console.log('Error:')
137-
console.log((err as { message: string }).message)
137+
console.log(bgRed(black('ERROR')))
138+
console.log(red(`${(err as { message: string }).message}`))
138139
console.log('See --help for valid options')
139140
process.exit(1)
140141
}
@@ -176,9 +177,9 @@ async function init() {
176177
const { extended } = processArgs()
177178

178179
console.log()
179-
console.log(`Welcome to ${packageJson.name} v${packageJson.version}`)
180+
console.log(`Welcome to ${bold(green(packageJson.name))} v${bold(cyan(packageJson.version))}`)
180181
console.log()
181-
console.log('This tool will help you to scaffold a Vite project for your Vue-based library.')
182+
console.log(`This tool will help you to scaffold a ${bgMagenta(bold(yellowBright('Vite')))} project for your ${bgGreen(bold(blue('Vue')))}-based library.`)
182183
console.log()
183184
console.log('It is recommended to use a scoped package name for your library.')
184185
console.log('e.g. @username/package-name')
@@ -188,7 +189,8 @@ async function init() {
188189
const scopedPackageName = await textPrompt('Package name', '')
189190

190191
if (!isValidPackageName(scopedPackageName)) {
191-
console.log('Invalid package name: ' + scopedPackageName)
192+
console.log(bgRed(black('ERROR')))
193+
console.log(red('Invalid package name: ' + scopedPackageName))
192194
process.exit(1)
193195
}
194196

@@ -200,7 +202,8 @@ async function init() {
200202
const targetDirName = await textPrompt('Target directory', unscopedPackageName)
201203

202204
if (targetDirName !== '.' && !isValidDirName(targetDirName)) {
203-
console.log('Invalid directory name: ' + targetDirName)
205+
console.log(bgRed(black('ERROR')))
206+
console.log(red('Invalid directory name: ' + targetDirName))
204207
process.exit(1)
205208
}
206209

@@ -209,12 +212,12 @@ async function init() {
209212
if (targetDirName === '.') {
210213
// TODO: Check files properly and prompt accordingly
211214
if (fs.existsSync(path.join(targetDirPath, 'package.json'))) {
212-
console.log('Target directory already contains package.json')
215+
console.log(`${bgYellowBright(black('⚠ WARNING'))} Target directory already contains package.json`)
213216
}
214217
}
215218
else {
216219
if (fs.existsSync(targetDirPath)) {
217-
console.log('Target directory already exists')
220+
console.log(`${bgYellowBright(black('⚠ WARNING'))} Target directory already exists`)
218221
}
219222
}
220223

@@ -224,7 +227,8 @@ async function init() {
224227
const mainPackageDirName = await textPromptIf(extended, 'Main package directory', unscopedPackageName)
225228

226229
if (!isValidDirName(mainPackageDirName)) {
227-
console.log('Invalid directory name: ' + mainPackageDirName)
230+
console.log(bgRed(black('ERROR')))
231+
console.log(red('Invalid directory name: ' + mainPackageDirName))
228232
process.exit(1)
229233
}
230234

@@ -238,7 +242,8 @@ async function init() {
238242
const globalVariableName = await textPromptIf(extended, 'Global variable name', defaultGlobalVariableName)
239243

240244
if (!/^[a-zA-Z$_][\w$]*$/.test(globalVariableName)) {
241-
console.log('Invalid variable name: ' + globalVariableName)
245+
console.log(bgRed(black('ERROR')))
246+
console.log(red('Invalid variable name: ' + globalVariableName))
242247
process.exit(1)
243248
}
244249

@@ -252,7 +257,8 @@ async function init() {
252257

253258
// We don't need to be strict here, so long as it won't break the generated files
254259
if (rawGithubPath && !/^[\w-]+\/[\w-.]+$/.test(githubPath)) {
255-
console.log('Invalid GitHub path: ' + rawGithubPath)
260+
console.log(bgRed(black('ERROR')))
261+
console.log(red('Invalid GitHub path: ' + rawGithubPath))
256262
process.exit(1)
257263
}
258264

@@ -273,19 +279,22 @@ async function init() {
273279
}
274280

275281
if (includeDocs && mainPackageDirName === 'docs') {
276-
console.log(`The directory name 'docs' is reserved for the documentation, please choose a different name.`)
282+
console.log(bgRed(black('ERROR')))
283+
console.log(red(`The directory name 'docs' is reserved for the documentation, please choose a different name.`))
277284
suggestExtended()
278285
process.exit(1)
279286
}
280287

281288
if (includePlayground && mainPackageDirName === 'playground') {
282-
console.log(`The directory name 'playground' is reserved for the playground, please choose a different name.`)
289+
console.log(bgRed(black('ERROR')))
290+
console.log(red(`The directory name 'playground' is reserved for the playground, please choose a different name.`))
283291
suggestExtended()
284292
process.exit(1)
285293
}
286294

287295
if (!includePackagesDir && mainPackageDirName === 'scripts') {
288-
console.log(`The directory name 'scripts' is reserved for the scripts, please choose a different name.`)
296+
console.log(bgRed(black('ERROR')))
297+
console.log(red(`The directory name 'scripts' is reserved for the scripts, please choose a different name.`))
289298
suggestExtended()
290299
process.exit(1)
291300
}
@@ -352,22 +361,22 @@ async function init() {
352361
}
353362

354363
console.log()
355-
console.log('Project created')
364+
console.log(`${bgGreen(bold(black('DONE')))} Project created`)
356365
console.log()
357-
console.log('Note: pnpm must be used as the package manager')
366+
console.log(`${bgYellowBright(black('NOTE'))} pnpm must be used as the package manager`)
358367
console.log()
359-
console.log('Next steps:')
368+
console.log(bold('Next steps:'))
360369
console.log()
361370

362371
if (targetDirName !== '.') {
363-
console.log(' cd ' + targetDirName)
372+
console.log(bold(green(' cd ' + targetDirName)))
364373
}
365374

366375
if (!fs.existsSync(path.join(targetDirPath, '.git'))) {
367-
console.log(' git init -b main')
376+
console.log(bold(green(' git init -b main')))
368377
}
369378

370-
console.log(' pnpm install')
379+
console.log(bold(green(' pnpm install')))
371380
console.log()
372381
console.log('See https://skirtles-code.github.io/create-vue-lib/next-steps for more suggestions.')
373382
}

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)