1
- import { BuildContext , BuildState } from './util/interfaces' ;
1
+ import { BuildContext , BuildState , BuildUpdateMessage } from './util/interfaces' ;
2
2
import { BuildError } from './util/errors' ;
3
3
import { bundle , bundleUpdate } from './bundle' ;
4
4
import { clean } from './clean' ;
@@ -45,6 +45,8 @@ function buildProd(context: BuildContext) {
45
45
// sync empty the www/build directory
46
46
clean ( context ) ;
47
47
48
+ buildId ++ ;
49
+
48
50
// async tasks
49
51
// these can happen all while other tasks are running
50
52
const copyPromise = copy ( context ) ;
@@ -90,6 +92,8 @@ function buildDev(context: BuildContext) {
90
92
// sync empty the www/build directory
91
93
clean ( context ) ;
92
94
95
+ buildId ++ ;
96
+
93
97
// async tasks
94
98
// these can happen all while other tasks are running
95
99
const copyPromise = copy ( context ) ;
@@ -121,8 +125,13 @@ export function buildUpdate(event: string, filePath: string, context: BuildConte
121
125
return new Promise ( resolve => {
122
126
const logger = new Logger ( 'build' ) ;
123
127
124
- buildUpdateId ++ ;
125
- emit ( EventType . BuildUpdateStarted , buildUpdateId ) ;
128
+ buildId ++ ;
129
+
130
+ const buildUpdateMsg : BuildUpdateMessage = {
131
+ buildId : buildId ,
132
+ reloadApp : false
133
+ } ;
134
+ emit ( EventType . BuildUpdateStarted , buildUpdateMsg ) ;
126
135
127
136
function buildTasksDone ( resolveValue : BuildTaskResolveValue ) {
128
137
// all build tasks have been resolved or one of them
@@ -131,13 +140,13 @@ export function buildUpdate(event: string, filePath: string, context: BuildConte
131
140
parallelTasksPromise . then ( ( ) => {
132
141
// all parallel tasks are also done
133
142
// so now we're done done
134
- emit ( EventType . BuildUpdateCompleted , buildUpdateId ) ;
135
-
136
- if ( resolveValue . requiresRefresh ) {
137
- // emit that we need to do a full page refresh
138
- emit ( EventType . ReloadApp ) ;
143
+ const buildUpdateMsg : BuildUpdateMessage = {
144
+ buildId : buildId ,
145
+ reloadApp : resolveValue . requiresAppReload
146
+ } ;
147
+ emit ( EventType . BuildUpdateCompleted , buildUpdateMsg ) ;
139
148
140
- } else {
149
+ if ( ! resolveValue . requiresAppReload ) {
141
150
// just emit that only a certain file changed
142
151
// this one is useful when only a sass changed happened
143
152
// and the webpack only needs to livereload the css
@@ -169,7 +178,7 @@ export function buildUpdate(event: string, filePath: string, context: BuildConte
169
178
. then ( buildTasksDone )
170
179
. catch ( ( ) => {
171
180
buildTasksDone ( {
172
- requiresRefresh : false ,
181
+ requiresAppReload : false ,
173
182
changedFile : filePath
174
183
} ) ;
175
184
} ) ;
@@ -182,15 +191,15 @@ export function buildUpdate(event: string, filePath: string, context: BuildConte
182
191
*/
183
192
function buildUpdateTasks ( event : string , filePath : string , context : BuildContext ) {
184
193
const resolveValue : BuildTaskResolveValue = {
185
- requiresRefresh : false ,
194
+ requiresAppReload : false ,
186
195
changedFile : filePath
187
196
} ;
188
197
189
198
return Promise . resolve ( )
190
199
. then ( ( ) => {
191
200
// TEMPLATE
192
201
if ( context . templateState === BuildState . RequiresUpdate ) {
193
- resolveValue . requiresRefresh = true ;
202
+ resolveValue . requiresAppReload = true ;
194
203
return templateUpdate ( event , filePath , context ) ;
195
204
}
196
205
// no template updates required
@@ -200,15 +209,15 @@ function buildUpdateTasks(event: string, filePath: string, context: BuildContext
200
209
. then ( ( ) => {
201
210
// TRANSPILE
202
211
if ( context . transpileState === BuildState . RequiresUpdate ) {
203
- resolveValue . requiresRefresh = true ;
212
+ resolveValue . requiresAppReload = true ;
204
213
// we've already had a successful transpile once, only do an update
205
214
// not that we've also already started a transpile diagnostics only
206
215
// build that only needs to be completed by the end of buildUpdate
207
216
return transpileUpdate ( event , filePath , context ) ;
208
217
209
218
} else if ( context . transpileState === BuildState . RequiresBuild ) {
210
219
// run the whole transpile
211
- resolveValue . requiresRefresh = true ;
220
+ resolveValue . requiresAppReload = true ;
212
221
return transpile ( context ) ;
213
222
}
214
223
// no transpiling required
@@ -219,12 +228,12 @@ function buildUpdateTasks(event: string, filePath: string, context: BuildContext
219
228
// BUNDLE
220
229
if ( context . bundleState === BuildState . RequiresUpdate ) {
221
230
// we need to do a bundle update
222
- resolveValue . requiresRefresh = true ;
231
+ resolveValue . requiresAppReload = true ;
223
232
return bundleUpdate ( event , filePath , context ) ;
224
233
225
234
} else if ( context . bundleState === BuildState . RequiresBuild ) {
226
235
// we need to do a full bundle build
227
- resolveValue . requiresRefresh = true ;
236
+ resolveValue . requiresAppReload = true ;
228
237
return bundle ( context ) ;
229
238
}
230
239
// no bundling required
@@ -254,7 +263,7 @@ function buildUpdateTasks(event: string, filePath: string, context: BuildContext
254
263
}
255
264
256
265
interface BuildTaskResolveValue {
257
- requiresRefresh : boolean ;
266
+ requiresAppReload : boolean ;
258
267
changedFile : string ;
259
268
}
260
269
@@ -273,4 +282,4 @@ function buildUpdateParallelTasks(event: string, filePath: string, context: Buil
273
282
return Promise . all ( parallelTasks ) ;
274
283
}
275
284
276
- let buildUpdateId = 0 ;
285
+ let buildId = 0 ;
0 commit comments