1
1
'use strict' ;
2
2
3
- var asyncGenerator = function ( ) {
4
- function AwaitValue ( value ) {
5
- this . value = value ;
6
- }
7
-
8
- function AsyncGenerator ( gen ) {
9
- var front , back ;
10
-
11
- function send ( key , arg ) {
12
- return new Promise ( function ( resolve , reject ) {
13
- var request = {
14
- key : key ,
15
- arg : arg ,
16
- resolve : resolve ,
17
- reject : reject ,
18
- next : null
19
- } ;
20
-
21
- if ( back ) {
22
- back = back . next = request ;
23
- } else {
24
- front = back = request ;
25
- resume ( key , arg ) ;
26
- }
27
- } ) ;
28
- }
29
-
30
- function resume ( key , arg ) {
31
- try {
32
- var result = gen [ key ] ( arg ) ;
33
- var value = result . value ;
34
-
35
- if ( value instanceof AwaitValue ) {
36
- Promise . resolve ( value . value ) . then ( function ( arg ) {
37
- resume ( "next" , arg ) ;
38
- } , function ( arg ) {
39
- resume ( "throw" , arg ) ;
40
- } ) ;
41
- } else {
42
- settle ( result . done ? "return" : "normal" , result . value ) ;
43
- }
44
- } catch ( err ) {
45
- settle ( "throw" , err ) ;
46
- }
47
- }
48
-
49
- function settle ( type , value ) {
50
- switch ( type ) {
51
- case "return" :
52
- front . resolve ( {
53
- value : value ,
54
- done : true
55
- } ) ;
56
- break ;
57
-
58
- case "throw" :
59
- front . reject ( value ) ;
60
- break ;
61
-
62
- default :
63
- front . resolve ( {
64
- value : value ,
65
- done : false
66
- } ) ;
67
- break ;
68
- }
69
-
70
- front = front . next ;
71
-
72
- if ( front ) {
73
- resume ( front . key , front . arg ) ;
74
- } else {
75
- back = null ;
76
- }
77
- }
78
-
79
- this . _invoke = send ;
80
-
81
- if ( typeof gen . return !== "function" ) {
82
- this . return = undefined ;
83
- }
84
- }
85
-
86
- if ( typeof Symbol === "function" && Symbol . asyncIterator ) {
87
- AsyncGenerator . prototype [ Symbol . asyncIterator ] = function ( ) {
88
- return this ;
89
- } ;
90
- }
91
-
92
- AsyncGenerator . prototype . next = function ( arg ) {
93
- return this . _invoke ( "next" , arg ) ;
94
- } ;
95
-
96
- AsyncGenerator . prototype . throw = function ( arg ) {
97
- return this . _invoke ( "throw" , arg ) ;
98
- } ;
99
-
100
- AsyncGenerator . prototype . return = function ( arg ) {
101
- return this . _invoke ( "return" , arg ) ;
102
- } ;
103
-
104
- return {
105
- wrap : function ( fn ) {
106
- return function ( ) {
107
- return new AsyncGenerator ( fn . apply ( this , arguments ) ) ;
108
- } ;
109
- } ,
110
- await : function ( value ) {
111
- return new AwaitValue ( value ) ;
112
- }
113
- } ;
114
- } ( ) ;
115
-
116
- var classCallCheck = function ( instance , Constructor ) {
117
- if ( ! ( instance instanceof Constructor ) ) {
118
- throw new TypeError ( "Cannot call a class as a function" ) ;
119
- }
120
- } ;
121
-
122
- var createClass = function ( ) {
123
- function defineProperties ( target , props ) {
124
- for ( var i = 0 ; i < props . length ; i ++ ) {
125
- var descriptor = props [ i ] ;
126
- descriptor . enumerable = descriptor . enumerable || false ;
127
- descriptor . configurable = true ;
128
- if ( "value" in descriptor ) descriptor . writable = true ;
129
- Object . defineProperty ( target , descriptor . key , descriptor ) ;
130
- }
131
- }
132
-
133
- return function ( Constructor , protoProps , staticProps ) {
134
- if ( protoProps ) defineProperties ( Constructor . prototype , protoProps ) ;
135
- if ( staticProps ) defineProperties ( Constructor , staticProps ) ;
136
- return Constructor ;
137
- } ;
138
- } ( ) ;
3
+ function _interopDefault ( ex ) { return ( ex && ( typeof ex === 'object' ) && 'default' in ex ) ? ex [ 'default' ] : ex ; }
139
4
140
- var toArray = function ( arr ) {
141
- return Array . isArray ( arr ) ? arr : Array . from ( arr ) ;
142
- } ;
5
+ var _getIterator = _interopDefault ( require ( 'babel-runtime/core-js/get-iterator' ) ) ;
6
+ var _regeneratorRuntime = _interopDefault ( require ( 'babel-runtime/regenerator' ) ) ;
7
+ var _Promise = _interopDefault ( require ( 'babel-runtime/core-js/promise' ) ) ;
8
+ var _asyncToGenerator = _interopDefault ( require ( 'babel-runtime/helpers/asyncToGenerator' ) ) ;
9
+ var _toArray = _interopDefault ( require ( 'babel-runtime/helpers/toArray' ) ) ;
10
+ var _classCallCheck = _interopDefault ( require ( 'babel-runtime/helpers/classCallCheck' ) ) ;
11
+ var _createClass = _interopDefault ( require ( 'babel-runtime/helpers/createClass' ) ) ;
12
+ var child_process = require ( 'child_process' ) ;
143
13
144
- var spawn = require ( 'child_process' ) . spawn ;
145
- var exec = require ( 'child_process' ) . exec ;
146
14
var os = require ( 'os' ) ;
147
15
148
16
var defaultOptions = {
@@ -151,17 +19,22 @@ var defaultOptions = {
151
19
onBuildExit : [ ] ,
152
20
dev : true ,
153
21
verbose : false ,
154
- safe : false
22
+ safe : false ,
23
+ sync : false
155
24
} ;
156
25
157
26
var WebpackShellPlugin = function ( ) {
158
27
function WebpackShellPlugin ( options ) {
159
- classCallCheck ( this , WebpackShellPlugin ) ;
28
+ _classCallCheck ( this , WebpackShellPlugin ) ;
160
29
161
30
this . options = this . validateInput ( this . mergeOptions ( options , defaultOptions ) ) ;
31
+
32
+ this . onCompilation = this . onCompilation . bind ( this ) ;
33
+ this . onAfterEmit = this . onAfterEmit . bind ( this ) ;
34
+ this . onDone = this . onDone . bind ( this ) ;
162
35
}
163
36
164
- createClass ( WebpackShellPlugin , [ {
37
+ _createClass ( WebpackShellPlugin , [ {
165
38
key : 'puts' ,
166
39
value : function puts ( error , stdout , stderr ) {
167
40
if ( error ) {
@@ -179,7 +52,7 @@ var WebpackShellPlugin = function () {
179
52
value : function serializeScript ( script ) {
180
53
if ( typeof script === 'string' ) {
181
54
var _script$split = script . split ( ' ' ) ,
182
- _script$split2 = toArray ( _script$split ) ,
55
+ _script$split2 = _toArray ( _script$split ) ,
183
56
_command = _script$split2 [ 0 ] ,
184
57
_args = _script$split2 . slice ( 1 ) ;
185
58
@@ -190,18 +63,83 @@ var WebpackShellPlugin = function () {
190
63
191
64
return { command : command , args : args } ;
192
65
}
66
+ } , {
67
+ key : 'sleep' ,
68
+ value : function ( ) {
69
+ var _ref = _asyncToGenerator ( /*#__PURE__*/ _regeneratorRuntime . mark ( function _callee ( ms ) {
70
+ return _regeneratorRuntime . wrap ( function _callee$ ( _context ) {
71
+ while ( 1 ) {
72
+ switch ( _context . prev = _context . next ) {
73
+ case 0 :
74
+ return _context . abrupt ( 'return' , new _Promise ( function ( resolve ) {
75
+ return setTimeout ( resolve , ms ) ;
76
+ } ) ) ;
77
+
78
+ case 1 :
79
+ case 'end' :
80
+ return _context . stop ( ) ;
81
+ }
82
+ }
83
+ } , _callee , this ) ;
84
+ } ) ) ;
85
+
86
+ function sleep ( _x ) {
87
+ return _ref . apply ( this , arguments ) ;
88
+ }
89
+
90
+ return sleep ;
91
+ } ( )
193
92
} , {
194
93
key : 'handleScript' ,
195
94
value : function handleScript ( script ) {
95
+ var proc = null ;
96
+
196
97
if ( os . platform ( ) === 'win32' || this . options . safe ) {
197
- this . spreadStdoutAndStdErr ( exec ( script , this . puts ) ) ;
98
+ if ( this . options . sync ) {
99
+ proc = child_process . execSync ( script , { stdio : [ 0 , 1 , 2 ] } ) ;
100
+ } else {
101
+ proc = child_process . exec ( script , this . puts ) ;
102
+ this . spreadStdoutAndStdErr ( proc ) ;
103
+ }
198
104
} else {
199
105
var _serializeScript = this . serializeScript ( script ) ,
200
106
command = _serializeScript . command ,
201
107
args = _serializeScript . args ;
202
108
203
- var proc = spawn ( command , args , { stdio : 'inherit' } ) ;
204
- proc . on ( 'close' , this . puts ) ;
109
+ if ( this . options . sync ) {
110
+ proc = child_process . spawnSync ( command , args , { stdio : 'inherit' } ) ;
111
+ } else {
112
+ proc = child_process . spawn ( command , args , { stdio : 'inherit' } ) ;
113
+ proc . on ( 'close' , this . puts ) ;
114
+ }
115
+ }
116
+ }
117
+ } , {
118
+ key : 'handleScriptsOn' ,
119
+ value : function handleScriptsOn ( data ) {
120
+ var _iteratorNormalCompletion = true ;
121
+ var _didIteratorError = false ;
122
+ var _iteratorError = undefined ;
123
+
124
+ try {
125
+ for ( var _iterator = _getIterator ( data ) , _step ; ! ( _iteratorNormalCompletion = ( _step = _iterator . next ( ) ) . done ) ; _iteratorNormalCompletion = true ) {
126
+ var item = _step . value ;
127
+
128
+ this . handleScript ( item ) ;
129
+ }
130
+ } catch ( err ) {
131
+ _didIteratorError = true ;
132
+ _iteratorError = err ;
133
+ } finally {
134
+ try {
135
+ if ( ! _iteratorNormalCompletion && _iterator . return ) {
136
+ _iterator . return ( ) ;
137
+ }
138
+ } finally {
139
+ if ( _didIteratorError ) {
140
+ throw _iteratorError ;
141
+ }
142
+ }
205
143
}
206
144
}
207
145
} , {
@@ -231,48 +169,48 @@ var WebpackShellPlugin = function () {
231
169
} , {
232
170
key : 'apply' ,
233
171
value : function apply ( compiler ) {
234
- var _this = this ;
235
-
236
- compiler . plugin ( 'compilation' , function ( compilation ) {
237
- if ( _this . options . verbose ) {
238
- console . log ( 'Report compilation: ' + compilation ) ;
239
- console . warn ( 'WebpackShellPlugin [' + new Date ( ) + ']: Verbose is being deprecated, please remove.' ) ;
240
- }
241
- if ( _this . options . onBuildStart . length ) {
242
- 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 = [ ] ;
248
- }
249
- }
250
- } ) ;
251
-
252
- compiler . plugin ( 'after-emit' , function ( compilation , callback ) {
253
- if ( _this . options . onBuildEnd . length ) {
254
- 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 = [ ] ;
260
- }
172
+ compiler . plugin ( 'compilation' , this . onCompilation ) ;
173
+ compiler . plugin ( 'after-emit' , this . onAfterEmit ) ;
174
+ compiler . plugin ( 'done' , this . onDone ) ;
175
+ }
176
+ } , {
177
+ key : 'onCompilation' ,
178
+ value : function onCompilation ( compilation ) {
179
+ if ( this . options . verbose ) {
180
+ console . log ( 'Report compilation: ' + compilation ) ;
181
+ console . warn ( 'WebpackShellPlugin [' + new Date ( ) + ']: Verbose is being deprecated, please remove.' ) ;
182
+ }
183
+ if ( this . options . onBuildStart . length ) {
184
+ console . log ( 'Executing pre-build scripts' ) ;
185
+ this . handleScriptsOn ( this . options . onBuildStart ) ;
186
+ if ( this . options . dev ) {
187
+ this . options . onBuildStart = [ ] ;
261
188
}
262
- callback ( ) ;
263
- } ) ;
264
-
265
- compiler . plugin ( 'done' , function ( ) {
266
- if ( _this . options . onBuildExit . length ) {
267
- 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 ] ) ;
270
- }
189
+ }
190
+ }
191
+ } , {
192
+ key : 'onAfterEmit' ,
193
+ value : function onAfterEmit ( compilation , callback ) {
194
+ if ( this . options . onBuildEnd . length ) {
195
+ console . log ( 'Executing post-build scripts' ) ;
196
+ this . handleScriptsOn ( this . options . onBuildEnd ) ;
197
+ if ( this . options . dev ) {
198
+ this . options . onBuildEnd = [ ] ;
271
199
}
272
- } ) ;
200
+ }
201
+ callback ( ) ;
202
+ }
203
+ } , {
204
+ key : 'onDone' ,
205
+ value : function onDone ( ) {
206
+ if ( this . options . onBuildExit . length ) {
207
+ console . log ( 'Executing additional scripts before exit' ) ;
208
+ this . handleScriptsOn ( this . options . onBuildExit ) ;
209
+ }
273
210
}
274
211
} ] ) ;
212
+
275
213
return WebpackShellPlugin ;
276
214
} ( ) ;
277
215
278
- module . exports = WebpackShellPlugin ;
216
+ module . exports = WebpackShellPlugin ;
0 commit comments