11'use strict' ;
22
3- const exec = require ( 'child_process' ) . exec ;
4- const defaultOptions = {
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+ } ( ) ;
139+
140+ var exec = require ( 'child_process' ) . exec ;
141+ var defaultOptions = {
5142 onBuildStart : [ ] ,
6143 onBuildEnd : [ ] ,
7144 onBuildExit : [ ] ,
@@ -41,70 +178,77 @@ function validateInput(options) {
41178}
42179
43180function mergeOptions ( options , defaults ) {
44- for ( const key in defaults ) {
181+ for ( var key in defaults ) {
45182 if ( options . hasOwnProperty ( key ) ) {
46183 defaults [ key ] = options [ key ] ;
47184 }
48185 }
49186 return defaults ;
50187}
51188
52- class WebpackShellPlugin {
53- constructor ( options ) {
189+ var WebpackShellPlugin = function ( ) {
190+ function WebpackShellPlugin ( options ) {
191+ classCallCheck ( this , WebpackShellPlugin ) ;
192+
54193 this . options = validateInput ( mergeOptions ( options , defaultOptions ) ) ;
55194 }
56195
57- apply ( compiler ) {
196+ createClass ( WebpackShellPlugin , [ {
197+ key : 'apply' ,
198+ value : function apply ( compiler ) {
199+ var _this = this ;
58200
59- compiler . plugin ( 'compilation' , compilation => {
60- if ( this . options . verbose ) {
61- console . log ( `Report compilation: ${ compilation } ` ) ;
62- }
63- if ( this . options . onBuildStart . length ) {
64- console . log ( 'Executing pre-build scripts' ) ;
65- this . options . onBuildStart . forEach ( script => {
66- if ( this . options . throwOnExecError ) {
67- spreadStdoutAndStdErr ( exec ( script , putsThrow ) ) ;
68- } else {
69- spreadStdoutAndStdErr ( exec ( script , puts ) ) ;
70- }
71- } ) ;
72- if ( this . options . dev ) {
73- this . options . onBuildStart = [ ] ;
201+ compiler . plugin ( 'compilation' , function ( compilation ) {
202+ if ( _this . options . verbose ) {
203+ console . log ( 'Report compilation: ' + compilation ) ;
74204 }
75- }
76- } ) ;
77-
78- compiler . plugin ( 'emit' , ( compilation , callback ) => {
79- if ( this . options . onBuildEnd . length ) {
80- console . log ( 'Executing post-build scripts' ) ;
81- this . options . onBuildEnd . forEach ( script => {
82- if ( this . options . throwOnExecError ) {
83- spreadStdoutAndStdErr ( exec ( script , putsThrow ) ) ;
84- } else {
85- spreadStdoutAndStdErr ( exec ( script , puts ) ) ;
205+ if ( _this . options . onBuildStart . length ) {
206+ console . log ( 'Executing pre-build scripts' ) ;
207+ _this . options . onBuildStart . forEach ( function ( script ) {
208+ if ( _this . options . throwOnExecError ) {
209+ spreadStdoutAndStdErr ( exec ( script , putsThrow ) ) ;
210+ } else {
211+ spreadStdoutAndStdErr ( exec ( script , puts ) ) ;
212+ }
213+ } ) ;
214+ if ( _this . options . dev ) {
215+ _this . options . onBuildStart = [ ] ;
86216 }
87- } ) ;
88- if ( this . options . dev ) {
89- this . options . onBuildEnd = [ ] ;
90217 }
91- }
92- callback ( ) ;
93- } ) ;
94-
95- compiler . plugin ( 'done' , ( ) => {
96- if ( this . options . onBuildExit . length ) {
97- console . log ( 'Executing additional scripts before exit' ) ;
98- this . options . onBuildExit . forEach ( script => {
99- if ( this . options . throwOnExecError ) {
100- spreadStdoutAndStdErr ( exec ( script , putsThrow ) ) ;
101- } else {
102- spreadStdoutAndStdErr ( exec ( script , puts ) ) ;
218+ } ) ;
219+
220+ compiler . plugin ( 'emit' , function ( compilation , callback ) {
221+ if ( _this . options . onBuildEnd . length ) {
222+ console . log ( 'Executing post-build scripts' ) ;
223+ _this . options . onBuildEnd . forEach ( function ( script ) {
224+ if ( _this . options . throwOnExecError ) {
225+ spreadStdoutAndStdErr ( exec ( script , putsThrow ) ) ;
226+ } else {
227+ spreadStdoutAndStdErr ( exec ( script , puts ) ) ;
228+ }
229+ } ) ;
230+ if ( _this . options . dev ) {
231+ _this . options . onBuildEnd = [ ] ;
103232 }
104- } ) ;
105- }
106- } ) ;
107- }
108- }
233+ }
234+ callback ( ) ;
235+ } ) ;
236+
237+ compiler . plugin ( 'done' , function ( ) {
238+ if ( _this . options . onBuildExit . length ) {
239+ console . log ( 'Executing additional scripts before exit' ) ;
240+ _this . options . onBuildExit . forEach ( function ( script ) {
241+ if ( _this . options . throwOnExecError ) {
242+ spreadStdoutAndStdErr ( exec ( script , putsThrow ) ) ;
243+ } else {
244+ spreadStdoutAndStdErr ( exec ( script , puts ) ) ;
245+ }
246+ } ) ;
247+ }
248+ } ) ;
249+ }
250+ } ] ) ;
251+ return WebpackShellPlugin ;
252+ } ( ) ;
109253
110254module . exports = WebpackShellPlugin ;
0 commit comments