@@ -5,6 +5,7 @@ import * as path from 'node:path'
5
5
import { parseArgs } from 'node:util'
6
6
import prompts , { type PromptObject } from 'prompts'
7
7
import ejs from 'ejs'
8
+ import { bgGreen , bgMagenta , bgRed , bgYellowBright , black , blue , bold , cyan , green , red , yellowBright } from 'picocolors'
8
9
import packageJson from '../package.json'
9
10
10
11
async function prompt ( options : Omit < PromptObject , 'name' > ) {
@@ -24,7 +25,7 @@ async function prompt(options: Omit<PromptObject, 'name'>) {
24
25
return result . name
25
26
}
26
27
catch ( cancelled ) {
27
- console . log ( ( cancelled as { message : string } ) . message )
28
+ console . log ( red ( ` ${ ( cancelled as { message : string } ) . message } ` ) )
28
29
process . exit ( 1 )
29
30
}
30
31
}
@@ -90,17 +91,17 @@ type Args = {
90
91
extended : boolean
91
92
}
92
93
93
- const helpMessage = `\
94
- Usage: create-vue-lib [OPTIONS...]
94
+ const helpMessage = `
95
+ ${ bold ( ' Usage:' ) } ${ bold ( green ( ' create-vue-lib' ) ) } ${ green ( ' [OPTIONS...]' ) }
95
96
96
97
Create a new Vite project to build a Vue-based library.
97
98
98
- Options:
99
- --extended, -x
99
+ ${ bold ( ' Options:' ) }
100
+ ${ cyan ( ' --extended' ) } , ${ cyan ( '-x' ) }
100
101
Prompt for extra configuration options.
101
- --help, -h
102
+ ${ cyan ( ' --help' ) } , ${ cyan ( '-h' ) }
102
103
Display this help message.
103
- --version, -v
104
+ ${ cyan ( ' --version' ) } , ${ cyan ( '-v' ) }
104
105
Display the version number for create-vue-lib.
105
106
106
107
Full documentation at https://skirtles-code.github.io/create-vue-lib/
@@ -133,8 +134,8 @@ function processArgs(): Args {
133
134
}
134
135
catch ( err ) {
135
136
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 } ` ) )
138
139
console . log ( 'See --help for valid options' )
139
140
process . exit ( 1 )
140
141
}
@@ -176,9 +177,9 @@ async function init() {
176
177
const { extended } = processArgs ( )
177
178
178
179
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 ) ) } ` )
180
181
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.` )
182
183
console . log ( )
183
184
console . log ( 'It is recommended to use a scoped package name for your library.' )
184
185
console . log ( 'e.g. @username/package-name' )
@@ -188,7 +189,8 @@ async function init() {
188
189
const scopedPackageName = await textPrompt ( 'Package name' , '' )
189
190
190
191
if ( ! isValidPackageName ( scopedPackageName ) ) {
191
- console . log ( 'Invalid package name: ' + scopedPackageName )
192
+ console . log ( bgRed ( black ( 'ERROR' ) ) )
193
+ console . log ( red ( 'Invalid package name: ' + scopedPackageName ) )
192
194
process . exit ( 1 )
193
195
}
194
196
@@ -200,7 +202,8 @@ async function init() {
200
202
const targetDirName = await textPrompt ( 'Target directory' , unscopedPackageName )
201
203
202
204
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 ) )
204
207
process . exit ( 1 )
205
208
}
206
209
@@ -209,12 +212,12 @@ async function init() {
209
212
if ( targetDirName === '.' ) {
210
213
// TODO: Check files properly and prompt accordingly
211
214
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` )
213
216
}
214
217
}
215
218
else {
216
219
if ( fs . existsSync ( targetDirPath ) ) {
217
- console . log ( ' Target directory already exists' )
220
+ console . log ( ` ${ bgYellowBright ( black ( '⚠ WARNING' ) ) } Target directory already exists` )
218
221
}
219
222
}
220
223
@@ -224,7 +227,8 @@ async function init() {
224
227
const mainPackageDirName = await textPromptIf ( extended , 'Main package directory' , unscopedPackageName )
225
228
226
229
if ( ! isValidDirName ( mainPackageDirName ) ) {
227
- console . log ( 'Invalid directory name: ' + mainPackageDirName )
230
+ console . log ( bgRed ( black ( 'ERROR' ) ) )
231
+ console . log ( red ( 'Invalid directory name: ' + mainPackageDirName ) )
228
232
process . exit ( 1 )
229
233
}
230
234
@@ -238,7 +242,8 @@ async function init() {
238
242
const globalVariableName = await textPromptIf ( extended , 'Global variable name' , defaultGlobalVariableName )
239
243
240
244
if ( ! / ^ [ a - z A - 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 ) )
242
247
process . exit ( 1 )
243
248
}
244
249
@@ -252,7 +257,8 @@ async function init() {
252
257
253
258
// We don't need to be strict here, so long as it won't break the generated files
254
259
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 ) )
256
262
process . exit ( 1 )
257
263
}
258
264
@@ -273,19 +279,22 @@ async function init() {
273
279
}
274
280
275
281
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.` ) )
277
284
suggestExtended ( )
278
285
process . exit ( 1 )
279
286
}
280
287
281
288
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.` ) )
283
291
suggestExtended ( )
284
292
process . exit ( 1 )
285
293
}
286
294
287
295
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.` ) )
289
298
suggestExtended ( )
290
299
process . exit ( 1 )
291
300
}
@@ -352,22 +361,22 @@ async function init() {
352
361
}
353
362
354
363
console . log ( )
355
- console . log ( ' Project created ' )
364
+ console . log ( ` ${ bgGreen ( bold ( black ( 'DONE' ) ) ) } Project created` )
356
365
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` )
358
367
console . log ( )
359
- console . log ( 'Next steps:' )
368
+ console . log ( bold ( 'Next steps:' ) )
360
369
console . log ( )
361
370
362
371
if ( targetDirName !== '.' ) {
363
- console . log ( ' cd ' + targetDirName )
372
+ console . log ( bold ( green ( ' cd ' + targetDirName ) ) )
364
373
}
365
374
366
375
if ( ! fs . existsSync ( path . join ( targetDirPath , '.git' ) ) ) {
367
- console . log ( ' git init -b main' )
376
+ console . log ( bold ( green ( ' git init -b main' ) ) )
368
377
}
369
378
370
- console . log ( ' pnpm install' )
379
+ console . log ( bold ( green ( ' pnpm install' ) ) )
371
380
console . log ( )
372
381
console . log ( 'See https://skirtles-code.github.io/create-vue-lib/next-steps for more suggestions.' )
373
382
}
0 commit comments