Skip to content
This repository has been archived by the owner on Nov 4, 2022. It is now read-only.

Commit

Permalink
Adding tracker and tracker config.
Browse files Browse the repository at this point in the history
  • Loading branch information
henvic committed Jan 17, 2015
1 parent ff18be8 commit 9bed3a8
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 0 deletions.
80 changes: 80 additions & 0 deletions lib/cmds/track.js
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;
41 changes: 41 additions & 0 deletions lib/tracker.js
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;

0 comments on commit 9bed3a8

Please sign in to comment.