Skip to content

Commit

Permalink
feat(ui): pwa open vue config/manifest suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Chau committed Jun 11, 2018
1 parent a26669c commit e57e749
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/@vue/cli-plugin-pwa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
60 changes: 59 additions & 1 deletion packages/@vue/cli-plugin-pwa/ui.js
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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 changes: 8 additions & 0 deletions packages/@vue/cli-ui/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit e57e749

Please sign in to comment.