2016-02-12 18:34:16 +00:00
|
|
|
_ = require('lodash')
|
|
|
|
Mixpanel = require('mixpanel')
|
2017-05-12 09:42:09 +00:00
|
|
|
Raven = require('raven')
|
2016-02-12 18:34:16 +00:00
|
|
|
Promise = require('bluebird')
|
2017-01-25 18:32:07 +00:00
|
|
|
resin = require('resin-sdk-preconfigured')
|
2016-02-12 18:34:16 +00:00
|
|
|
packageJSON = require('../package.json')
|
|
|
|
|
|
|
|
exports.getLoggerInstance = _.memoize ->
|
|
|
|
return resin.models.config.getMixpanelToken().then(Mixpanel.init)
|
|
|
|
|
|
|
|
exports.trackCommand = (capitanoCommand) ->
|
2017-03-27 09:14:55 +00:00
|
|
|
capitanoStateGetMatchCommandAsync = Promise.promisify(require('capitano').state.getMatchCommand)
|
|
|
|
|
2016-02-12 18:34:16 +00:00
|
|
|
return Promise.props
|
|
|
|
resinUrl: resin.settings.get('resinUrl')
|
2017-10-05 10:49:06 +00:00
|
|
|
username: resin.auth.whoami().catchReturn(undefined)
|
2016-02-12 18:34:16 +00:00
|
|
|
mixpanel: exports.getLoggerInstance()
|
2017-05-12 09:42:09 +00:00
|
|
|
.then ({ username, resinUrl, mixpanel }) ->
|
2017-03-27 09:14:55 +00:00
|
|
|
return capitanoStateGetMatchCommandAsync(capitanoCommand.command).then (command) ->
|
2017-05-12 09:42:09 +00:00
|
|
|
Raven.mergeContext(user: {
|
|
|
|
id: username,
|
|
|
|
username
|
|
|
|
})
|
|
|
|
mixpanel.track "[CLI] #{command.signature.toString()}",
|
|
|
|
distinct_id: username
|
2016-03-29 15:27:53 +00:00
|
|
|
argv: process.argv.join(' ')
|
|
|
|
version: packageJSON.version
|
|
|
|
node: process.version
|
|
|
|
arch: process.arch
|
2017-05-12 09:42:09 +00:00
|
|
|
resinUrl: resinUrl
|
2016-03-29 15:27:53 +00:00
|
|
|
platform: process.platform
|
|
|
|
command: capitanoCommand
|
2017-10-05 10:49:06 +00:00
|
|
|
.timeout(100)
|
|
|
|
.catchReturn()
|