Skip to content

Commit c8c0ebd

Browse files
Merge pull request #22 from vuejs/dev
input field still free flow value for display
2 parents f81fcf9 + 500dc50 commit c8c0ebd

File tree

1 file changed

+51
-2
lines changed

1 file changed

+51
-2
lines changed

docs/dev-guide/plugin-dev.md

+51-2
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ A generator should export a function which receives three arguments:
102102

103103
And if the user creates a project using the `foo` preset, then the generator of `@vue/cli-plugin-foo` will receive `{ option: 'bar' }` as its second argument.
104104

105-
For a 3rd party plugin, the options will be resolved from the prompts or command line arguments when the user executes `vue invoke` (see [Prompts for 3rd party plugins](#prompts-for-3rd-party-plugins)).
105+
For a 3rd party plugin, the options will be resolved from the prompts or command line arguments when the user executes `vue invoke` (see [Prompts](#prompts)).
106106

107107
3. The entire preset (`presets.foo`) will be passed as the third argument.
108108

@@ -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)