1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const fs = require('fs');
|
4 | const os = require('os');
|
5 | const path = require('path');
|
6 | const Analytics = require('analytics-node');
|
7 | const child_process_1 = require("child_process");
|
8 | exports.botonic_home_path = path.join(os.homedir(), '.botonic');
|
9 | exports.botonic_credentials_path = path.join(exports.botonic_home_path, 'credentials.json');
|
10 | function initializeCredentials() {
|
11 | if (!fs.existsSync(exports.botonic_home_path))
|
12 | fs.mkdirSync(exports.botonic_home_path);
|
13 | let anonymous_id = Math.round(Math.random() * 100000000);
|
14 | fs.writeFileSync(exports.botonic_credentials_path, JSON.stringify({ analytics: { anonymous_id } }));
|
15 | }
|
16 | exports.initializeCredentials = initializeCredentials;
|
17 | function readCredentials() {
|
18 | if (!fs.existsSync(exports.botonic_credentials_path)) {
|
19 | initializeCredentials();
|
20 | }
|
21 | try {
|
22 | exports.credentials = JSON.parse(fs.readFileSync(exports.botonic_credentials_path));
|
23 | }
|
24 | catch (e) { }
|
25 | }
|
26 | try {
|
27 | readCredentials();
|
28 | }
|
29 | catch (e) { }
|
30 | function analytics_enabled() {
|
31 | return process.env.BOTONIC_DISABLE_ANALYTICS !== '1';
|
32 | }
|
33 | if (analytics_enabled()) {
|
34 | exports.analytics = new Analytics('YD0jpJHNGW12uhLNbgB4wbdTRQ4Cy1Zu');
|
35 | }
|
36 | function track(event, properties = {}) {
|
37 | if (analytics_enabled() && exports.analytics && exports.credentials && exports.credentials.analytics)
|
38 | exports.analytics.track({
|
39 | event: event,
|
40 | anonymousId: exports.credentials.analytics.anonymous_id,
|
41 | properties: properties
|
42 | });
|
43 | }
|
44 | exports.track = track;
|
45 | function botonicPostInstall() {
|
46 | if (analytics_enabled()) {
|
47 | initializeCredentials();
|
48 | readCredentials();
|
49 | track('Installed Botonic CLI');
|
50 | }
|
51 | }
|
52 | exports.botonicPostInstall = botonicPostInstall;
|
53 | function sleep(ms) {
|
54 | return new Promise(resolve => setTimeout(resolve, ms));
|
55 | }
|
56 | exports.sleep = sleep;
|
57 | async function sh(cmd) {
|
58 | return new Promise(function (resolve, reject) {
|
59 | child_process_1.exec(cmd, (err, stdout, stderr) => {
|
60 | if (err) {
|
61 | reject(err);
|
62 | }
|
63 | else {
|
64 | resolve({ stdout, stderr });
|
65 | }
|
66 | });
|
67 | });
|
68 | }
|
69 | async function getGlobalNodeModulesPath() {
|
70 | const CROSS_PLATFORM_REGEX = /\r?\n|\r/g;
|
71 | return (await sh('npm root -g')).stdout.replace(CROSS_PLATFORM_REGEX, '');
|
72 | }
|
73 | exports.getGlobalNodeModulesPath = getGlobalNodeModulesPath;
|
74 |
|
\ | No newline at end of file |