Skip to content

Commit

Permalink
Adding logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jayair committed Oct 18, 2016
1 parent 756b758 commit 6d25503
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/actions/action-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ export const SPECS_LOAD_FAIL = 'SPECS_LOAD_FAIL';
export const TOOLS_LOAD = 'TOOLS_LOAD';
export const TOOLS_LOAD_SUCCESS = 'TOOLS_LOAD_SUCCESS';
export const TOOLS_LOAD_FAIL = 'TOOLS_LOAD_FAIL';

export const TRACKER_TRACK = 'TRACKER_TRACK';
export const TRACKER_TRACK_SUCCESS = 'TRACKER_TRACK_SUCCESS';
export const TRACKER_TRACK_FAIL = 'TRACKER_TRACK_FAIL';
20 changes: 20 additions & 0 deletions src/actions/tracker-actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as types from './action-types';

/////////////
// Actions //
/////////////

export function track(event, properties) {
return {
types: [ types.TRACKER_TRACK, types.TRACKER_TRACK_SUCCESS, types.TRACKER_TRACK_FAIL ],
promise: (client, sessionId) => client.post('/public/track', {
data: {
session_id: sessionId,
event_name: event,
event_properties: JSON.stringify({
arguments: JSON.stringify(properties)
})
}
})
};
}
15 changes: 15 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import yargs from 'yargs';
import updateNotifier from 'update-notifier';

import store from './store';
import * as userActions from './actions/user-actions';
import * as trackerActions from './actions/tracker-actions';
import errorHandler from './libs/error-handler';
import { trimChar } from './libs/string';
import { quietParse } from './libs/json';
Expand Down Expand Up @@ -166,6 +168,9 @@ catch(e) {
///////////////////////

function runCommand(argv) {
store.dispatch(userActions.load());
store.dispatch(trackerActions.track(...getTrackerArgs(argv)));

switch (argv._[0]) {
case SIGNUP:
return requireAnonymous(() => signup(store));
Expand Down Expand Up @@ -341,6 +346,16 @@ function checkOperation(argv) {
return true;
}

function getTrackerArgs(argv) {
const event = `CLI ${argv._.join('.')}`;
const [ , , ...rawArgs ] = process.argv;

return [
event,
rawArgs,
];
}

function checkUpdates() {
const notifier = updateNotifier({ pkg: packageJson });

Expand Down
2 changes: 0 additions & 2 deletions src/libs/require-anonymous.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import chalk from 'chalk';
import * as userActions from '../actions/user-actions';

export default store => callback => {
store.dispatch(userActions.load());

if (userActions.isLoggedIn(store.getState())) {
console.log(`You are logged in as '${userActions.getUserEmail(store.getState())}'`);
return;
Expand Down
2 changes: 0 additions & 2 deletions src/libs/require-login.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import chalk from 'chalk';
import * as userActions from '../actions/user-actions';

export default store => callback => {
store.dispatch(userActions.load());

if ( ! userActions.isLoggedIn(store.getState())) {
console.log(chalk.red('Error: You need to be logged in to continue'));
return;
Expand Down
2 changes: 2 additions & 0 deletions src/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import user from './user';
import spec from './spec';
import specs from './specs';
import tools from './tools';
import tracker from './tracker';

export {
user,
spec,
specs,
tools,
tracker,
};
16 changes: 16 additions & 0 deletions src/reducers/tracker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as types from '../actions/action-types';

const initialState = {
};

export default function user(state = initialState, action = {}) {
switch (action.type) {

case types.TRACKER_TRACK:
// Handled in middleware
return state;

default:
return state;
}
}
1 change: 1 addition & 0 deletions src/reducers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default function user(state = initialState, action = {}) {
switch (action.type) {

case types.USER_LOAD:
// Handled in middleware
return state;
case types.USER_LOAD_SUCCESS:
return { ...state,
Expand Down

0 comments on commit 6d25503

Please sign in to comment.