mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-22 15:02:22 +00:00
ca40d7ca65
Currently we log a CLI event with the passed command, however this might include usr params, like a uuid, and therefore cause thousands of different event names in Mixpanel.
42 lines
1.2 KiB
JavaScript
42 lines
1.2 KiB
JavaScript
(function() {
|
|
var Mixpanel, Promise, _, capitanoState, packageJSON, resin;
|
|
|
|
_ = require('lodash');
|
|
|
|
Mixpanel = require('mixpanel');
|
|
|
|
Promise = require('bluebird');
|
|
|
|
resin = require('resin-sdk');
|
|
|
|
capitanoState = Promise.promisifyAll(require('capitano').state);
|
|
|
|
packageJSON = require('../package.json');
|
|
|
|
exports.getLoggerInstance = _.memoize(function() {
|
|
return resin.models.config.getMixpanelToken().then(Mixpanel.init);
|
|
});
|
|
|
|
exports.trackCommand = function(capitanoCommand) {
|
|
return Promise.props({
|
|
resinUrl: resin.settings.get('resinUrl'),
|
|
username: resin.auth.whoami(),
|
|
mixpanel: exports.getLoggerInstance()
|
|
}).then(function(data) {
|
|
return capitanoState.getMatchCommandAsync(capitanoCommand.command).then(function(command) {
|
|
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
|
|
});
|
|
});
|
|
});
|
|
};
|
|
|
|
}).call(this);
|