2017-06-08 10:52:47 +00:00
|
|
|
// Generated by CoffeeScript 1.12.6
|
2017-05-12 09:42:09 +00:00
|
|
|
var Mixpanel, Promise, Raven, _, packageJSON, resin;
|
2016-02-12 18:34:16 +00:00
|
|
|
|
2017-03-22 09:46:06 +00:00
|
|
|
_ = require('lodash');
|
2016-02-12 18:34:16 +00:00
|
|
|
|
2017-03-22 09:46:06 +00:00
|
|
|
Mixpanel = require('mixpanel');
|
2016-02-12 18:34:16 +00:00
|
|
|
|
2017-05-12 09:42:09 +00:00
|
|
|
Raven = require('raven');
|
|
|
|
|
2017-03-22 09:46:06 +00:00
|
|
|
Promise = require('bluebird');
|
2016-02-12 18:34:16 +00:00
|
|
|
|
2017-03-22 09:46:06 +00:00
|
|
|
resin = require('resin-sdk-preconfigured');
|
2016-02-12 18:34:16 +00:00
|
|
|
|
2017-03-22 09:46:06 +00:00
|
|
|
packageJSON = require('../package.json');
|
2016-02-12 18:34:16 +00:00
|
|
|
|
2017-03-22 09:46:06 +00:00
|
|
|
exports.getLoggerInstance = _.memoize(function() {
|
|
|
|
return resin.models.config.getMixpanelToken().then(Mixpanel.init);
|
|
|
|
});
|
2016-02-12 18:34:16 +00:00
|
|
|
|
2017-03-22 09:46:06 +00:00
|
|
|
exports.trackCommand = function(capitanoCommand) {
|
2017-03-27 09:14:55 +00:00
|
|
|
var capitanoStateGetMatchCommandAsync;
|
|
|
|
capitanoStateGetMatchCommandAsync = Promise.promisify(require('capitano').state.getMatchCommand);
|
2017-03-22 09:46:06 +00:00
|
|
|
return Promise.props({
|
|
|
|
resinUrl: resin.settings.get('resinUrl'),
|
|
|
|
username: resin.auth.whoami(),
|
|
|
|
mixpanel: exports.getLoggerInstance()
|
2017-05-12 09:42:09 +00:00
|
|
|
}).then(function(arg) {
|
|
|
|
var mixpanel, resinUrl, username;
|
|
|
|
username = arg.username, resinUrl = arg.resinUrl, mixpanel = arg.mixpanel;
|
2017-03-27 09:14:55 +00:00
|
|
|
return capitanoStateGetMatchCommandAsync(capitanoCommand.command).then(function(command) {
|
2017-05-12 09:42:09 +00:00
|
|
|
Raven.mergeContext({
|
|
|
|
user: {
|
|
|
|
id: username,
|
|
|
|
username: username
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return mixpanel.track("[CLI] " + (command.signature.toString()), {
|
|
|
|
distinct_id: username,
|
2017-03-22 09:46:06 +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,
|
2017-03-22 09:46:06 +00:00
|
|
|
platform: process.platform,
|
|
|
|
command: capitanoCommand
|
2016-02-12 18:34:16 +00:00
|
|
|
});
|
|
|
|
});
|
2017-03-22 09:46:06 +00:00
|
|
|
});
|
|
|
|
};
|