Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ node_modules
.DS_Store
test-results.xml
connect-form
constants.json
.env
9 changes: 7 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,19 @@
"protocol": "inspector",
"port": 6005,
"sourceMaps": true,
"outFiles": ["${workspaceFolder}/out/**/*.js"],
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
}
],
"compounds": [
{
"name": "Extension + Server Inspector",
"configurations": ["Run Extension", "Attach to Language Server"]
"configurations": [
"Run Extension",
"Attach to Language Server"
]
}
]
}
3 changes: 2 additions & 1 deletion .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ vsc-extension-quickstart.md
**/tsconfig.json
**/tslint.json
**/*.map
**/*.ts
**/*.ts
.env
4 changes: 4 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ steps:

- bash: npm run test
displayName: 'Run Tests'
env:
SEGMENT_KEY: $(segmentKey)
- bash: ls -alh
displayName: 'Post Tests'

Expand All @@ -72,6 +74,8 @@ steps:
npm i -g vsce;
vsce package
displayName: 'Build .vsix'
env:
SEGMENT_KEY: $(segmentKey)

# https://docs.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch#set-variables-in-scripts
- bash: |
Expand Down
113 changes: 102 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@
"compile": "npm-run-all compile:*",
"compile:views": "webpack --mode development",
"compile:extension": "npm run update-grammar && npm run update-snippets && tsc -p ./",
"compile:keyfile": "ts-node ./scripts/generate-keyfile.ts",
"watch": "npm-run-all -p watch:*",
"watch:views": "webpack --watch --mode development",
"watch:extension": "npm run compile:extension -- -watch",
"pretest": "npm run compile && cross-env MONGODB_VERSION=4.2.3 mongodb-runner start --port=27018",
"test": "xvfb-maybe node ./out/test/runTest.js",
"test": "cross-env NODE_OPTIONS=--no-force-async-hooks-checks xvfb-maybe node ./out/test/runTest.js",
"posttest": "mongodb-runner stop --port=27018",
"vscode:prepublish": "npm run compile",
"check": "mongodb-js-precommit './src/**/*{.ts}'",
Expand Down Expand Up @@ -420,6 +421,11 @@
"default": true,
"description": "Show a confirmation message before running commands in a playground."
},
"mdb.sendTelemetry": {
"type": "boolean",
"default": true,
"description": "Allow the sending of diagnostic and usage telemetry data to help improve user experience."
},
"mdb.connectionSaving.hideOptionToChooseWhereToSaveNewConnections": {
"type": "boolean",
"default": false,
Expand Down Expand Up @@ -451,6 +457,7 @@
"dependencies": {
"@mongosh/browser-runtime-electron": "0.0.1-alpha.10",
"@mongosh/service-provider-server": "0.0.1-alpha.10",
"analytics-node": "^3.4.0-beta.1",
"bson": "^4.0.3",
"debug": "^4.1.1",
"mongodb-connection-model": "^14.6.2",
Expand Down Expand Up @@ -483,6 +490,7 @@
"chai-json-schema": "^1.5.1",
"cross-env": "^7.0.2",
"css-loader": "^3.4.2",
"dotenv": "^8.2.0",
"eslint": "^6.8.0",
"eslint-config-mongodb-js": "^5.0.3",
"eslint-plugin-react": "^7.19.0",
Expand Down
29 changes: 29 additions & 0 deletions scripts/generate-keyfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#! /usr/bin/env ts-node

import ora = require('ora');
import fs = require('fs');
import path = require('path');
import { resolve } from 'path';
import { config } from 'dotenv';

const { promisify } = require('util');
const writeFile = promisify(fs.writeFile);
const ROOT_DIR = path.join(__dirname, '..');
const ui = ora('Generate constants keyfile').start();

config({ path: resolve(__dirname, '../.env') });

(async () => {
if (process.env.SEGMENT_KEY) {
await writeFile(
`${ROOT_DIR}/constants.json`,
JSON.stringify({ segmentKey: process.env.SEGMENT_KEY }, null, 2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just clarifying so I understand - Is the reason for creating the constants.json file so that we can use it in the built extension?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid storing segment key on git, we keep il locally in .env file, that is not being pushed to git, and during the compilation process, we generate constants.json file with this key injected. The constants.json file is also added to .gitignore, so the key exists only on the local machine.

To publish vscode extension or to build a package locally we use vsce command-line tool, sort of npm publish for vscode, that require the compilation step as well, therefore the build will also include constants.json file.

When we run tests on Azure, we don't have access to .env file that is stored on our computer, therefore to get constants.json generated there, I use Azure Pipeline variable that I pass to npm test script in azure-pipelines.yml.

I think later when we will have automatic publishing using CI we can get rid of .env file and pass a the same azure variable to deploy script. Since we don't publish to the marketplace yet, and I can't test how this key injection will work, I have this intermediate solution.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we can keep .env, in any case, if we want to continue building packages locally, what also can be useful.

);
ui.succeed('Generated .constants.json');
} else {
await Promise.reject(new Error('The Segment key is missing in environment variables'));
}
})().catch((error) => {
ui.fail('Failed to generate constants keyfile');
console.log(error);
})
13 changes: 7 additions & 6 deletions scripts/update-grammar.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#! /usr/bin/env ts-node

const path = require('path');
const download = require('download');
const ora = require('ora');
const meow = require('meow');
const mkdirp = require('mkdirp');
import path = require('path');
import mkdirp = require('mkdirp');
import ora = require('ora');
import download = require('download');
import meow = require('meow');

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

Expand Down Expand Up @@ -45,10 +45,11 @@ const cli = meow(
const ui = ora()
.info('Downlading latest mongodb.tmLanguage.json')
.start();

try {
await download(cli.flags.url, cli.flags.dest);
ui.succeed(
`Downloaded to ${path.join(cli.flags.dest, 'mongodb.tmLanguage.json')}`
`Downloaded to ${path.join(cli.flags.dest as string, 'mongodb.tmLanguage.json')}`
);
} catch (err) {
ui.fail(`Download failed: ${err.message}`);
Expand Down
14 changes: 6 additions & 8 deletions scripts/update-snippets.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#! /usr/bin/env ts-node

const fs = require('fs');
import path = require('path');
import mkdirp = require('mkdirp');
import ora = require('ora');
import fs = require('fs');

const { promisify } = require('util');
const writeFile = promisify(fs.writeFile);

const path = require('path');
const mkdirp = require('mkdirp');
const ora = require('ora');

const { STAGE_OPERATORS } = require('mongodb-ace-autocompleter');
const config = require(path.join(__dirname, '..', 'package.json'));
const SNIPPETS_DIR = path.join(__dirname, '..', 'snippets');

/**
Expand Down Expand Up @@ -75,9 +73,9 @@ const snippets = STAGE_OPERATORS.reduce(

(async () => {
const ui = ora('Update snippets').start();

ui.info(`Create the ${SNIPPETS_DIR} folder`);
await mkdirp(SNIPPETS_DIR);

await writeFile(
`${SNIPPETS_DIR}/stage-autocompleter.json`,
JSON.stringify(snippets, null, 2)
Expand Down
Loading