Skip to content

Commit e7dda4c

Browse files
VSCODE-20: setup telemetry (#52)
* feat: setup telemetry * build: set variable * build: rebase from master * build: change format of the variable * build: update format * feat: add local env file to npmignore * test: try no-force-async-hooks to solve tests fail on mac * test: try cross-env * fix: use vscode ignore * refactor: fix variables and command description * feat: throw error if the segment key is missing in environment variables * build: add key env variable to the build task
1 parent 64aea70 commit e7dda4c

18 files changed

+487
-42
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ node_modules
55
.DS_Store
66
test-results.xml
77
connect-form
8+
constants.json
9+
.env

.vscode/launch.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,19 @@
4040
"protocol": "inspector",
4141
"port": 6005,
4242
"sourceMaps": true,
43-
"outFiles": ["${workspaceFolder}/out/**/*.js"],
43+
"outFiles": [
44+
"${workspaceFolder}/out/**/*.js"
45+
],
4446
"preLaunchTask": "${defaultBuildTask}"
4547
}
4648
],
4749
"compounds": [
4850
{
4951
"name": "Extension + Server Inspector",
50-
"configurations": ["Run Extension", "Attach to Language Server"]
52+
"configurations": [
53+
"Run Extension",
54+
"Attach to Language Server"
55+
]
5156
}
5257
]
5358
}

.vscodeignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ vsc-extension-quickstart.md
77
**/tsconfig.json
88
**/tslint.json
99
**/*.map
10-
**/*.ts
10+
**/*.ts
11+
.env

azure-pipelines.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ steps:
5757
5858
- bash: npm run test
5959
displayName: 'Run Tests'
60+
env:
61+
SEGMENT_KEY: $(segmentKey)
6062
- bash: ls -alh
6163
displayName: 'Post Tests'
6264

@@ -72,6 +74,8 @@ steps:
7274
npm i -g vsce;
7375
vsce package
7476
displayName: 'Build .vsix'
77+
env:
78+
SEGMENT_KEY: $(segmentKey)
7579
7680
# https://docs.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch#set-variables-in-scripts
7781
- bash: |

package-lock.json

Lines changed: 102 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@
4242
"compile": "npm-run-all compile:*",
4343
"compile:views": "webpack --mode development",
4444
"compile:extension": "npm run update-grammar && npm run update-snippets && tsc -p ./",
45+
"compile:keyfile": "ts-node ./scripts/generate-keyfile.ts",
4546
"watch": "npm-run-all -p watch:*",
4647
"watch:views": "webpack --watch --mode development",
4748
"watch:extension": "npm run compile:extension -- -watch",
4849
"pretest": "npm run compile && cross-env MONGODB_VERSION=4.2.3 mongodb-runner start --port=27018",
49-
"test": "xvfb-maybe node ./out/test/runTest.js",
50+
"test": "cross-env NODE_OPTIONS=--no-force-async-hooks-checks xvfb-maybe node ./out/test/runTest.js",
5051
"posttest": "mongodb-runner stop --port=27018",
5152
"vscode:prepublish": "npm run compile",
5253
"check": "mongodb-js-precommit './src/**/*{.ts}'",
@@ -420,6 +421,11 @@
420421
"default": true,
421422
"description": "Show a confirmation message before running commands in a playground."
422423
},
424+
"mdb.sendTelemetry": {
425+
"type": "boolean",
426+
"default": true,
427+
"description": "Allow the sending of diagnostic and usage telemetry data to help improve user experience."
428+
},
423429
"mdb.connectionSaving.hideOptionToChooseWhereToSaveNewConnections": {
424430
"type": "boolean",
425431
"default": false,
@@ -451,6 +457,7 @@
451457
"dependencies": {
452458
"@mongosh/browser-runtime-electron": "0.0.1-alpha.10",
453459
"@mongosh/service-provider-server": "0.0.1-alpha.10",
460+
"analytics-node": "^3.4.0-beta.1",
454461
"bson": "^4.0.3",
455462
"debug": "^4.1.1",
456463
"mongodb-connection-model": "^14.6.2",
@@ -483,6 +490,7 @@
483490
"chai-json-schema": "^1.5.1",
484491
"cross-env": "^7.0.2",
485492
"css-loader": "^3.4.2",
493+
"dotenv": "^8.2.0",
486494
"eslint": "^6.8.0",
487495
"eslint-config-mongodb-js": "^5.0.3",
488496
"eslint-plugin-react": "^7.19.0",

scripts/generate-keyfile.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#! /usr/bin/env ts-node
2+
3+
import ora = require('ora');
4+
import fs = require('fs');
5+
import path = require('path');
6+
import { resolve } from 'path';
7+
import { config } from 'dotenv';
8+
9+
const { promisify } = require('util');
10+
const writeFile = promisify(fs.writeFile);
11+
const ROOT_DIR = path.join(__dirname, '..');
12+
const ui = ora('Generate constants keyfile').start();
13+
14+
config({ path: resolve(__dirname, '../.env') });
15+
16+
(async () => {
17+
if (process.env.SEGMENT_KEY) {
18+
await writeFile(
19+
`${ROOT_DIR}/constants.json`,
20+
JSON.stringify({ segmentKey: process.env.SEGMENT_KEY }, null, 2)
21+
);
22+
ui.succeed('Generated .constants.json');
23+
} else {
24+
await Promise.reject(new Error('The Segment key is missing in environment variables'));
25+
}
26+
})().catch((error) => {
27+
ui.fail('Failed to generate constants keyfile');
28+
console.log(error);
29+
})

scripts/update-grammar.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#! /usr/bin/env ts-node
22

3-
const path = require('path');
4-
const download = require('download');
5-
const ora = require('ora');
6-
const meow = require('meow');
7-
const mkdirp = require('mkdirp');
3+
import path = require('path');
4+
import mkdirp = require('mkdirp');
5+
import ora = require('ora');
6+
import download = require('download');
7+
import meow = require('meow');
88

99
const DEFAULT_DEST = path.join(__dirname, '..', 'syntaxes');
1010

@@ -45,10 +45,11 @@ const cli = meow(
4545
const ui = ora()
4646
.info('Downlading latest mongodb.tmLanguage.json')
4747
.start();
48+
4849
try {
4950
await download(cli.flags.url, cli.flags.dest);
5051
ui.succeed(
51-
`Downloaded to ${path.join(cli.flags.dest, 'mongodb.tmLanguage.json')}`
52+
`Downloaded to ${path.join(cli.flags.dest as string, 'mongodb.tmLanguage.json')}`
5253
);
5354
} catch (err) {
5455
ui.fail(`Download failed: ${err.message}`);

scripts/update-snippets.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
#! /usr/bin/env ts-node
22

3-
const fs = require('fs');
3+
import path = require('path');
4+
import mkdirp = require('mkdirp');
5+
import ora = require('ora');
6+
import fs = require('fs');
7+
48
const { promisify } = require('util');
59
const writeFile = promisify(fs.writeFile);
6-
7-
const path = require('path');
8-
const mkdirp = require('mkdirp');
9-
const ora = require('ora');
10-
1110
const { STAGE_OPERATORS } = require('mongodb-ace-autocompleter');
12-
const config = require(path.join(__dirname, '..', 'package.json'));
1311
const SNIPPETS_DIR = path.join(__dirname, '..', 'snippets');
1412

1513
/**
@@ -75,9 +73,9 @@ const snippets = STAGE_OPERATORS.reduce(
7573

7674
(async () => {
7775
const ui = ora('Update snippets').start();
76+
7877
ui.info(`Create the ${SNIPPETS_DIR} folder`);
7978
await mkdirp(SNIPPETS_DIR);
80-
8179
await writeFile(
8280
`${SNIPPETS_DIR}/stage-autocompleter.json`,
8381
JSON.stringify(snippets, null, 2)

0 commit comments

Comments
 (0)