balena-cli/build/events.js

50 lines
1.4 KiB
JavaScript
Raw Normal View History

2017-06-08 10:52:47 +00:00
// Generated by CoffeeScript 1.12.6
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
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) {
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(arg) {
var mixpanel, resinUrl, username;
username = arg.username, resinUrl = arg.resinUrl, mixpanel = arg.mixpanel;
return capitanoStateGetMatchCommandAsync(capitanoCommand.command).then(function(command) {
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,
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
});
};