mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-24 07:46:39 +00:00
6daed83d88
Change-Type: patch
43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import * as Capitano from 'capitano';
|
|
|
|
import _ = require('lodash');
|
|
import Mixpanel = require('mixpanel');
|
|
import Raven = require('raven');
|
|
import Promise = require('bluebird');
|
|
import ResinSdk = require('resin-sdk');
|
|
import packageJSON = require('../package.json');
|
|
|
|
const resin = ResinSdk.fromSharedOptions();
|
|
const getMatchCommandAsync = Promise.promisify(Capitano.state.getMatchCommand);
|
|
const getMixpanel = _.memoize<any>(() => resin.models.config.getAll().get('mixpanelToken').then(Mixpanel.init));
|
|
|
|
export function trackCommand(capitanoCli: Capitano.Cli) {
|
|
return Promise.props({
|
|
resinUrl: resin.settings.get('resinUrl'),
|
|
username: resin.auth.whoami().catchReturn(undefined),
|
|
mixpanel: getMixpanel(),
|
|
}).then(({ username, resinUrl, mixpanel }) => {
|
|
return getMatchCommandAsync(capitanoCli.command).then((command) => {
|
|
Raven.mergeContext({
|
|
user: {
|
|
id: username,
|
|
username,
|
|
},
|
|
});
|
|
|
|
return mixpanel.track(`[CLI] ${command.signature.toString()}`, {
|
|
distinct_id: username,
|
|
argv: process.argv.join(' '),
|
|
version: packageJSON.version,
|
|
node: process.version,
|
|
arch: process.arch,
|
|
resinUrl,
|
|
platform: process.platform,
|
|
command: capitanoCli,
|
|
});
|
|
});
|
|
})
|
|
.timeout(100)
|
|
.catchReturn(undefined);
|
|
}
|