2017-03-08 23:30:24 +00:00
|
|
|
// Generated by CoffeeScript 1.12.4
|
2017-03-27 09:14:55 +00:00
|
|
|
var Mixpanel, Promise, _, 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-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()
|
|
|
|
}).then(function(data) {
|
2017-03-27 09:14:55 +00:00
|
|
|
return capitanoStateGetMatchCommandAsync(capitanoCommand.command).then(function(command) {
|
2017-03-22 09:46:06 +00:00
|
|
|
return data.mixpanel.track("[CLI] " + (command.signature.toString()), {
|
|
|
|
distinct_id: data.username,
|
|
|
|
argv: process.argv.join(' '),
|
|
|
|
version: packageJSON.version,
|
|
|
|
node: process.version,
|
|
|
|
arch: process.arch,
|
|
|
|
resinUrl: data.resinUrl,
|
|
|
|
platform: process.platform,
|
|
|
|
command: capitanoCommand
|
2016-02-12 18:34:16 +00:00
|
|
|
});
|
|
|
|
});
|
2017-03-22 09:46:06 +00:00
|
|
|
});
|
|
|
|
};
|