Skip to content

Commit 500dc50

Browse files
kazuponhaoqunjiang
authored andcommitted
docs: add more explanation at prompts (#3924)
1 parent 5f879c4 commit 500dc50

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

docs/dev-guide/plugin-dev.md

+50-1
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,56 @@ This is because the command's expected mode needs to be known before loading env
430430

431431
Prompts are required to handle user choices when creating a new project or adding a new plugin to the existing one. All prompts logic is stored inside the `prompts.js` file. The prompts are presented using [inquirer](https://github.com/SBoudrias/Inquirer.js) under the hood.
432432

433-
When user initialize the plugin by calling `vue invoke`, if the plugin contains a `prompts.js` in its root directory, it will be used during invocation. The file should export an array of [Questions](https://github.com/SBoudrias/Inquirer.js#question) that will be handled by Inquirer.js. The resolved answers object will be passed to the plugin's generator as options.
433+
When user initialize the plugin by calling `vue invoke`, if the plugin contains a `prompts.js` in its root directory, it will be used during invocation. The file should export an array of [Questions](https://github.com/SBoudrias/Inquirer.js#question) that will be handled by Inquirer.js.
434+
435+
You should export directly array of questions, or export function that return those.
436+
437+
e.g. directly array of questions:
438+
```js
439+
// prompts.js
440+
441+
module.exports = [
442+
{
443+
type: 'input',
444+
name: 'locale',
445+
message: 'The locale of project localization.',
446+
validate: input => !!input,
447+
default: 'en'
448+
},
449+
// ...
450+
]
451+
```
452+
453+
e.g. function that return array of questions:
454+
```js
455+
// prompts.js
456+
457+
// pass `package.json` of project to function argument
458+
module.exports = pkg => {
459+
const prompts = [
460+
{
461+
type: 'input',
462+
name: 'locale',
463+
message: 'The locale of project localization.',
464+
validate: input => !!input,
465+
default: 'en'
466+
}
467+
]
468+
469+
// add dynamically propmpt
470+
if ('@vue/cli-plugin-eslint' in (pkg.devDependencies || {})) {
471+
prompts.push({
472+
type: 'confirm',
473+
name: 'useESLintPluginVueI18n',
474+
message: 'Use ESLint plugin for Vue I18n ?'
475+
})
476+
}
477+
478+
return prompts
479+
}
480+
```
481+
482+
The resolved answers object will be passed to the plugin's generator as options.
434483

435484
Alternatively, the user can skip the prompts and directly initialize the plugin by passing options via the command line, e.g.:
436485

0 commit comments

Comments
 (0)