forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build(analytics): add support for tracking npm installs
Since the very first npm install is called while node_modules is empty, we need to ignore it, but we can track the start timestamp and record the install even once the installation is completed.
- Loading branch information
Showing
4 changed files
with
135 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env node | ||
|
||
'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 + '"'); | ||
} | ||
|
||
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': | ||
var startTime = fs.readFileSync(startTimestampFilePath, 'utf-8'); | ||
analytics[actionCategory + 'Success'](actionName, Date.now() - startTime); | ||
fs.unlinkSync(startTimestampFilePath); | ||
break; | ||
case 'error': | ||
var startTime = fs.readFileSync(startTimestampFilePath, 'utf-8'); | ||
analytics[actionCategory + 'Error'](actionName, Date.now() - startTime); | ||
fs.unlinkSync(startTimestampFilePath); | ||
} |