Skip to content

Commit 2eac8ff

Browse files
author
Guillaume Chau
committed
feat(ui): PWA config + ESLint extra config
1 parent ae552a9 commit 2eac8ff

File tree

6 files changed

+191
-6
lines changed

6 files changed

+191
-6
lines changed

docs/plugin-dev-ui.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ Use the `onRead` hook to return a list of prompts to be displayed for the config
127127
```js
128128
api.describeConfig({
129129
/* ... */
130-
onRead: ({ data }) => ({
130+
onRead: ({ data, cwd }) => ({
131131
prompts: [
132132
// Prompt objects
133133
]
@@ -156,7 +156,7 @@ Use the `onWrite` hook to write the data to the configuration file (or execute a
156156
```js
157157
api.describeConfig({
158158
/* ... */
159-
onWrite: ({ prompts, answers, data, file, api }) => {
159+
onWrite: ({ prompts, answers, data, file, cwd, api }) => {
160160
// ...
161161
}
162162
})
@@ -168,6 +168,7 @@ Arguments:
168168
- `answers`: answers data from the user inputs
169169
- `data`: read-only initial data read from the file
170170
- `file`: descriptor of the found file (`{ type: 'json', path: '...' }`)
171+
- `cwd`: current working directory
171172
- `api`: onWrite API
172173

173174
Prompts runtime objects:

packages/@vue/cli-plugin-eslint/ui.js

+33-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = api => {
66
id: 'eslintrc',
77
name: 'ESLint configuration',
88
description: 'eslint.config.eslint.description',
9-
link: 'https://eslint.org',
9+
link: 'https://github.com/vuejs/eslint-plugin-vue',
1010
icon: '.eslintrc.json',
1111
files: {
1212
json: ['.eslintrc', '.eslintrc.json'],
@@ -178,10 +178,41 @@ module.exports = api => {
178178
}
179179
})
180180

181+
api.describeConfig({
182+
id: 'eslintrc-config',
183+
name: 'ESLint extra',
184+
description: 'eslint.config.eslint-extra.description',
185+
link: 'https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint#configuration',
186+
icon: '.eslintrc.json',
187+
files: {
188+
js: ['vue.config.js']
189+
},
190+
onRead: ({ data }) => ({
191+
prompts: [
192+
{
193+
name: 'lintOnSave',
194+
type: 'confirm',
195+
message: 'Lint on save',
196+
description: 'Automatically lint source files when saved',
197+
link: 'https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint#configuration',
198+
default: false,
199+
value: data.lintOnSave
200+
}
201+
]
202+
}),
203+
onWrite: async ({ api, prompts }) => {
204+
const result = {}
205+
for (const prompt of prompts) {
206+
result[prompt.id] = await api.getAnswer(prompt.id)
207+
}
208+
api.setData(result)
209+
}
210+
})
211+
181212
// Tasks
182213
api.describeTask({
183214
match: /vue-cli-service lint/,
184-
description: 'Lints and fixes files',
215+
description: 'eslint.tasks.lint.description',
185216
link: 'https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint#injected-commands',
186217
prompts: [
187218
{

packages/@vue/cli-plugin-pwa/ui.js

+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/* eslint-disable vue-libs/no-async-functions */
2+
const path = require('path')
3+
const fs = require('fs')
4+
5+
function readAppManifest (cwd) {
6+
const manifestPath = path.join(cwd, 'public/manifest.json')
7+
if (fs.existsSync(manifestPath)) {
8+
try {
9+
return JSON.parse(fs.readFileSync(manifestPath, { encoding: 'utf8' }))
10+
} catch (e) {
11+
console.log(`Can't read JSON in ${manifestPath}`)
12+
}
13+
}
14+
}
15+
16+
function updateAppManifest (cwd, handler) {
17+
const manifestPath = path.join(cwd, 'public/manifest.json')
18+
if (fs.existsSync(manifestPath)) {
19+
try {
20+
const manifest = JSON.parse(fs.readFileSync(manifestPath, { encoding: 'utf8' }))
21+
handler(manifest)
22+
fs.writeFileSync(manifestPath, JSON.stringify(manifest), { encoding: 'utf8' })
23+
} catch (e) {
24+
console.log(`Can't update JSON in ${manifestPath}`)
25+
}
26+
}
27+
}
28+
29+
module.exports = api => {
30+
// Config file
31+
api.describeConfig({
32+
id: 'pwa',
33+
name: 'PWA',
34+
description: 'pwa.config.pwa.description',
35+
link: 'https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-pwa#configuration',
36+
icon: 'mobile.xm',
37+
files: {
38+
js: ['vue.config.js']
39+
},
40+
onRead: ({ data, cwd }) => {
41+
const manifest = readAppManifest(cwd)
42+
return {
43+
prompts: [
44+
{
45+
name: 'workboxPluginMode',
46+
type: 'list',
47+
message: 'Plugin mode',
48+
description: 'This allows you to the choose between the two modes supported by the underlying `workbox-webpack-plugin`',
49+
link: 'https://developers.google.com/web/tools/workbox/modules/workbox-webpack-plugin#which_plugin_to_use',
50+
default: 'GenerateSW',
51+
value: data.pwa && data.pwa.workboxPluginMode,
52+
choices: [
53+
{
54+
name: 'GenerateSW',
55+
value: 'GenerateSW'
56+
},
57+
{
58+
name: 'InjectManifest',
59+
value: 'InjectManifest'
60+
}
61+
]
62+
},
63+
{
64+
name: 'name',
65+
type: 'input',
66+
message: 'App name',
67+
description: 'Used as the value for the `apple-mobile-web-app-title` meta tag in the generated HTML.',
68+
value: data.pwa && data.pwa.name
69+
},
70+
{
71+
name: 'themeColor',
72+
type: 'input',
73+
message: 'Theme color',
74+
description: 'Color used to theme the browser',
75+
default: '#4DBA87',
76+
value: data.pwa && data.pwa.themeColor
77+
},
78+
{
79+
name: 'backgroundColor',
80+
type: 'input',
81+
message: 'Splash background color',
82+
description: 'Background color used for the app splash screen',
83+
default: '#000000',
84+
value: manifest && manifest.background_color,
85+
skipSave: true
86+
},
87+
{
88+
name: 'msTileColor',
89+
type: 'input',
90+
message: 'Windows app tile color',
91+
description: 'Color used for the app tile on Windows',
92+
default: '#000000',
93+
value: data.pwa && data.pwa.msTileColor
94+
},
95+
{
96+
name: 'appleMobileWebAppStatusBarStyle',
97+
type: 'input',
98+
message: 'Apple mobile status bar style',
99+
description: 'Style for the web app status bar on iOS',
100+
default: 'default',
101+
value: data.pwa && data.pwa.appleMobileWebAppStatusBarStyle
102+
}
103+
]
104+
}
105+
},
106+
onWrite: async ({ api, prompts, cwd }) => {
107+
const result = {}
108+
for (const prompt of prompts.filter(p => !p.raw.skipSave)) {
109+
result[`pwa.${prompt.id}`] = await api.getAnswer(prompt.id)
110+
}
111+
api.setData(result)
112+
113+
// Update app manifest
114+
115+
const name = result['pwa.name']
116+
if (name) {
117+
updateAppManifest(cwd, manifest => {
118+
manifest.name = name
119+
manifest.short_name = name
120+
})
121+
}
122+
123+
const themeColor = result['pwa.themeColor']
124+
if (themeColor) {
125+
updateAppManifest(cwd, manifest => {
126+
manifest.theme_color = themeColor
127+
})
128+
}
129+
130+
const backgroundColor = await api.getAnswer('backgroundColor')
131+
if (backgroundColor) {
132+
updateAppManifest(cwd, manifest => {
133+
manifest.background_color = backgroundColor
134+
})
135+
}
136+
}
137+
})
138+
}

packages/@vue/cli-ui/src/graphql-api/connectors/configurations.js

+2
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ async function getPrompts (id, context) {
109109
data
110110
}
111111
const configData = await config.onRead({
112+
cwd: cwd.get(),
112113
data
113114
})
114115
await prompts.reset()
@@ -134,6 +135,7 @@ async function save (id, context) {
134135
answers,
135136
data: current.data,
136137
file: config.file,
138+
cwd: cwd.get(),
137139
api: {
138140
assignData: newData => {
139141
changedFields.push(...Object.keys(newData))

packages/@vue/cli-ui/vue.config.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
module.exports = {
2-
lintOnSave: false,
3-
42
pluginOptions: {
53
graphqlMock: false,
64
apolloEngine: false,

packages/@vue/cli/locales/en.json

+15
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,21 @@
375375
"strongly-recommended": "Strongly recommended",
376376
"recommended": "Recommended"
377377
}
378+
},
379+
"eslint-extra": {
380+
"description": "Extra ESLint settings"
381+
}
382+
},
383+
"tasks": {
384+
"lint": {
385+
"description": "Lints and fixes files"
386+
}
387+
}
388+
},
389+
"pwa": {
390+
"config": {
391+
"pwa": {
392+
"description": "Progressive Web App"
378393
}
379394
}
380395
}

0 commit comments

Comments
 (0)