55 Author Tobias Koppers @sokra
66*/
77var path = require ( "path" ) ;
8+ var Insight = require ( "insight" ) ;
9+ var pkg = require ( "../package.json" ) ;
10+ var asyncLib = require ( "async" ) ;
11+
12+ var insight = new Insight ( {
13+ trackingCode : "UA-46921629-3" ,
14+ pkg : pkg
15+ } ) ;
816
917// Local version replace global one
1018try {
1119 var localWebpack = require . resolve ( path . join ( process . cwd ( ) , "node_modules" , "webpack" , "bin" , "webpack.js" ) ) ;
1220 if ( __filename !== localWebpack ) {
1321 return require ( localWebpack ) ;
1422 }
15- } catch ( e ) { }
23+ } catch ( e ) { }
1624var yargs = require ( "yargs" )
1725 . usage ( "webpack " + require ( "../package.json" ) . version + "\n" +
18- "Usage: https://webpack.js.org/api/cli/\n" +
19- "Usage without config file: webpack <entry> [<entry>] <output>\n" +
20- "Usage with config file: webpack" ) ;
26+ "Usage: https://webpack.js.org/api/cli/\n" +
27+ "Usage without config file: webpack <entry> [<entry>] <output>\n" +
28+ "Usage with config file: webpack" ) ;
2129
2230require ( "./config-yargs" ) ( yargs ) ;
2331
@@ -180,7 +188,7 @@ yargs.parse(process.argv.slice(2), (err, argv, output) => {
180188 }
181189 }
182190
183- function processOptions ( options ) {
191+ function processOptions ( options , insightReporter ) {
184192 // process Promise
185193 if ( typeof options . then === "function" ) {
186194 options . then ( processOptions ) . catch ( function ( err ) {
@@ -326,6 +334,11 @@ yargs.parse(process.argv.slice(2), (err, argv, output) => {
326334 }
327335 } ) ;
328336
337+ asyncLib . forEach ( Object . keys ( options ) , function ( optionKey , cb ) {
338+ insight . trackEvent ( "options" , optionKey , JSON . stringify ( options [ optionKey ] ) ) ;
339+ cb ( ) ;
340+ } ) ;
341+
329342 var webpack = require ( "../lib/webpack.js" ) ;
330343
331344 Error . stackTraceLimit = 30 ;
@@ -357,6 +370,8 @@ yargs.parse(process.argv.slice(2), (err, argv, output) => {
357370 // Do not keep cache anymore
358371 compiler . purgeInputFileSystem ( ) ;
359372 }
373+
374+ insightReporter . trackEvent ( "compiler" , "build-end" ) ;
360375 if ( err ) {
361376 lastHash = null ;
362377 console . error ( err . stack || err ) ;
@@ -373,6 +388,7 @@ yargs.parse(process.argv.slice(2), (err, argv, output) => {
373388 }
374389 if ( ! options . watch && stats . hasErrors ( ) ) {
375390 process . exitCode = 2 ;
391+
376392 }
377393 }
378394 if ( firstOptions . watch || options . watch ) {
@@ -386,10 +402,16 @@ yargs.parse(process.argv.slice(2), (err, argv, output) => {
386402 compiler . watch ( watchOptions , compilerCallback ) ;
387403 console . log ( "\nWebpack is watching the files…\n" ) ;
388404 } else
389- compiler . run ( compilerCallback ) ;
390-
405+ insightReporter . trackEvent ( "compiler" , "build-start" ) ;
406+ compiler . run ( compilerCallback ) ;
391407 }
392408
393- processOptions ( options ) ;
409+ if ( insight . optOut === undefined ) {
410+ insight . askPermission ( null , ( ) => {
411+ processOptions ( options , insight ) ;
412+ } ) ;
413+ } else {
414+ processOptions ( options , insight ) ;
415+ }
394416
395417} ) ;
0 commit comments