mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-04-22 20:38:55 -05:00
feat(plugin-api): prompts.js can now export a function which receives package info
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
const { chalk, hasGit } = require('@vue/cli-shared-utils')
|
||||
|
||||
module.exports = [
|
||||
const prompts = module.exports = [
|
||||
{
|
||||
name: `classComponent`,
|
||||
type: `confirm`,
|
||||
@@ -38,3 +38,11 @@ module.exports = [
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
// in RC6+ the export can be function, but that would break invoke for RC5 and
|
||||
// below, so this is a temporary compatibility hack until we release stable.
|
||||
// TODO just export the function in 3.0.0
|
||||
module.exports.getPrompts = pkg => {
|
||||
prompts[2].when = () => !('@vue/cli-plugin-eslint' in (pkg.devDependencies || {}))
|
||||
return prompts
|
||||
}
|
||||
|
||||
@@ -84,8 +84,14 @@ async function invoke (pluginName, options = {}, context = process.cwd()) {
|
||||
// resolve options if no command line options are passed, and the plugin
|
||||
// contains a prompt module.
|
||||
if (!Object.keys(options).length) {
|
||||
const pluginPrompts = loadModule(`${id}/prompts`, context)
|
||||
let pluginPrompts = loadModule(`${id}/prompts`, context)
|
||||
if (pluginPrompts) {
|
||||
if (typeof pluginPrompts === 'function') {
|
||||
pluginPrompts = pluginPrompts(pkg)
|
||||
}
|
||||
if (typeof pluginPrompts.getPrompts === 'function') {
|
||||
pluginPrompts = pluginPrompts.getPrompts(pkg)
|
||||
}
|
||||
options = await inquirer.prompt(pluginPrompts)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user