feat(ui): pwa open vue config/manifest suggestions

This commit is contained in:
Guillaume Chau
2018-06-11 21:13:41 +02:00
parent a26669c25f
commit e57e74926a
3 changed files with 69 additions and 2 deletions
+2 -1
View File
@@ -22,7 +22,8 @@
"access": "public"
},
"dependencies": {
"workbox-webpack-plugin": "^3.2.0"
"workbox-webpack-plugin": "^3.2.0",
"launch-editor": "^2.2.1"
},
"devDependencies": {
"register-service-worker": "^1.0.0"
+59 -1
View File
@@ -1,7 +1,9 @@
module.exports = api => {
const CONFIG = 'pwa'
// Config file
api.describeConfig({
id: 'pwa',
id: CONFIG,
name: 'PWA',
description: 'pwa.config.pwa.description',
link: 'https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-pwa#configuration',
@@ -110,4 +112,60 @@ module.exports = api => {
}
}
})
const OPEN_VUE = 'vue-pwa-open-vue'
const OPEN_MANIFEST = 'vue-pwa-open-manifest'
api.onViewOpen(({ view }) => {
if (view.id !== 'vue-project-configurations') {
removeSuggestions()
}
})
api.onConfigRead(({ config }) => {
if (config.id === CONFIG) {
if (config.foundFiles.vue) {
api.addSuggestion({
id: OPEN_VUE,
type: 'action',
label: 'pwa.suggestions.open-vue.label',
handler () {
const file = config.foundFiles.vue.path
console.log('open', file)
const launch = require('launch-editor')
launch(file)
return {
keep: true
}
}
})
} else {
api.removeSuggestion(OPEN_VUE)
}
if (config.foundFiles.manifest) {
api.addSuggestion({
id: OPEN_MANIFEST,
type: 'action',
label: 'pwa.suggestions.open-manifest.label',
handler () {
const file = config.foundFiles.manifest.path
console.log('open', file)
const launch = require('launch-editor')
launch(file)
return {
keep: true
}
}
})
} else {
api.removeSuggestion(OPEN_MANIFEST)
}
} else {
removeSuggestions()
}
})
function removeSuggestions () {
[OPEN_VUE, OPEN_MANIFEST].forEach(id => api.removeSuggestion(id))
}
}
+8
View File
@@ -497,6 +497,14 @@
"description": "Style for the web app status bar on iOS"
}
}
},
"suggestions": {
"open-vue": {
"label": "Open vue config"
},
"open-manifest": {
"label": "Open manifest"
}
}
},
"cypress": {