From 005d010193b5bdf9cadf4210c1445f82a4fd4994 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Thu, 2 May 2019 00:59:23 +0900 Subject: [PATCH 1/2] docs: add more explanation at prompts --- docs/dev-guide/plugin-dev.md | 51 +++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/docs/dev-guide/plugin-dev.md b/docs/dev-guide/plugin-dev.md index 7197ae559d..f22ce75c3e 100644 --- a/docs/dev-guide/plugin-dev.md +++ b/docs/dev-guide/plugin-dev.md @@ -430,7 +430,56 @@ This is because the command's expected mode needs to be known before loading env 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. -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. +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. + +You should export directly array of questions, or export function that return those. + +e.g. directly array of questions: +```js +// prompts.js + +module.exports = [ + { + type: 'input', + name: 'locale', + message: 'The locale of project localization.', + validate: input => !!input, + default: 'en' + }, + // ... +] +``` + +e.g. function that return array of questions: +```js +// prompts.js + +// pass `package.json` of project to function argument +module.exports = pkg => { + const prompts = [ + { + type: 'input', + name: 'locale', + message: 'The locale of project localization.', + validate: input => !!input, + default: 'en' + } + ] + + // add dynamically propmpt + if ('@vue/cli-plugin-eslint' in (pkg.devDependencies || {})) { + prompts.push({ + type: 'confirm', + name: 'useESLintPluginVueI18n', + message: 'ESLint plugin for Vue I18n ?' + }) + } + + return prompts +} +``` + +The resolved answers object will be passed to the plugin's generator as options. Alternatively, the user can skip the prompts and directly initialize the plugin by passing options via the command line, e.g.: From bec8936fe1024d9cf52b24051d42b44ea1da2512 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Thu, 2 May 2019 01:05:37 +0900 Subject: [PATCH 2/2] docs: tweak --- docs/dev-guide/plugin-dev.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/dev-guide/plugin-dev.md b/docs/dev-guide/plugin-dev.md index f22ce75c3e..d505ad1693 100644 --- a/docs/dev-guide/plugin-dev.md +++ b/docs/dev-guide/plugin-dev.md @@ -471,7 +471,7 @@ module.exports = pkg => { prompts.push({ type: 'confirm', name: 'useESLintPluginVueI18n', - message: 'ESLint plugin for Vue I18n ?' + message: 'Use ESLint plugin for Vue I18n ?' }) }