@@ -151,7 +151,8 @@ var defaultOptions = {
151151 onBuildExit : [ ] ,
152152 dev : true ,
153153 verbose : false ,
154- safe : false
154+ safe : false ,
155+ sync : false
155156} ;
156157
157158var WebpackShellPlugin = function ( ) {
@@ -192,17 +193,42 @@ var WebpackShellPlugin = function () {
192193 }
193194 } , {
194195 key : 'handleScript' ,
195- value : function handleScript ( script ) {
196+ value : function handleScript ( script , next ) {
197+ var proc = null ;
196198 if ( os . platform ( ) === 'win32' || this . options . safe ) {
197- this . spreadStdoutAndStdErr ( exec ( script , this . puts ) ) ;
199+ proc = exec ( script , this . puts ) ;
200+ this . spreadStdoutAndStdErr ( proc ) ;
198201 } else {
199202 var _serializeScript = this . serializeScript ( script ) ,
200203 command = _serializeScript . command ,
201204 args = _serializeScript . args ;
202205
203- var proc = spawn ( command , args , { stdio : 'inherit' } ) ;
206+ proc = spawn ( command , args , { stdio : 'inherit' } ) ;
204207 proc . on ( 'close' , this . puts ) ;
205208 }
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 ) ;
206232 }
207233 } , {
208234 key : 'validateInput' ,
@@ -231,42 +257,38 @@ var WebpackShellPlugin = function () {
231257 } , {
232258 key : 'apply' ,
233259 value : function apply ( compiler ) {
234- var _this = this ;
260+ var _this2 = this ;
235261
236262 compiler . plugin ( 'compilation' , function ( compilation ) {
237- if ( _this . options . verbose ) {
263+ if ( _this2 . options . verbose ) {
238264 console . log ( 'Report compilation: ' + compilation ) ;
239265 console . warn ( 'WebpackShellPlugin [' + new Date ( ) + ']: Verbose is being deprecated, please remove.' ) ;
240266 }
241- if ( _this . options . onBuildStart . length ) {
267+ if ( _this2 . options . onBuildStart . length ) {
242268 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 = [ ] ;
248272 }
249273 }
250274 } ) ;
251275
252276 compiler . plugin ( 'after-emit' , function ( compilation , callback ) {
253- if ( _this . options . onBuildEnd . length ) {
277+ if ( _this2 . options . onBuildEnd . length ) {
254278 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 = [ ] ;
260282 }
261283 }
262284 callback ( ) ;
263285 } ) ;
264286
265287 compiler . plugin ( 'done' , function ( ) {
266- if ( _this . options . onBuildExit . length ) {
288+ if ( _this2 . options . onBuildExit . length ) {
267289 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 ] ) ;
270292 }
271293 }
272294 } ) ;
0 commit comments