This repository has been archived by the owner on Nov 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
121 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright 2013-2015, All Rights Reserved. | ||
* | ||
* Code licensed under the BSD License: | ||
* https://github.com/node-gh/gh/blob/master/LICENSE.md | ||
* | ||
*/ | ||
|
||
'use strict'; | ||
|
||
// -- Requires ------------------------------------------------------------------------------------- | ||
|
||
var logger = require('../logger'), | ||
clc = require('cli-color'), | ||
tracker = require('../tracker'); | ||
|
||
// -- Constructor ---------------------------------------------------------------------------------- | ||
|
||
function Track(options) { | ||
this.options = options; | ||
} | ||
|
||
// -- Constants ------------------------------------------------------------------------------------ | ||
|
||
Track.DETAILS = { | ||
alias: 'tk', | ||
description: 'Anonymous usage reporting control.', | ||
commands: [ | ||
'opt-in', | ||
'opt-out' | ||
], | ||
options: { | ||
'opt-in': Boolean, | ||
'opt-out': Boolean | ||
}, | ||
shorthands: { | ||
'o': ['--opt-in'], | ||
'O': ['--opt-out'] | ||
} | ||
}; | ||
|
||
// -- Commands ------------------------------------------------------------------------------------- | ||
|
||
Track.prototype.run = function() { | ||
var options = this.options; | ||
|
||
if (options['opt-in']) { | ||
this.optIn(); | ||
} | ||
|
||
if (options['opt-out']) { | ||
this.optOut(); | ||
} | ||
|
||
this.isTracking(); | ||
}; | ||
|
||
Track.prototype.isTracking = function() { | ||
var status = 'enable', | ||
next = 'opt-out', | ||
current = tracker.optOut !== false; | ||
|
||
if (current) { | ||
status = 'disable'; | ||
next = 'opt-in'; | ||
} | ||
|
||
logger.info('Reporting anonymous usage statistics is ' + clc.bold(status + 'd') + '.'); | ||
logger.info('You can ' + next + ' it with: ' + clc.cyan('gh track --' + next)); | ||
}; | ||
|
||
Track.prototype.optIn = function() { | ||
tracker.optOut = false; | ||
}; | ||
|
||
Track.prototype.optOut = function() { | ||
tracker.optOut = true; | ||
}; | ||
|
||
exports.Impl = Track; |
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,41 @@ | ||
/* | ||
* Copyright 2015, All Rights Reserved. | ||
* | ||
* Code licensed under the BSD License: | ||
* https://github.com/node-gh/gh/blob/master/LICENSE.md | ||
* | ||
* @author Henrique Vicente <[email protected]> | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var tracker, | ||
Insight = require('insight'), | ||
CmdAnonymizer = require('./cmd-anonymizer'), | ||
pkg = require('../package.json'), | ||
redaction = '********'; | ||
|
||
tracker = new Insight({ | ||
trackingCode: pkg.trackingCode, | ||
pkg: pkg | ||
}); | ||
|
||
tracker.resolveCommand = function(cmd, commandDetails) { | ||
var cmdAnonymizer; | ||
|
||
if (!commandDetails) { | ||
return cmd.join(' ').replace(/\w+/g, redaction); | ||
} | ||
|
||
cmdAnonymizer = new CmdAnonymizer(commandDetails, redaction); | ||
|
||
return cmdAnonymizer.resolveToString(cmd); | ||
}; | ||
|
||
tracker.trackCommand = function(cmd, commandDetails) { | ||
var tracking = pkg.name + ' ' + this.resolveCommand(cmd, commandDetails); | ||
|
||
this.track(tracking.replace(/ /g, '%20')); | ||
}; | ||
|
||
module.exports = tracker; |