Skip to content

Commit 570568a

Browse files
author
Guillaume Chau
committed
refactor: shared plugin prompts
1 parent 99b2cee commit 570568a

File tree

9 files changed

+141
-153
lines changed

9 files changed

+141
-153
lines changed
Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,12 @@
11
// these prompts are used if the plugin is late-installed into an existing
22
// project and invoked by `vue invoke`.
33

4-
const { chalk, hasGit } = require('@vue/cli-shared-utils')
4+
const {
5+
lintOn,
6+
eslintConfig
7+
} = require('@vue/cli-shared-utils/lib/pluginPrompts/eslint')
58

69
module.exports = [
7-
{
8-
name: 'config',
9-
type: 'list',
10-
message: `Pick an ESLint config:`,
11-
choices: [
12-
{
13-
name: 'Error prevention only',
14-
value: 'base',
15-
short: 'Basic'
16-
},
17-
{
18-
name: 'Airbnb',
19-
value: 'airbnb',
20-
short: 'Airbnb'
21-
},
22-
{
23-
name: 'Standard',
24-
value: 'standard',
25-
short: 'Standard'
26-
},
27-
{
28-
name: 'Prettier',
29-
value: 'prettier',
30-
short: 'Prettier'
31-
}
32-
]
33-
},
34-
{
35-
name: 'lintOn',
36-
type: 'checkbox',
37-
message: 'Pick additional lint features:',
38-
choices: [
39-
{
40-
name: 'Lint on save',
41-
value: 'save',
42-
checked: true
43-
},
44-
{
45-
name: 'Lint and fix on commit' + (hasGit() ? '' : chalk.red(' (requires Git)')),
46-
value: 'commit'
47-
}
48-
]
49-
}
10+
eslintConfig,
11+
lintOn
5012
]
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
// these prompts are used if the plugin is late-installed into an existing
22
// project and invoked by `vue invoke`.
33

4-
const { chalk } = require('@vue/cli-shared-utils')
4+
const {
5+
historyMode
6+
} = require('@vue/cli-shared-utils/lib/pluginPrompts/router')
57

68
module.exports = [
7-
{
8-
name: 'historyMode',
9-
type: 'confirm',
10-
message: `Use history mode for router? ${chalk.yellow(`(Requires proper server setup for index fallback in production)`)}`,
11-
description: `By using the HTML5 History API, the URLs don't need the '#' character anymore.`
12-
}
9+
historyMode
1310
]

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

Lines changed: 17 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,27 @@
11
// these prompts are used if the plugin is late-installed into an existing
22
// project and invoked by `vue invoke`.
33

4-
const { chalk, hasGit } = require('@vue/cli-shared-utils')
4+
const {
5+
lintOn
6+
} = require('@vue/cli-shared-utils/lib/pluginPrompts/eslint')
7+
const {
8+
classComponent,
9+
useTsWithBabel,
10+
useTsLint,
11+
convertJsToTs,
12+
allowJs
13+
} = require('@vue/cli-shared-utils/lib/pluginPrompts/typescript')
514

615
const prompts = module.exports = [
16+
classComponent,
17+
useTsWithBabel,
18+
useTsLint,
719
{
8-
name: `classComponent`,
9-
type: `confirm`,
10-
message: `Use class-style component syntax?`,
11-
default: true
20+
...lintOn,
21+
when: answers => answers.lint
1222
},
13-
{
14-
name: `useTsWithBabel`,
15-
type: `confirm`,
16-
message: 'Use Babel alongside TypeScript (required for modern mode, auto-detected polyfills, transpiling JSX)?'
17-
},
18-
{
19-
name: `lint`,
20-
type: `confirm`,
21-
message: `Use TSLint?`
22-
},
23-
{
24-
name: `lintOn`,
25-
type: `checkbox`,
26-
when: answers => answers.lint,
27-
message: `Pick lint features:`,
28-
choices: [
29-
{
30-
name: 'Lint on save',
31-
value: 'save',
32-
checked: true
33-
},
34-
{
35-
name: 'Lint and fix on commit' + (hasGit() ? '' : chalk.red(' (requires Git)')),
36-
value: 'commit'
37-
}
38-
]
39-
},
40-
{
41-
name: `convertJsToTs`,
42-
type: `confirm`,
43-
message: `Convert all .js files to .ts?`,
44-
default: true
45-
},
46-
{
47-
name: `allowJs`,
48-
type: `confirm`,
49-
message: `Allow .js files to be compiled?`,
50-
default: false
51-
}
23+
convertJsToTs,
24+
allowJs
5225
]
5326

5427
// in RC6+ the export can be function, but that would break invoke for RC5 and
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const chalk = require('chalk')
2+
const { hasGit } = require('../../')
3+
4+
exports.lintOn = {
5+
name: 'lintOn',
6+
message: 'Pick additional lint features:',
7+
type: 'checkbox',
8+
choices: [
9+
{
10+
name: 'Lint on save',
11+
value: 'save',
12+
checked: true
13+
},
14+
{
15+
name: 'Lint and fix on commit' + (hasGit() ? '' : chalk.red(' (requires Git)')),
16+
value: 'commit'
17+
}
18+
]
19+
}
20+
21+
exports.eslintConfig = {
22+
name: 'config',
23+
type: 'list',
24+
message: `Pick an ESLint config:`,
25+
description: 'Checking code errors and enforcing an homogeoneous code style is recommended.',
26+
choices: [
27+
{
28+
name: 'Error prevention only',
29+
value: 'base',
30+
short: 'Basic'
31+
},
32+
{
33+
name: 'Airbnb',
34+
value: 'airbnb',
35+
short: 'Airbnb'
36+
},
37+
{
38+
name: 'Standard',
39+
value: 'standard',
40+
short: 'Standard'
41+
},
42+
{
43+
name: 'Prettier',
44+
value: 'prettier',
45+
short: 'Prettier'
46+
}
47+
]
48+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const chalk = require('chalk')
2+
3+
exports.historyMode = {
4+
name: 'historyMode',
5+
type: 'confirm',
6+
message: `Use history mode for router? ${chalk.yellow(`(Requires proper server setup for index fallback in production)`)}`,
7+
description: `By using the HTML5 History API, the URLs don't need the '#' character anymore.`,
8+
link: 'https://router.vuejs.org/guide/essentials/history-mode.html'
9+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
exports.classComponent = {
2+
name: 'classComponent',
3+
type: 'confirm',
4+
message: 'Use class-style component syntax?',
5+
description: 'Use the @Component decorator on classes.',
6+
link: 'https://vuejs.org/v2/guide/typescript.html#Class-Style-Vue-Components',
7+
default: true
8+
}
9+
10+
exports.useTsWithBabel = {
11+
name: 'useTsWithBabel',
12+
type: 'confirm',
13+
message: 'Use Babel alongside TypeScript (required for modern mode, auto-detected polyfills, transpiling JSX)?',
14+
description: 'It will output ES2015 and delegate the rest to Babel for auto polyfill based on browser targets.'
15+
}
16+
17+
exports.useTsLint = {
18+
name: `lint`,
19+
type: `confirm`,
20+
message: `Use TSLint?`
21+
}
22+
23+
exports.convertJsToTs = {
24+
name: `convertJsToTs`,
25+
type: `confirm`,
26+
message: `Convert all .js files to .ts?`,
27+
default: true
28+
}
29+
30+
exports.allowJs = {
31+
name: `allowJs`,
32+
type: `confirm`,
33+
message: `Allow .js files to be compiled?`,
34+
default: false
35+
}

packages/@vue/cli-utils/lib/promptModules/linter.js

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module.exports = cli => {
2-
const chalk = require('chalk')
3-
const { hasGit } = require('@vue/cli-shared-utils')
2+
const {
3+
lintOn,
4+
eslintConfig
5+
} = require('@vue/cli-shared-utils/lib/pluginPrompts/eslint')
46

57
cli.injectFeature({
68
name: 'Linter / Formatter',
@@ -13,11 +15,9 @@ module.exports = cli => {
1315
})
1416

1517
cli.injectPrompt({
18+
...eslintConfig,
1619
name: 'eslintConfig',
1720
when: answers => answers.features.includes('linter'),
18-
type: 'list',
19-
message: 'Pick a linter / formatter config:',
20-
description: 'Checking code errors and enforcing an homogeoneous code style is recommended.',
2121
choices: answers => [
2222
...(
2323
answers.features.includes('ts')
@@ -28,45 +28,13 @@ module.exports = cli => {
2828
}]
2929
: []
3030
),
31-
{
32-
name: 'ESLint with error prevention only',
33-
value: 'base',
34-
short: 'Basic'
35-
},
36-
{
37-
name: 'ESLint + Airbnb config',
38-
value: 'airbnb',
39-
short: 'Airbnb'
40-
},
41-
{
42-
name: 'ESLint + Standard config',
43-
value: 'standard',
44-
short: 'Standard'
45-
},
46-
{
47-
name: 'ESLint + Prettier',
48-
value: 'prettier',
49-
short: 'Prettier'
50-
}
31+
...eslintConfig.choices
5132
]
5233
})
5334

5435
cli.injectPrompt({
55-
name: 'lintOn',
56-
message: 'Pick additional lint features:',
57-
when: answers => answers.features.includes('linter'),
58-
type: 'checkbox',
59-
choices: [
60-
{
61-
name: 'Lint on save',
62-
value: 'save',
63-
checked: true
64-
},
65-
{
66-
name: 'Lint and fix on commit' + (hasGit() ? '' : chalk.red(' (requires Git)')),
67-
value: 'commit'
68-
}
69-
]
36+
...lintOn,
37+
when: answers => answers.features.includes('linter')
7038
})
7139

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

packages/@vue/cli-utils/lib/promptModules/router.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
const chalk = require('chalk')
2-
31
module.exports = cli => {
2+
const {
3+
historyMode
4+
} = require('@vue/cli-shared-utils/lib/pluginPrompts/router')
5+
46
cli.injectFeature({
57
name: 'Router',
68
value: 'router',
@@ -9,12 +11,8 @@ module.exports = cli => {
911
})
1012

1113
cli.injectPrompt({
12-
name: 'historyMode',
13-
when: answers => answers.features.includes('router'),
14-
type: 'confirm',
15-
message: `Use history mode for router? ${chalk.yellow(`(Requires proper server setup for index fallback in production)`)}`,
16-
description: `By using the HTML5 History API, the URLs don't need the '#' character anymore.`,
17-
link: 'https://router.vuejs.org/guide/essentials/history-mode.html'
14+
...historyMode,
15+
when: answers => answers.features.includes('router')
1816
})
1917

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

packages/@vue/cli-utils/lib/promptModules/typescript.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
const {
2+
classComponent,
3+
useTsWithBabel
4+
} = require('@vue/cli-shared-utils/lib/pluginPrompts/typescript')
5+
16
module.exports = cli => {
27
cli.injectFeature({
38
name: 'TypeScript',
@@ -9,21 +14,14 @@ module.exports = cli => {
914
})
1015

1116
cli.injectPrompt({
17+
...classComponent,
1218
name: 'tsClassComponent',
13-
when: answers => answers.features.includes('ts'),
14-
type: 'confirm',
15-
message: 'Use class-style component syntax?',
16-
description: 'Use the @Component decorator on classes.',
17-
link: 'https://vuejs.org/v2/guide/typescript.html#Class-Style-Vue-Components',
18-
default: true
19+
when: answers => answers.features.includes('ts')
1920
})
2021

2122
cli.injectPrompt({
22-
name: 'useTsWithBabel',
23+
...useTsWithBabel,
2324
when: answers => answers.features.includes('ts'),
24-
type: 'confirm',
25-
message: 'Use Babel alongside TypeScript (required for modern mode, auto-detected polyfills, transpiling JSX)?',
26-
description: 'It will output ES2015 and delegate the rest to Babel for auto polyfill based on browser targets.',
2725
default: answers => answers.features.includes('babel')
2826
})
2927

0 commit comments

Comments
 (0)