|
1 |
| -const path = require('path') |
2 |
| -const fs = require('fs-extra') |
3 | 1 | const prompts = require('./uiOptions')
|
4 | 2 |
|
5 | 3 | module.exports = api => {
|
6 |
| - const { setSharedData, removeSharedData } = api.namespace( |
7 |
| - 'webpack-dashboard-' |
8 |
| - ) |
9 |
| - |
10 |
| - let firstRun = true |
11 |
| - let hadFailed = false |
12 |
| - let modernMode = false |
13 |
| - |
14 |
| - // For webpack dashboard |
15 |
| - function resetSharedData (key) { |
16 |
| - setSharedData(`${key}-status`, null) |
17 |
| - setSharedData(`${key}-progress`, 0) |
18 |
| - setSharedData(`${key}-operations`, null) |
19 |
| - setSharedData(`${key}-stats`, null) |
20 |
| - setSharedData(`${key}-sizes`, null) |
21 |
| - setSharedData(`${key}-problems`, null) |
22 |
| - } |
23 |
| - |
24 |
| - // For webpack dashboard |
25 |
| - async function onWebpackMessage ({ data: message }) { |
26 |
| - if (message.webpackDashboardData) { |
27 |
| - const type = message.webpackDashboardData.type |
28 |
| - for (const data of message.webpackDashboardData.value) { |
29 |
| - if (data.type === 'stats') { |
30 |
| - // Stats are read from a file |
31 |
| - const statsFile = path.resolve( |
32 |
| - process.cwd(), |
33 |
| - `./node_modules/.stats-${type}.json` |
34 |
| - ) |
35 |
| - const value = await fs.readJson(statsFile) |
36 |
| - setSharedData(`${type}-${data.type}`, value) |
37 |
| - await fs.remove(statsFile) |
38 |
| - } else if ( |
39 |
| - type.indexOf('build') !== -1 && |
40 |
| - modernMode && |
41 |
| - data.type === 'progress' |
42 |
| - ) { |
43 |
| - // Progress is shared between 'build' and 'build-modern' |
44 |
| - // 'build' first and then 'build-modern' |
45 |
| - const value = type === 'build' ? data.value / 2 : (data.value + 1) / 2 |
46 |
| - // We display the same progress bar for both |
47 |
| - for (const t of ['build', 'build-modern']) { |
48 |
| - setSharedData(`${t}-${data.type}`, value) |
49 |
| - } |
50 |
| - } else { |
51 |
| - setSharedData(`${type}-${data.type}`, data.value) |
52 |
| - |
53 |
| - // Notifications |
54 |
| - if (type === 'serve' && data.type === 'status') { |
55 |
| - if (data.value === 'Failed') { |
56 |
| - api.notify({ |
57 |
| - title: 'Build failed', |
58 |
| - message: 'The build has errors.', |
59 |
| - icon: 'error' |
60 |
| - }) |
61 |
| - hadFailed = true |
62 |
| - } else if (data.value === 'Success') { |
63 |
| - if (hadFailed) { |
64 |
| - api.notify({ |
65 |
| - title: 'Build fixed', |
66 |
| - message: 'The build succeeded.', |
67 |
| - icon: 'done' |
68 |
| - }) |
69 |
| - hadFailed = false |
70 |
| - } else if (firstRun) { |
71 |
| - api.notify({ |
72 |
| - title: 'App ready', |
73 |
| - message: 'The build succeeded.', |
74 |
| - icon: 'done' |
75 |
| - }) |
76 |
| - firstRun = false |
77 |
| - } |
78 |
| - } |
79 |
| - } |
80 |
| - } |
81 |
| - } |
82 |
| - } |
83 |
| - } |
84 |
| - |
85 | 4 | api.describeTask({
|
86 | 5 | match: /vue-cli-service electron:build/,
|
87 | 6 | description: 'Build your app for production with electron-builder',
|
@@ -115,65 +34,11 @@ module.exports = api => {
|
115 | 34 | answers.archs.forEach(a => {
|
116 | 35 | args.push(`--${a}`)
|
117 | 36 | })
|
118 |
| - // Webpack dashboard |
119 |
| - setSharedData('modern-mode', (modernMode = !!answers.modern)) |
120 |
| - // Tell renderer build to send status to dashboard |
121 |
| - args.push('--dashboard') |
122 |
| - // Data |
123 |
| - resetSharedData('build') |
124 |
| - resetSharedData('build-modern') |
125 |
| - }, |
126 |
| - onRun: () => { |
127 |
| - api.ipcOn(onWebpackMessage) |
128 |
| - }, |
129 |
| - onExit: () => { |
130 |
| - api.ipcOff(onWebpackMessage) |
131 |
| - }, |
132 |
| - views: [ |
133 |
| - { |
134 |
| - id: 'vue-webpack-dashboard', |
135 |
| - label: 'vue-webpack.dashboard.title', |
136 |
| - icon: 'dashboard', |
137 |
| - component: 'vue-webpack-dashboard' |
138 |
| - }, |
139 |
| - { |
140 |
| - id: 'vue-webpack-analyzer', |
141 |
| - label: 'vue-webpack.analyzer.title', |
142 |
| - icon: 'donut_large', |
143 |
| - component: 'vue-webpack-analyzer' |
144 |
| - } |
145 |
| - ], |
146 |
| - defaultView: 'vue-webpack-dashboard' |
| 37 | + } |
147 | 38 | })
|
148 | 39 | api.describeTask({
|
149 | 40 | match: /vue-cli-service electron:serve/,
|
150 | 41 | description: 'Serve your app, launch electron',
|
151 |
| - link: 'https://nklayman.github.io/vue-cli-plugin-electron-builder/', |
152 |
| - onBeforeRun: ({ answers, args }) => { |
153 |
| - // Tell dev server to send status to dashboard |
154 |
| - args.push('--dashboard') |
155 |
| - |
156 |
| - // Data |
157 |
| - resetSharedData('serve') |
158 |
| - removeSharedData('serve-url') |
159 |
| - firstRun = true |
160 |
| - hadFailed = false |
161 |
| - }, |
162 |
| - onRun: () => { |
163 |
| - api.ipcOn(onWebpackMessage) |
164 |
| - }, |
165 |
| - onExit: () => { |
166 |
| - api.ipcOff(onWebpackMessage) |
167 |
| - removeSharedData('serve-url') |
168 |
| - }, |
169 |
| - views: [ |
170 |
| - { |
171 |
| - id: 'vue-webpack-dashboard', |
172 |
| - label: 'vue-webpack.dashboard.title', |
173 |
| - icon: 'dashboard', |
174 |
| - component: 'vue-webpack-dashboard' |
175 |
| - } |
176 |
| - ], |
177 |
| - defaultView: 'vue-webpack-dashboard' |
| 42 | + link: 'https://nklayman.github.io/vue-cli-plugin-electron-builder/' |
178 | 43 | })
|
179 | 44 | }
|
0 commit comments