Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3d89338

Browse filesBrowse files
authored
feat: add --help and --version options (#646)
* feat: add `--help` and `--version` options * chore: update descriptions for feature flags [skip ci]
1 parent d5a0ea3 commit 3d89338
Copy full SHA for 3d89338

File tree

2 files changed

+72
-27
lines changed
Filter options

2 files changed

+72
-27
lines changed

‎README.md

Copy file name to clipboardExpand all lines: README.md
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ npm create vue@latest
1717
> [!NOTE]
1818
> (`@latest` or `@legacy`) MUST NOT be omitted, otherwise `npm` may resolve to a cached and outdated version of the package.
1919
20-
Or, if you need to support IE11, you can create a Vue 2 project with:
20+
By default the command will run in interactive mode, but you can also provide feature flags in the CLI arguments to skip the prompts. Run `npm create vue@latest --help` to see all available options.
21+
22+
If you need to support IE11, you can create a Vue 2 project with:
2123

2224
```sh
2325
npm create vue@legacy

‎index.ts

Copy file name to clipboardExpand all lines: index.ts
+69-26Lines changed: 69 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as path from 'node:path'
66
import { parseArgs } from 'node:util'
77

88
import prompts from 'prompts'
9-
import { red, green, bold } from 'kleur/colors'
9+
import { red, green, cyan, bold } from 'kleur/colors'
1010

1111
import ejs from 'ejs'
1212

@@ -20,6 +20,8 @@ import getLanguage from './utils/getLanguage'
2020
import renderEslint from './utils/renderEslint'
2121
import trimBoilerplate from './utils/trimBoilerplate'
2222

23+
import cliPackageJson from './package.json'
24+
2325
function isValidPackageName(projectName) {
2426
return /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(projectName)
2527
}
@@ -61,33 +63,56 @@ function emptyDir(dir) {
6163
)
6264
}
6365

64-
async function init() {
65-
console.log()
66-
console.log(
67-
process.stdout.isTTY && process.stdout.getColorDepth() > 8
68-
? banners.gradientBanner
69-
: banners.defaultBanner,
70-
)
71-
console.log()
66+
const helpMessage = `\
67+
Usage: create-vue [FEATURE_FLGAS...] [OPTIONS...] [DIRECTORY]
68+
69+
Create a new Vue.js project.
70+
Start the CLI in interactive mode when no FEATURE_FLAGS is provided, or if the DIRECTORY argument is not a valid package name.
71+
72+
Options:
73+
--force
74+
Create the project even if the directory is not empty.
75+
--bare
76+
Create a barebone project without example code.
77+
--help
78+
Display this help message.
79+
--version
80+
Display the version number of this CLI.
81+
82+
Available feature flags:
83+
--default
84+
Create a project with the default configuration without any additional features.
85+
--ts, --typescript
86+
Add TypeScript support.
87+
--jsx
88+
Add JSX support.
89+
--router, --vue-router
90+
Add Vue Router for SPA development.
91+
--pinia
92+
Add Pinia for state management.
93+
--vitest
94+
Add Vitest for unit testing.
95+
--cypress
96+
Add Cypress for end-to-end testing.
97+
If used without ${cyan('--vitest')}, it will also add Cypress Component Testing.
98+
--playwright
99+
Add Playwright for end-to-end testing.
100+
--nightwatch
101+
Add Nightwatch for end-to-end testing.
102+
If used without ${cyan('--vitest')}, it will also add Nightwatch Component Testing.
103+
--eslint
104+
Add ESLint for code quality.
105+
--eslint-with-prettier
106+
Add Prettier for code formatting in addition to ESLint.
107+
108+
Unstable feature flags:
109+
--tests, --with-tests
110+
Add both unit testing and end-to-end testing support.
111+
Currently equivalent to ${cyan('--vitest --cypress')}, but may change in the future.
112+
`
72113

114+
async function init() {
73115
const cwd = process.cwd()
74-
// possible options:
75-
// --default
76-
// --typescript / --ts
77-
// --jsx
78-
// --router / --vue-router
79-
// --pinia
80-
// --with-tests / --tests (equals to `--vitest --cypress`)
81-
// --vitest
82-
// --cypress
83-
// --nightwatch
84-
// --playwright
85-
// --eslint
86-
// --eslint-with-prettier (only support prettier through eslint for simplicity)
87-
// in addition to the feature flags, you can also pass the following options:
88-
// --bare (for a barebone template without example code)
89-
// --force (for force overwriting without confirming)
90-
91116
const args = process.argv.slice(2)
92117

93118
// alias is not supported by parseArgs
@@ -106,6 +131,16 @@ async function init() {
106131
strict: false,
107132
})
108133

134+
if (argv.help) {
135+
console.log(helpMessage)
136+
process.exit(0)
137+
}
138+
139+
if (argv.version) {
140+
console.log(`${cliPackageJson.name} v${cliPackageJson.version}`)
141+
process.exit(0)
142+
}
143+
109144
// if any of the feature flags is set, we would skip the feature prompts
110145
const isFeatureFlagsUsed =
111146
typeof (
@@ -145,6 +180,14 @@ async function init() {
145180
needsPrettier?: boolean
146181
} = {}
147182

183+
console.log()
184+
console.log(
185+
process.stdout.isTTY && process.stdout.getColorDepth() > 8
186+
? banners.gradientBanner
187+
: banners.defaultBanner,
188+
)
189+
console.log()
190+
148191
try {
149192
// Prompts:
150193
// - Project name:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.