diff --git a/packages/@vue/cli-plugin-pwa/package.json b/packages/@vue/cli-plugin-pwa/package.json index f68e86a7b3..5183769426 100644 --- a/packages/@vue/cli-plugin-pwa/package.json +++ b/packages/@vue/cli-plugin-pwa/package.json @@ -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" diff --git a/packages/@vue/cli-plugin-pwa/ui.js b/packages/@vue/cli-plugin-pwa/ui.js index e9792af5ef..b6ed347dd9 100644 --- a/packages/@vue/cli-plugin-pwa/ui.js +++ b/packages/@vue/cli-plugin-pwa/ui.js @@ -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)) + } } diff --git a/packages/@vue/cli-ui/locales/en.json b/packages/@vue/cli-ui/locales/en.json index d771a2625e..715c60c0c9 100644 --- a/packages/@vue/cli-ui/locales/en.json +++ b/packages/@vue/cli-ui/locales/en.json @@ -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": {