Skip to content

Commit e57e749

Browse files
author
Guillaume Chau
committed
feat(ui): pwa open vue config/manifest suggestions
1 parent a26669c commit e57e749

File tree

3 files changed

+69
-2
lines changed

3 files changed

+69
-2
lines changed

packages/@vue/cli-plugin-pwa/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"access": "public"
2323
},
2424
"dependencies": {
25-
"workbox-webpack-plugin": "^3.2.0"
25+
"workbox-webpack-plugin": "^3.2.0",
26+
"launch-editor": "^2.2.1"
2627
},
2728
"devDependencies": {
2829
"register-service-worker": "^1.0.0"

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

+59-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
module.exports = api => {
2+
const CONFIG = 'pwa'
3+
24
// Config file
35
api.describeConfig({
4-
id: 'pwa',
6+
id: CONFIG,
57
name: 'PWA',
68
description: 'pwa.config.pwa.description',
79
link: 'https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-pwa#configuration',
@@ -110,4 +112,60 @@ module.exports = api => {
110112
}
111113
}
112114
})
115+
116+
const OPEN_VUE = 'vue-pwa-open-vue'
117+
const OPEN_MANIFEST = 'vue-pwa-open-manifest'
118+
119+
api.onViewOpen(({ view }) => {
120+
if (view.id !== 'vue-project-configurations') {
121+
removeSuggestions()
122+
}
123+
})
124+
125+
api.onConfigRead(({ config }) => {
126+
if (config.id === CONFIG) {
127+
if (config.foundFiles.vue) {
128+
api.addSuggestion({
129+
id: OPEN_VUE,
130+
type: 'action',
131+
label: 'pwa.suggestions.open-vue.label',
132+
handler () {
133+
const file = config.foundFiles.vue.path
134+
console.log('open', file)
135+
const launch = require('launch-editor')
136+
launch(file)
137+
return {
138+
keep: true
139+
}
140+
}
141+
})
142+
} else {
143+
api.removeSuggestion(OPEN_VUE)
144+
}
145+
if (config.foundFiles.manifest) {
146+
api.addSuggestion({
147+
id: OPEN_MANIFEST,
148+
type: 'action',
149+
label: 'pwa.suggestions.open-manifest.label',
150+
handler () {
151+
const file = config.foundFiles.manifest.path
152+
console.log('open', file)
153+
const launch = require('launch-editor')
154+
launch(file)
155+
return {
156+
keep: true
157+
}
158+
}
159+
})
160+
} else {
161+
api.removeSuggestion(OPEN_MANIFEST)
162+
}
163+
} else {
164+
removeSuggestions()
165+
}
166+
})
167+
168+
function removeSuggestions () {
169+
[OPEN_VUE, OPEN_MANIFEST].forEach(id => api.removeSuggestion(id))
170+
}
113171
}

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

+8
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,14 @@
497497
"description": "Style for the web app status bar on iOS"
498498
}
499499
}
500+
},
501+
"suggestions": {
502+
"open-vue": {
503+
"label": "Open vue config"
504+
},
505+
"open-manifest": {
506+
"label": "Open manifest"
507+
}
500508
}
501509
},
502510
"cypress": {

0 commit comments

Comments
 (0)