Skip to content

Commit 0e838a0

Browse files
committed
feat: add vue version choice to creator prompt
1 parent e1ca9c7 commit 0e838a0

File tree

4 files changed

+44
-12
lines changed

4 files changed

+44
-12
lines changed

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

+26-4
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ module.exports = class Creator extends EventEmitter {
5151

5252
this.name = name
5353
this.context = process.env.VUE_CLI_CONTEXT = context
54-
const { presetPrompt, featurePrompt } = this.resolveIntroPrompts()
54+
const { vueVersionPrompt, presetPrompt, featurePrompt } = this.resolveIntroPrompts()
55+
this.vueVersionPrompt = vueVersionPrompt
5556
this.presetPrompt = presetPrompt
5657
this.featurePrompt = featurePrompt
5758
this.outroPrompts = this.resolveOutroPrompts()
@@ -307,6 +308,8 @@ module.exports = class Creator extends EventEmitter {
307308
this.promptCompleteCbs.forEach(cb => cb(answers, preset))
308309
}
309310

311+
preset.vueVersion = answers.vueVersion
312+
310313
// validate
311314
validatePreset(preset)
312315

@@ -398,10 +401,11 @@ module.exports = class Creator extends EventEmitter {
398401

399402
resolveIntroPrompts () {
400403
const presets = this.getPresets()
401-
const presetChoices = Object.keys(presets).map(name => {
404+
const presetChoices = Object.entries(presets).map(([name, preset]) => {
402405
return {
403-
name: `${name} (${formatFeatures(presets[name])})`,
404-
value: name
406+
name: `${name} (${formatFeatures(name, preset)})`,
407+
value: name,
408+
when: (answers) => !preset.vueVersion || preset.vueVersion === answers.vueVersion
405409
}
406410
})
407411
const presetPrompt = {
@@ -416,6 +420,22 @@ module.exports = class Creator extends EventEmitter {
416420
}
417421
]
418422
}
423+
const vueVersionPrompt = {
424+
when: answers => answers.preset === 'default',
425+
name: 'vueVersion',
426+
type: 'list',
427+
message: `Choose a version of Vue.js that you want to start the project with`,
428+
choices: [
429+
{
430+
name: '2.x',
431+
value: '2'
432+
},
433+
{
434+
name: '3.x (preview)',
435+
value: '3'
436+
}
437+
]
438+
}
419439
const featurePrompt = {
420440
name: 'features',
421441
when: isManualMode,
@@ -425,6 +445,7 @@ module.exports = class Creator extends EventEmitter {
425445
pageSize: 10
426446
}
427447
return {
448+
vueVersionPrompt,
428449
presetPrompt,
429450
featurePrompt
430451
}
@@ -511,6 +532,7 @@ module.exports = class Creator extends EventEmitter {
511532
})
512533
const prompts = [
513534
this.presetPrompt,
535+
this.vueVersionPrompt,
514536
this.featurePrompt,
515537
...this.injectedPrompts,
516538
...this.outroPrompts

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

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const { createSchema, validate } = require('@vue/cli-shared-utils/lib/validate')
88
const rcPath = exports.rcPath = getRcPath('.vuerc')
99

1010
const presetSchema = createSchema(joi => joi.object().keys({
11+
vueVersion: joi.string().only(['2', '3']),
1112
bare: joi.boolean(),
1213
useConfigFiles: joi.boolean(),
1314
// TODO: Use warn for router and vuex once @hapi/joi v16 releases

packages/@vue/cli/lib/promptModules/vueVersion.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
module.exports = cli => {
2-
cli.injectPrompt({
3-
name: 'vueVersion',
2+
cli.injectFeature({
3+
name: 'Choose Vue version',
4+
value: 'vueVersion',
5+
description: 'Choose a version of Vue.js that you want to start the project with',
46
type: 'list',
5-
message: `Choose a version of Vue.js that you want to start the project with`,
67
choices: [
78
{
89
name: '2.x',
@@ -12,7 +13,8 @@ module.exports = cli => {
1213
name: '3.x (preview)',
1314
value: '3'
1415
}
15-
]
16+
],
17+
checked: true
1618
})
1719

1820
cli.onPromptComplete((answers, options) => {

packages/@vue/cli/lib/util/features.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,17 @@ exports.getFeatures = (preset) => {
1818
return features
1919
}
2020

21-
exports.formatFeatures = (preset, lead, joiner) => {
21+
exports.formatFeatures = (name, preset) => {
22+
let versionInfo = ''
23+
if (preset.vueVersion) {
24+
versionInfo = chalk.yellow(`[Vue ${preset.vueVersion}] `)
25+
} else if (name !== 'default') { // default preset is Vue version-agnositic
26+
versionInfo = chalk.yellow('[Vue 2] ')
27+
}
28+
2229
const features = exports.getFeatures(preset)
23-
return features.map(dep => {
30+
return versionInfo + features.map(dep => {
2431
dep = toShortPluginId(dep)
25-
return `${lead || ''}${chalk.yellow(dep)}`
26-
}).join(joiner || ', ')
32+
return chalk.yellow(dep)
33+
}).join(', ')
2734
}

0 commit comments

Comments
 (0)