@getty.io/taskapp
Advanced tools
Comparing version 1.2.3 to 1.2.4
const Mixpanel = require('mixpanel'); | ||
const {getOptions, getParams} = require('./utils.js'); | ||
const {getOptions, getParams, checkNested} = require('./utils.js'); | ||
const chalk = require('chalk'); | ||
let init = true; | ||
let callback = false; | ||
let hasError = false; | ||
@@ -16,30 +17,34 @@ function mixPanelCallback(e) { | ||
const createEvent = (msg, username) => { | ||
const token = getOptions().taskapp.mixpanel.token; | ||
if (token && token.length > 0) { | ||
const mixpanel = Mixpanel.init(token); | ||
const project = getOptions().name; | ||
const {scope, task, spent } = getParams(msg); | ||
mixpanel.people.set(username, {}, mixPanelCallback); | ||
if (checkNested(getOptions(), 'token')){ | ||
const token = getOptions().taskapp.mixpanel.token; | ||
if (token && token.length > 0) { | ||
const mixpanel = Mixpanel.init(token); | ||
const project = getOptions().name; | ||
const {scope, task, spent } = getParams(msg); | ||
mixpanel.people.set(username, {}, mixPanelCallback); | ||
let stateCheck = setInterval(() => { | ||
if (callback) { | ||
clearInterval(stateCheck); | ||
if (init) { | ||
mixpanel.track(project, { | ||
distinct_id: username, | ||
scope: scope, | ||
task: task, | ||
spent: spent | ||
}); | ||
let stateCheck = setInterval(() => { | ||
if (callback) { | ||
clearInterval(stateCheck); | ||
if (init) { | ||
mixpanel.track(project, { | ||
distinct_id: username, | ||
scope: scope, | ||
task: task, | ||
spent: spent | ||
}); | ||
} | ||
} | ||
} | ||
}, 0); | ||
}, 0); | ||
}else{ | ||
hasError = true; | ||
} | ||
} else { | ||
console.warn(chalk.yellow('INFO: Mixpanel token not found. Please insert the token in the package.json.\nMore info: https://www.npmjs.com/package/@getty.io/taskapp')); | ||
hasError = true; | ||
} | ||
if (hasError) console.warn(chalk.yellow('INFO: Mixpanel token not found. Please insert the token in the package.json.\nMore info: https://www.npmjs.com/package/@getty.io/taskapp')); | ||
} | ||
module.exports = createEvent; |
@@ -22,2 +22,14 @@ const findRoot = require('find-root'); | ||
function checkNested(obj) { | ||
var args = Array.prototype.slice.call(arguments, 1); | ||
for (var i = 0; i < args.length; i++) { | ||
if (!obj || !obj.hasOwnProperty(args[i])) { | ||
return false; | ||
} | ||
obj = obj[args[i]]; | ||
} | ||
return true; | ||
} | ||
const getOptions = () => { | ||
@@ -45,3 +57,4 @@ try { | ||
getOptions, | ||
getParams | ||
getParams, | ||
checkNested | ||
} |
{ | ||
"name": "@getty.io/taskapp", | ||
"version": "1.2.3", | ||
"version": "1.2.4", | ||
"description": "Getty/IO commit-msg hook validator", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
22450
159