@@ -151,7 +151,8 @@ var defaultOptions = {
151
151
onBuildExit : [ ] ,
152
152
dev : true ,
153
153
verbose : false ,
154
- safe : false
154
+ safe : false ,
155
+ sync : false
155
156
} ;
156
157
157
158
var WebpackShellPlugin = function ( ) {
@@ -192,17 +193,42 @@ var WebpackShellPlugin = function () {
192
193
}
193
194
} , {
194
195
key : 'handleScript' ,
195
- value : function handleScript ( script ) {
196
+ value : function handleScript ( script , next ) {
197
+ var proc = null ;
196
198
if ( os . platform ( ) === 'win32' || this . options . safe ) {
197
- this . spreadStdoutAndStdErr ( exec ( script , this . puts ) ) ;
199
+ proc = exec ( script , this . puts ) ;
200
+ this . spreadStdoutAndStdErr ( proc ) ;
198
201
} else {
199
202
var _serializeScript = this . serializeScript ( script ) ,
200
203
command = _serializeScript . command ,
201
204
args = _serializeScript . args ;
202
205
203
- var proc = spawn ( command , args , { stdio : 'inherit' } ) ;
206
+ proc = spawn ( command , args , { stdio : 'inherit' } ) ;
204
207
proc . on ( 'close' , this . puts ) ;
205
208
}
209
+
210
+ if ( this . options . sync ) {
211
+ proc . on ( 'close' , next ) ;
212
+ } else {
213
+ next ( ) ;
214
+ }
215
+ }
216
+ } , {
217
+ key : 'handleScriptsOn' ,
218
+ value : function handleScriptsOn ( data ) {
219
+ var _this = this ;
220
+
221
+ var next = function next ( inbound ) {
222
+ if ( inbound . length > 0 ) {
223
+ var head = inbound [ 0 ] ;
224
+ var tail = inbound . slice ( 1 ) ;
225
+
226
+ _this . handleScript ( head , function ( ) {
227
+ next ( tail ) ;
228
+ } ) ;
229
+ }
230
+ } ;
231
+ next ( data ) ;
206
232
}
207
233
} , {
208
234
key : 'validateInput' ,
@@ -231,42 +257,38 @@ var WebpackShellPlugin = function () {
231
257
} , {
232
258
key : 'apply' ,
233
259
value : function apply ( compiler ) {
234
- var _this = this ;
260
+ var _this2 = this ;
235
261
236
262
compiler . plugin ( 'compilation' , function ( compilation ) {
237
- if ( _this . options . verbose ) {
263
+ if ( _this2 . options . verbose ) {
238
264
console . log ( 'Report compilation: ' + compilation ) ;
239
265
console . warn ( 'WebpackShellPlugin [' + new Date ( ) + ']: Verbose is being deprecated, please remove.' ) ;
240
266
}
241
- if ( _this . options . onBuildStart . length ) {
267
+ if ( _this2 . options . onBuildStart . length ) {
242
268
console . log ( 'Executing pre-build scripts' ) ;
243
- for ( var i = 0 ; i < _this . options . onBuildStart . length ; i ++ ) {
244
- _this . handleScript ( _this . options . onBuildStart [ i ] ) ;
245
- }
246
- if ( _this . options . dev ) {
247
- _this . options . onBuildStart = [ ] ;
269
+ _this2 . handleScriptsOn ( _this2 . options . onBuildStart ) ;
270
+ if ( _this2 . options . dev ) {
271
+ _this2 . options . onBuildStart = [ ] ;
248
272
}
249
273
}
250
274
} ) ;
251
275
252
276
compiler . plugin ( 'after-emit' , function ( compilation , callback ) {
253
- if ( _this . options . onBuildEnd . length ) {
277
+ if ( _this2 . options . onBuildEnd . length ) {
254
278
console . log ( 'Executing post-build scripts' ) ;
255
- for ( var i = 0 ; i < _this . options . onBuildEnd . length ; i ++ ) {
256
- _this . handleScript ( _this . options . onBuildEnd [ i ] ) ;
257
- }
258
- if ( _this . options . dev ) {
259
- _this . options . onBuildEnd = [ ] ;
279
+ _this2 . handleScriptsOn ( _this2 . options . onBuildEnd ) ;
280
+ if ( _this2 . options . dev ) {
281
+ _this2 . options . onBuildEnd = [ ] ;
260
282
}
261
283
}
262
284
callback ( ) ;
263
285
} ) ;
264
286
265
287
compiler . plugin ( 'done' , function ( ) {
266
- if ( _this . options . onBuildExit . length ) {
288
+ if ( _this2 . options . onBuildExit . length ) {
267
289
console . log ( 'Executing additional scripts before exit' ) ;
268
- for ( var i = 0 ; i < _this . options . onBuildExit . length ; i ++ ) {
269
- _this . handleScript ( _this . options . onBuildExit [ i ] ) ;
290
+ for ( var i = 0 ; i < _this2 . options . onBuildExit . length ; i ++ ) {
291
+ _this2 . handleScript ( _this2 . options . onBuildExit [ i ] ) ;
270
292
}
271
293
}
272
294
} ) ;
0 commit comments