Skip to content

Commit e33b04c

Browse files
committed
feat(plugin-api): prompts.js can now export a function which receives package info
1 parent ba4d0f2 commit e33b04c

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

packages/@vue/cli-plugin-typescript/prompts.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
const { chalk, hasGit } = require('@vue/cli-shared-utils')
55

6-
module.exports = [
6+
const prompts = module.exports = [
77
{
88
name: `classComponent`,
99
type: `confirm`,
@@ -38,3 +38,11 @@ module.exports = [
3838
]
3939
}
4040
]
41+
42+
// in RC6+ the export can be function, but that would break invoke for RC5 and
43+
// below, so this is a temporary compatibility hack until we release stable.
44+
// TODO just export the function in 3.0.0
45+
module.exports.getPrompts = pkg => {
46+
prompts[2].when = () => !('@vue/cli-plugin-eslint' in (pkg.devDependencies || {}))
47+
return prompts
48+
}

packages/@vue/cli/lib/invoke.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,14 @@ async function invoke (pluginName, options = {}, context = process.cwd()) {
8484
// resolve options if no command line options are passed, and the plugin
8585
// contains a prompt module.
8686
if (!Object.keys(options).length) {
87-
const pluginPrompts = loadModule(`${id}/prompts`, context)
87+
let pluginPrompts = loadModule(`${id}/prompts`, context)
8888
if (pluginPrompts) {
89+
if (typeof pluginPrompts === 'function') {
90+
pluginPrompts = pluginPrompts(pkg)
91+
}
92+
if (typeof pluginPrompts.getPrompts === 'function') {
93+
pluginPrompts = pluginPrompts.getPrompts(pkg)
94+
}
8995
options = await inquirer.prompt(pluginPrompts)
9096
}
9197
}

0 commit comments

Comments
 (0)