Skip to content

Commit dc8b454

Browse files
author
Guillaume Chau
committedApr 23, 2018
feat(ui): webpack dashboard 'open app' button
1 parent ad395a8 commit dc8b454

File tree

7 files changed

+89
-6
lines changed

7 files changed

+89
-6
lines changed
 

‎docs/plugin-dev-ui.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ module.exports = api => {
7070
}
7171
```
7272

73+
**⚠️ The files will be reloaded when feetching the plugin list in the 'Project plugins' view. To apply changes, click on the 'Project plugins' button in the navigation sidebar on the left.**
74+
7375
### Project configurations
7476

7577
![Configuration ui](./config-ui.png)
@@ -466,9 +468,14 @@ In the plugin `ui.js`:
466468
// Set or update
467469
api.setSharedData('my-variable', 'some-data')
468470
// Get
469-
api.getSharedData('my-variable')
471+
const sharedData = api.getSharedData('my-variable')
472+
if (sharedData) {
473+
console.log(sharedData.value)
474+
}
475+
// Remove
476+
api.removeSharedData('my-variable')
470477
// Namespaced versions
471-
const { setSharedData, getSharedData } = api.namespace('webpack-dashboard-')
478+
const { setSharedData, getSharedData, removeSharedData } = api.namespace('webpack-dashboard-')
472479
```
473480

474481
In the custom component:

‎packages/@vue/cli-service/lib/commands/serve.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ const {
22
info,
33
error,
44
hasYarn,
5-
openBrowser
5+
openBrowser,
6+
IpcMessenger
67
} = require('@vue/cli-shared-utils')
78

89
const defaults = {
@@ -121,6 +122,17 @@ module.exports = (api, options) => {
121122
openBrowser(urls.localUrlForBrowser)
122123
}
123124

125+
if (args.dashboard) {
126+
const ipc = new IpcMessenger()
127+
ipc.connect()
128+
ipc.send({
129+
vueServe: {
130+
url: urls.localUrlForBrowser
131+
}
132+
})
133+
ipc.disconnect()
134+
}
135+
124136
// resolve returned Promise
125137
// so other commands can do api.service.run('serve').then(...)
126138
resolve({

‎packages/@vue/cli-service/ui.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/* eslint-disable vue-libs/no-async-functions */
2+
const { openBrowser } = require('@vue/cli-shared-utils')
23

34
module.exports = api => {
4-
const { setSharedData, getSharedData } = api.namespace('webpack-dashboard-')
5+
const { setSharedData, getSharedData, removeSharedData, onAction } = api.namespace('webpack-dashboard-')
56

67
function resetSharedData (key) {
78
setSharedData(`${key}-status`, null)
@@ -90,12 +91,14 @@ module.exports = api => {
9091

9192
// Data
9293
resetSharedData('serve')
94+
removeSharedData('serve-url')
9395
},
9496
onRun: () => {
9597
api.ipcOn(onWebpackMessage)
9698
},
9799
onExit: () => {
98100
api.ipcOff(onWebpackMessage)
101+
removeSharedData('serve-url')
99102
},
100103
views: [
101104
{
@@ -202,4 +205,15 @@ module.exports = api => {
202205
id: 'vue-webpack',
203206
path: '@vue/cli-ui-addon-webpack/dist'
204207
})
208+
209+
api.ipcOn(({ data }) => {
210+
if (data.vueServe) {
211+
setSharedData('serve-url', data.vueServe.url)
212+
}
213+
})
214+
215+
onAction('open-app', () => {
216+
const url = getSharedData('serve-url')
217+
url && openBrowser(url.value)
218+
})
205219
}

‎packages/@vue/cli-ui-addon-webpack/src/components/WebpackDashboard.vue

+28-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@
33
<div class="pane-toolbar">
44
<VueIcon icon="dashboard"/>
55
<div class="title">Dashboard</div>
6+
7+
<template
8+
v-if="mode === 'serve'"
9+
>
10+
<VueButton
11+
icon-left="open_in_browser"
12+
label="Open app"
13+
:disabled="!serveUrl"
14+
@click="$callPluginAction('webpack-dashboard-open-app')"
15+
/>
16+
<VueIcon
17+
icon="lens"
18+
class="separator"
19+
/>
20+
</template>
621
<VueSwitch
722
v-model="useGzip"
823
>
@@ -50,6 +65,18 @@ export default {
5065
'TaskDetails'
5166
],
5267
68+
data () {
69+
return {
70+
mode: null
71+
}
72+
},
73+
74+
sharedData () {
75+
return {
76+
serveUrl: `webpack-dashboard-serve-url`
77+
}
78+
},
79+
5380
computed: {
5481
useGzip: {
5582
get () { return this.$store.getters.useGzip },
@@ -58,7 +85,7 @@ export default {
5885
},
5986
6087
created () {
61-
const mode = this.TaskDetails.task.command.indexOf('vue-cli-service serve') !== -1 ? 'serve' : 'build'
88+
const mode = this.mode = this.TaskDetails.task.command.indexOf('vue-cli-service serve') !== -1 ? 'serve' : 'build'
6289
this.$store.commit('mode', mode)
6390
this.$watchSharedData(`webpack-dashboard-${mode}-stats`, value => {
6491
this.$store.commit('stats', {

‎packages/@vue/cli-ui/src/graphql-api/api/PluginApi.js

+10
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,15 @@ class PluginApi {
211211
sharedData.set({ id, value }, this.context)
212212
}
213213

214+
/**
215+
* Delete a shared data.
216+
*
217+
* @param {string} id Id of the Shared data
218+
*/
219+
removeSharedData (id) {
220+
sharedData.remove(id, this.context)
221+
}
222+
214223
/**
215224
* Listener triggered when a Plugin action is called from a client addon component.
216225
*
@@ -252,6 +261,7 @@ class PluginApi {
252261
return {
253262
getSharedData: (id) => this.getSharedData(namespace + id),
254263
setSharedData: (id, value) => this.setSharedData(namespace + id, value),
264+
removeSharedData: (id) => this.removeSharedData(namespace + id),
255265
onAction: (id, cb) => this.onAction(namespace + id, cb),
256266
callAction: (id, params) => this.callAction(namespace + id, params)
257267
}

‎packages/@vue/cli-ui/src/graphql-api/connectors/shared-data.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,15 @@ function set ({ id, value }, context) {
2222
return { id, value }
2323
}
2424

25+
function remove (id, context) {
26+
sharedData.delete(id)
27+
context.pubsub.publish(channels.SHARED_DATA_UPDATED, {
28+
sharedDataUpdated: { id, value: undefined }
29+
})
30+
}
31+
2532
module.exports = {
2633
get,
27-
set
34+
set,
35+
remove
2836
}

‎packages/@vue/cli-ui/src/style/main.styl

+5
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,12 @@ ansi-colors('white', $vue-ui-color-light)
123123
width 0
124124
ellipsis()
125125

126+
> .vue-ui-switch,
127+
> .vue-ui-button:not(.icon-button)
128+
padding 0 8px
129+
126130
> .vue-ui-switch
131+
font-size 14px
127132
&:not(.selected)
128133
.wrapper
129134
background rgba($vue-ui-color-dark, .2)

0 commit comments

Comments
 (0)
Please sign in to comment.