@@ -153,85 +153,70 @@ function c(str) {
153153 return argv . colors ? str : "" ;
154154}
155155
156- if ( ! output ) {
157- // DEPRECATED
158- webpack ( input , options , function ( err , source ) {
159- if ( err ) {
160- console . error ( err ) ;
161- return ;
162- }
163- if ( output ) {
164- fs . writeFileSync ( output , source , "utf-8" ) ;
165- } else {
166- process . stdout . write ( source ) ;
156+ output = output || path . join ( process . cwd ( ) , "js" , "web.js" ) ;
157+ if ( ! options . outputDirectory ) options . outputDirectory = path . dirname ( output ) ;
158+ if ( ! options . output ) options . output = path . basename ( output ) ;
159+ if ( ! options . outputPostfix ) options . outputPostfix = "." + path . basename ( output ) ;
160+ if ( ! options . context ) options . context = process . cwd ( ) ;
161+
162+ // some listeners for the progress display
163+ if ( argv . progress ) {
164+ if ( ! options . events ) options . events = new ( require ( "events" ) . EventEmitter ) ( ) ;
165+ var events = options . events ;
166+
167+ var sum = 0 ;
168+ var finished = 0 ;
169+ var chars = 0 ;
170+ function print ( ) {
171+ var msg = "" ;
172+ if ( sum > 0 ) {
173+ msg += "compiling... (" + c ( "\033[1m\033[33m" ) ;
174+ msg += sprintf ( "%4s" , finished + "" ) + "/" + sprintf ( "%4s" , sum + "" ) ;
175+ msg += " " + sprintf ( "%4s" , Math . floor ( finished * 100 / sum ) + "%" ) ;
176+ msg += c ( "\033[39m\033[22m" ) + ")" ;
167177 }
178+ for ( var i = 0 ; i < chars ; i ++ )
179+ process . stderr . write ( "\b" ) ;
180+ process . stderr . write ( msg ) ;
181+ chars = msg . length ;
182+ }
183+ events . on ( "task" , function ( name ) {
184+ sum ++ ;
185+ print ( ) ;
168186 } ) ;
169- } else {
170- output = output || path . join ( process . cwd ( ) , "js" , "web.js" ) ;
171- if ( ! options . outputDirectory ) options . outputDirectory = path . dirname ( output ) ;
172- if ( ! options . output ) options . output = path . basename ( output ) ;
173- if ( ! options . outputPostfix ) options . outputPostfix = "." + path . basename ( output ) ;
174- if ( ! options . context ) options . context = process . cwd ( ) ;
175-
176- // some listeners for the progress display
177- if ( argv . progress ) {
178- if ( ! options . events ) options . events = new ( require ( "events" ) . EventEmitter ) ( ) ;
179- var events = options . events ;
180-
181- var sum = 0 ;
182- var finished = 0 ;
183- var chars = 0 ;
184- function print ( ) {
185- var msg = "" ;
186- if ( sum > 0 ) {
187- msg += "compiling... (" + c ( "\033[1m\033[33m" ) ;
188- msg += sprintf ( "%4s" , finished + "" ) + "/" + sprintf ( "%4s" , sum + "" ) ;
189- msg += " " + sprintf ( "%4s" , Math . floor ( finished * 100 / sum ) + "%" ) ;
190- msg += c ( "\033[39m\033[22m" ) + ")" ;
191- }
192- for ( var i = 0 ; i < chars ; i ++ )
193- process . stderr . write ( "\b" ) ;
194- process . stderr . write ( msg ) ;
195- chars = msg . length ;
196- }
197- events . on ( "task" , function ( name ) {
198- sum ++ ;
199- print ( ) ;
200- } ) ;
201- events . on ( "task-end" , function ( name ) {
202- finished ++ ;
203- if ( name ) {
204- for ( var i = 0 ; i < chars ; i ++ )
205- process . stderr . write ( "\b \b" ) ;
206- process . stderr . write ( name + " " + c ( "\033[1m\033[32m" ) + "done" + c ( "\033[39m\033[22m" ) + "\n" ) ;
207- chars = 0 ;
208- }
209- print ( ) ;
210- } ) ;
211- events . on ( "bundle" , function ( name ) {
212- sum = 0 ;
213- finished = 0 ;
187+ events . on ( "task-end" , function ( name ) {
188+ finished ++ ;
189+ if ( name ) {
214190 for ( var i = 0 ; i < chars ; i ++ )
215191 process . stderr . write ( "\b \b" ) ;
192+ process . stderr . write ( name + " " + c ( "\033[1m\033[32m" ) + "done" + c ( "\033[39m\033[22m" ) + "\n" ) ;
216193 chars = 0 ;
217- } ) ;
218- }
219-
220- // do the stuff
221- webpack ( input , options , function ( err , stats ) {
222- if ( err ) {
223- console . error ( err ) ;
224- return ;
225- }
226- if ( argv . json )
227- console . log ( util . inspect ( stats , false , 10 , argv . colors ) ) ;
228- else {
229- console . log ( formatOutput ( stats , {
230- colors : argv . colors ,
231- "by-size" : argv [ "by-size" ] ,
232- verbose : argv . verbose ,
233- context : options . context
234- } ) ) ;
235194 }
195+ print ( ) ;
196+ } ) ;
197+ events . on ( "bundle" , function ( name ) {
198+ sum = 0 ;
199+ finished = 0 ;
200+ for ( var i = 0 ; i < chars ; i ++ )
201+ process . stderr . write ( "\b \b" ) ;
202+ chars = 0 ;
236203 } ) ;
237- }
204+ }
205+
206+ // do the stuff
207+ webpack ( input , options , function ( err , stats ) {
208+ if ( err ) {
209+ console . error ( err ) ;
210+ return ;
211+ }
212+ if ( argv . json )
213+ console . log ( JSON . stringify ( stats ) ) ;
214+ else {
215+ console . log ( formatOutput ( stats , {
216+ colors : argv . colors ,
217+ "by-size" : argv [ "by-size" ] ,
218+ verbose : argv . verbose ,
219+ context : options . context
220+ } ) ) ;
221+ }
222+ } ) ;
0 commit comments