Skip to content

Commit cef1455

Browse files
committed
feat(analytics): implement mvp analytics
1 parent 0c4d69b commit cef1455

File tree

3 files changed

+324
-21
lines changed

3 files changed

+324
-21
lines changed

bin/webpack.js

100644100755
Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,27 @@
55
Author Tobias Koppers @sokra
66
*/
77
var 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
1018
try {
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) { }
1624
var 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

2230
require("./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
});

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"async": "^2.1.2",
1212
"enhanced-resolve": "^3.4.0",
1313
"escope": "^3.6.0",
14+
"insight": "^0.8.4",
1415
"interpret": "^1.0.0",
1516
"json-loader": "^0.5.4",
1617
"json5": "^0.5.1",

0 commit comments

Comments
 (0)