Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify the option to stop tracking. #399

Merged
merged 1 commit into from
Aug 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions dist/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,10 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de

var logger = console;

_commander2.default.version(_package2.default.version).option('-p, --port [number]', 'Port to run Storybook (Required)', parseInt).option('-h, --host [string]', 'Host to run Storybook').option('-s, --static-dir <dir-names>', 'Directory where to load static files from', _utils.parseList).option('-c, --config-dir [dir-name]', 'Directory where to load Storybook configurations from').option('--dont-track', 'Do not send anonymous usage stats').option('--do-track', 'Send anonymous usage stats').parse(process.argv);
_commander2.default.version(_package2.default.version).option('-p, --port [number]', 'Port to run Storybook (Required)', parseInt).option('-h, --host [string]', 'Host to run Storybook').option('-s, --static-dir <dir-names>', 'Directory where to load static files from', _utils.parseList).option('-c, --config-dir [dir-name]', 'Directory where to load Storybook configurations from').option('--dont-track', 'Do not send anonymous usage stats.').parse(process.argv);

if (_commander2.default.dontTrack) {
(0, _track_usage.dontTrack)();
logger.info('Storybook would not send anonymous usage stats anymore.');
process.exit(0);
}

if (_commander2.default.doTrack) {
(0, _track_usage.dontTrack)(false);
logger.info('Storybook would send anonymous usage to getstorybooks.io.');
process.exit(0);
}

if (!_commander2.default.port) {
Expand Down
30 changes: 8 additions & 22 deletions dist/server/track_usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ var logger = console; // ### WHAT?
// ### CAN I STOP THIS?
//
// You(or your company) may have certain policies.
// If so, you can stop sending these metrics. Simply run:
// start-storybook --dont-track
// If so, you can stop sending these metrics.
// To do that, use --dont-track flag when running React Storybook.
// start-storybook --dont-track -p 9001

// ### HELP US?
//
Expand All @@ -54,13 +55,17 @@ var logger = console; // ### WHAT?
// service around it. With that, we could continue to maintain and
// improve Storybook.

var DONT_TRACK = false;

function getStore() {
var key = 'react-storybook-usage';
var store = new _configstore2.default(key);
return store;
}

function track() {
if (DONT_TRACK) return;

var store = getStore();

// Just a hash to aggregate metrics. Don't use any personal info.
Expand All @@ -70,22 +75,6 @@ function track() {
store.set('userId', userId);
}

if (store.get('dontTrack')) {
// Here we'll try to send a one last ping saying you are asked to don't track.
// We used this to identify the ratio of dontTrack.
if (!store.get('notifiedDontTrack')) {
// We don't wanna worry about the success or failure of this.
_request2.default.post('https://ping.getstorybook.io/react-storybook-dont-track', {
json: { userId: userId }
}, function () {});
store.set('notifiedDontTrack', true);
}
return;
}

// We need to clear this in case user decided to track again.
store.set('notifiedDontTrack', null);

var pkg = require('../../package.json');

// We don't wanna worry about the success or failure of this.
Expand All @@ -111,8 +100,5 @@ function track() {
}

function dontTrack() {
var state = arguments.length <= 0 || arguments[0] === undefined ? true : arguments[0];

var store = getStore();
store.set('dontTrack', Boolean(state));
DONT_TRACK = true;
}
11 changes: 1 addition & 10 deletions src/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,12 @@ program
.option('-h, --host [string]', 'Host to run Storybook')
.option('-s, --static-dir <dir-names>', 'Directory where to load static files from', parseList)
.option('-c, --config-dir [dir-name]', 'Directory where to load Storybook configurations from')
.option('--dont-track', 'Do not send anonymous usage stats')
.option('--do-track', 'Send anonymous usage stats')
.option('--dont-track', 'Do not send anonymous usage stats.')
.parse(process.argv);


if (program.dontTrack) {
dontTrack();
logger.info('Storybook would not send anonymous usage stats anymore.');
process.exit(0);
}

if (program.doTrack) {
dontTrack(false);
logger.info('Storybook would send anonymous usage to getstorybooks.io.');
process.exit(0);
}

if (!program.port) {
Expand Down
30 changes: 9 additions & 21 deletions src/server/track_usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
// ### CAN I STOP THIS?
//
// You(or your company) may have certain policies.
// If so, you can stop sending these metrics. Simply run:
// start-storybook --dont-track
// If so, you can stop sending these metrics.
// To do that, use --dont-track flag when running React Storybook.
// start-storybook --dont-track -p 9001

// ### HELP US?
//
Expand All @@ -37,13 +38,17 @@ import request from 'request';

const logger = console;

let DONT_TRACK = false;

export function getStore() {
const key = 'react-storybook-usage';
const store = new ConfigStore(key);
return store;
}

export function track() {
if (DONT_TRACK) return;

const store = getStore();

// Just a hash to aggregate metrics. Don't use any personal info.
Expand All @@ -53,22 +58,6 @@ export function track() {
store.set('userId', userId);
}

if (store.get('dontTrack')) {
// Here we'll try to send a one last ping saying you are asked to don't track.
// We used this to identify the ratio of dontTrack.
if (!store.get('notifiedDontTrack')) {
// We don't wanna worry about the success or failure of this.
request.post('https://ping.getstorybook.io/react-storybook-dont-track', {
json: { userId },
}, () => {});
store.set('notifiedDontTrack', true);
}
return;
}

// We need to clear this in case user decided to track again.
store.set('notifiedDontTrack', null);

const pkg = require('../../package.json');

// We don't wanna worry about the success or failure of this.
Expand All @@ -93,7 +82,6 @@ export function track() {
}
}

export function dontTrack(state = true) {
const store = getStore();
store.set('dontTrack', Boolean(state));
export function dontTrack() {
DONT_TRACK = true;
}