forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-analytics
More file actions
executable file
·65 lines (49 loc) · 1.84 KB
/
build-analytics
File metadata and controls
executable file
·65 lines (49 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env node
// Usage:
//
// build analytics start|success|error|<exitCode> <actionCategory> <actionName>
'use strict';
var analytics = require('./analytics');
var fs = require('fs');
var path = require('path');
var eventType = process.argv[2];
var actionCategory = process.argv[3];
var actionName = process.argv[4];
if (!analytics[actionCategory + 'Start']) {
throw new Error('Unknown build-analytics actionCategory "' + actionCategory + '"');
}
var exitCode = Number.parseInt(eventType, 10);
if (!Number.isNaN(exitCode)) {
eventType = (exitCode === 0) ? 'success' : 'error';
}
if (eventType != 'start' && eventType != 'success' && eventType != 'error') {
throw new Error('Unknown build-analytics eventType "' + eventType + '"');
}
var startTimestampFilePath = path.resolve(path.join(__dirname, '..', '..', 'tmp', 'analytics', actionCategory + '-' + actionName));
var analyticsDirPath = path.dirname(startTimestampFilePath);
var tmpDirPath = path.dirname(analyticsDirPath);
if (!fs.existsSync(tmpDirPath)) {
fs.mkdirSync(tmpDirPath);
}
if (!fs.existsSync(analyticsDirPath)) {
fs.mkdirSync(analyticsDirPath);
}
switch (eventType) {
case 'start':
analytics[actionCategory + 'Start'](actionName);
fs.writeFileSync(startTimestampFilePath, Date.now(), 'utf-8');
break;
case 'success':
try {
var startTime = fs.readFileSync(startTimestampFilePath, 'utf-8');
analytics[actionCategory + 'Success'](actionName, Date.now() - startTime);
fs.unlinkSync(startTimestampFilePath);
} catch(e) {
console.log('No start timestamp file "' + startTimestampFilePath + '" found, skipping analytics.');
}
break;
case 'error':
var startTime = fs.readFileSync(startTimestampFilePath, 'utf-8');
analytics[actionCategory + 'Error'](actionName, Date.now() - startTime);
fs.unlinkSync(startTimestampFilePath);
}