Skip to content

Commit 1d9bfc0

Browse files
edvardsantabluwy
andauthored
feat(create-vite): add help usage (#16390)
Co-authored-by: bluwy <[email protected]>
1 parent b4b4acf commit 1d9bfc0

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

packages/create-vite/__tests__/cli.spec.ts

+12
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,15 @@ test('accepts command line override for --overwrite', () => {
103103
const { stdout } = run(['.', '--overwrite', 'ignore'], { cwd: genPath })
104104
expect(stdout).not.toContain(`Current directory is not empty.`)
105105
})
106+
107+
test('return help usage how to use create-vite', () => {
108+
const { stdout } = run(['--help'], { cwd: __dirname })
109+
const message = 'Usage: create-vite [OPTION]... [DIRECTORY]'
110+
expect(stdout).toContain(message)
111+
})
112+
113+
test('return help usage how to use create-vite with -h alias', () => {
114+
const { stdout } = run(['--h'], { cwd: __dirname })
115+
const message = 'Usage: create-vite [OPTION]... [DIRECTORY]'
116+
expect(stdout).toContain(message)
117+
})

packages/create-vite/src/index.ts

+33-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,36 @@ import {
2020
// Avoids autoconversion to number of the project name by defining that the args
2121
// non associated with an option ( _ ) needs to be parsed as a string. See #4606
2222
const argv = minimist<{
23-
t?: string
2423
template?: string
25-
}>(process.argv.slice(2), { string: ['_'] })
24+
help?: boolean
25+
}>(process.argv.slice(2), {
26+
default: { help: false },
27+
alias: { h: 'help', t: 'template' },
28+
string: ['_'],
29+
})
2630
const cwd = process.cwd()
2731

32+
// prettier-ignore
33+
const helpMessage = `\
34+
Usage: create-vite [OPTION]... [DIRECTORY]
35+
36+
Create a new Vite project in JavaScript or TypeScript.
37+
With no arguments, start the CLI in interactive mode.
38+
39+
Options:
40+
-t, --template NAME use a specific template
41+
42+
Available templates:
43+
${yellow ('vanilla-ts vanilla' )}
44+
${green ('vue-ts vue' )}
45+
${cyan ('react-ts react' )}
46+
${cyan ('react-swc-ts react-swc')}
47+
${magenta ('preact-ts preact' )}
48+
${lightRed ('lit-ts lit' )}
49+
${red ('svelte-ts svelte' )}
50+
${blue ('solid-ts solid' )}
51+
${lightBlue('qwik-ts qwik' )}`
52+
2853
type ColorFunc = (str: string | number) => string
2954
type Framework = {
3055
name: string
@@ -251,6 +276,12 @@ async function init() {
251276
const argTargetDir = formatTargetDir(argv._[0])
252277
const argTemplate = argv.template || argv.t
253278

279+
const help = argv.help
280+
if (help) {
281+
console.log(helpMessage)
282+
return
283+
}
284+
254285
let targetDir = argTargetDir || defaultTargetDir
255286
const getProjectName = () =>
256287
targetDir === '.' ? path.basename(path.resolve()) : targetDir

0 commit comments

Comments
 (0)