Skip to content

Use chrome-debug-adapter-core #181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jul 17, 2018
Merged
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
language: node_js

node_js:
- "8.0"

script:
- npm run build
- npm test
- npm run tslint
81 changes: 21 additions & 60 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,83 +2,44 @@
"version": "0.1.0",
"configurations": [
{
"name": "launch as server",
"name": "Launch as server",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/out/debug-adapter/webKitDebug.js",
"runtimeArgs": ["--nolazy"],
"program": "${workspaceRoot}/out/debug-adapter/nativeScriptDebug.js",
"runtimeArgs": ["--nolazy"],
"args": [ "--server=4712" ],
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": [ "${workspaceFolder}/out/**/*.js" ],
"cwd": "${workspaceFolder}"
},
{
"name": "launch in extension host",
"name": "Launch in extension host",
"type": "extensionHost",
"request": "launch",
// Path to VSCode executable
// Path to VSCode executablensDebugClient
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceRoot}"
],
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": [ "${workspaceFolder}/out/**/*.js" ],
"outFiles": [ "${workspaceFolder}/out/**/*.js" ]
},
{
"name": "run tests on mac",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"runtimeArgs": [ "--nolazy" ],
"args": [
"--opts", "${workspaceRoot}/src/tests/config/mocha.opts",
"--config", "${workspaceRoot}/src/tests/config/mac.json",
"${workspaceRoot}/out/tests/"
],
"stopOnEntry": false,
"sourceMaps": true,
"outDir": "${workspaceRoot}/out",
"cwd": "${workspaceRoot}"
},
{
"name": "run tests on win",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"runtimeArgs": [ "--nolazy" ],
"args": [
"--opts", "${workspaceRoot}/src/tests/config/mocha.opts",
"--config", "${workspaceRoot}/src/tests/config/win.json",
"${workspaceRoot}/out/tests/"
],
"stopOnEntry": false,
"sourceMaps": true,
"outDir": "${workspaceRoot}/out",
"cwd": "${workspaceRoot}"
},
{
"name": "run tests (custom)",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"runtimeArgs": [ "--nolazy" ],
"args": [
"--opts", "${workspaceRoot}/src/tests/config/mocha.opts",
"--config", "${workspaceRoot}/src/tests/config/custom.json",
"${workspaceRoot}/out/tests/"
],
"stopOnEntry": false,
"sourceMaps": true,
"outDir": "${workspaceRoot}/out",
"cwd": "${workspaceRoot}"
}
{
"name": "Run tests",
"type": "node",
"request": "launch",
"runtimeExecutable": "npm",
"runtimeArgs": [
"run", "test", "--"
]
}
],
"compounds": [
{
"name": "Extension + Server",
"configurations": [ "launch in extension host", "launch as server" ]
}
]
"compounds": [
{
"name": "Extension + Server",
"configurations": [ "Launch in extension host", "Launch as server" ]
}
]
}
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"editor.insertSpaces": true,
"files.trimTrailingWhitespace": true,
"editor.renderWhitespace": "all",
"files.exclude": {
".git": true,
"bin": true,
Expand Down
31 changes: 15 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,35 @@
],
"license": "SEE LICENSE IN LICENSE.txt",
"dependencies": {
"node-ipc": "8.10.3",
"source-map": "0.6.1",
"lodash": "^4.17.10",
"semver": "^5.5.0",
"universal-analytics": "0.4.13",
"uuid": "^3.2.1",
"vscode-chrome-debug-core": "~3.9.0",
"vscode-debugadapter": "1.26.0",
"vscode-debugprotocol": "1.26.0",
"xmlhttprequest": "https://github.com/telerik/node-XMLHttpRequest/tarball/master"
"vscode-chrome-debug-core": "^3.23.11",
"vscode-debugadapter": "^1.28.0-pre.2"
},
"devDependencies": {
"@types/mocha": "2.2.41",
"@types/lodash": "^4.14.109",
"@types/mocha": "^5.2.1",
"@types/node": "6.0.46",
"@types/source-map": "~0.1.0",
"chrome-remote-debug-protocol": "https://github.com/roblourens/chrome-remote-debug-protocol/tarball/master",
"mocha": "2.5.3",
"mocha": "^5.2.0",
"sinon": "^5.0.10",
"tslint": "5.10.0",
"tslint-eslint-rules": "^5.3.1",
"typescript": "2.6.2",
"vsce": "~1.36.0",
"vscode": "~1.1.10",
"vscode-debugadapter-testsupport": "1.26.0"
"vscode-debugprotocol": "^1.28.0-pre.1"
},
"scripts": {
"clean": "git clean -fdx",
"postinstall": "node ./node_modules/vscode/bin/install",
"build": "tsc -p ./src",
"package": "vsce package",
"full-build": "npm run clean && npm install && npm run build && npm run package",
"launch-as-server": "node --nolazy ./out/debug-adapter/webKitDebug.js --server=4712",
"test-mac": "mocha --opts ./src/tests/config/mocha.opts --config ../../src/tests/config/mac.json ./out/tests",
"test-win": "mocha --opts ./src/tests/config/mocha.opts --config ../../src/tests/config/win.json ./out/tests",
"test-custom": "mocha --opts ./src/tests/config/mocha.opts --config ../../src/tests/config/custom.json ./out/tests"
"launch-as-server": "node --nolazy ./out/debug-adapter/nativeScriptDebug.js --server=4712",
"test": "mocha --opts ./src/tests/config/mocha.opts",
"tslint": "tslint -p ./src/tsconfig.json -c tslint.json"
},
"main": "./out/main",
"activationEvents": [
Expand Down Expand Up @@ -129,7 +128,7 @@
"typescript"
]
},
"program": "./out/debug-adapter/webKitDebug.js",
"program": "./out/debug-adapter/nativeScriptDebug.js",
"runtime": "node",
"initialConfigurations": [
{
Expand Down
14 changes: 7 additions & 7 deletions src/analytics/analyticsBaseInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ export enum OperatingSystem {
Windows,
Linux,
OSX,
Other
Other,
}

export interface AnalyticsBaseInfo {
operatingSystem: OperatingSystem,
cliVersion: string,
extensionVersion: string,
clientId: string
}
export interface IAnalyticsBaseInfo {
operatingSystem: OperatingSystem;
cliVersion: string;
extensionVersion: string;
clientId: string;
}
101 changes: 55 additions & 46 deletions src/analytics/analyticsService.ts
Original file line number Diff line number Diff line change
@@ -1,82 +1,91 @@
import * as os from 'os';
import { Version } from '../common/version';
import { GUAService } from './guaService';
import { AnalyticsBaseInfo, OperatingSystem } from './analyticsBaseInfo';
import { Services } from '../services/extensionHostServices';
import * as utils from '../common/utilities';
import * as _ from 'lodash';
import * as uuid from 'uuid';
import * as vscode from 'vscode';
import * as uuid from "uuid";
import { ILogger } from '../common/logger';
import { services } from '../services/extensionHostServices';
import { IAnalyticsBaseInfo, OperatingSystem } from './analyticsBaseInfo';
import { GUAService } from './guaService';

export class AnalyticsService {
private static HAS_ANALYTICS_PROMPT_SHOWN_KEY = "nativescript.hasAnalyticsPromptShown";
private static CLIENT_ID_KEY = "nativescript.analyticsClientId";
private static HAS_ANALYTICS_PROMPT_SHOWN_KEY = 'nativescript.hasAnalyticsPromptShown';
private static CLIENT_ID_KEY = 'nativescript.analyticsClientId';
private static DOCS_LINK = 'https://github.com/NativeScript/nativescript-vscode-extension/blob/master/README.md#how-to-disable-the-analytics';
private static ANALYTICS_PROMPT_MESSAGE = `Help us improve the NativeScript extension by allowing Progress to collect anonymous usage data.
For more information about the gathered information and how it is used, read our [privacy statement](https://www.progress.com/legal/privacy-policy).
You can [disable the analytics and data collection](https://github.com/NativeScript/nativescript-vscode-extension/blob/master/README.md#how-to-disable-the-analytics) at any given time.
For more information about the gathered information and how it is used,
read our [privacy statement](https://www.progress.com/legal/privacy-policy).
You can [disable the analytics and data collection](${AnalyticsService.DOCS_LINK}) at any given time.
Do you want to enable analytics?`;
private static ANALYTICS_PROMPT_ACCEPT_ACTION = "Yes";
private static ANALYTICS_PROMPT_DENY_ACTION = "No";

private static ANALYTICS_PROMPT_ACCEPT_ACTION = 'Yes';
private static ANALYTICS_PROMPT_DENY_ACTION = 'No';

private static getOperatingSystem(): OperatingSystem {
switch (process.platform) {
case 'win32':
return OperatingSystem.Windows;
case 'darwin':
return OperatingSystem.OSX;
case 'linux':
case 'freebsd':
return OperatingSystem.Linux;
default:
return OperatingSystem.Other;
}
}

private _globalState: vscode.Memento;
private _baseInfo: AnalyticsBaseInfo;
private _logger: ILogger;
private _baseInfo: IAnalyticsBaseInfo;
private _gua: GUAService;
private _analyticsEnabled: boolean;

constructor(globalState: vscode.Memento) {
constructor(globalState: vscode.Memento, cliVersion: string, extensionVersion: string, logger: ILogger) {
this._globalState = globalState;
this._logger = logger;

vscode.workspace.onDidChangeConfiguration(() => this.updateAnalyticsEnabled());

this._baseInfo = {
cliVersion: Services.cli().version.toString(),
extensionVersion: utils.getInstalledExtensionVersion().toString(),
cliVersion,
clientId: this.getOrGenerateClientId(),
extensionVersion,
operatingSystem: AnalyticsService.getOperatingSystem(),
clientId: this.getOrGenerateClientId()
};
}

public launchDebugger(request: string, platform: string): Promise<any> {
if(this._analyticsEnabled) {
if (this._analyticsEnabled) {
try {
return this._gua.launchDebugger(request, platform);
} catch(e) {}
} catch (e) {
this._logger.log(`Analytics error: ${_.isString(e) ? e : e.message}`);
}
}

return Promise.resolve();
}

public runRunCommand(platform: string): Promise<any> {
if(this._analyticsEnabled) {
if (this._analyticsEnabled) {
try {
return this._gua.runRunCommand(platform);
} catch(e) { }
} catch (e) {
this._logger.log(`Analytics error: ${_.isString(e) ? e : e.message}`);
}
}

return Promise.resolve();
}

private static getOperatingSystem() : OperatingSystem {
switch(process.platform) {
case 'win32':
return OperatingSystem.Windows;
case 'darwin':
return OperatingSystem.OSX;
case 'linux':
case 'freebsd':
return OperatingSystem.Linux;
default:
return OperatingSystem.Other;
};
}

public initialize() : void {
public initialize(): void {
const hasAnalyticsPromptShown = this._globalState.get<boolean>(AnalyticsService.HAS_ANALYTICS_PROMPT_SHOWN_KEY);
if(!hasAnalyticsPromptShown) {

if (!hasAnalyticsPromptShown) {
vscode.window.showInformationMessage(AnalyticsService.ANALYTICS_PROMPT_MESSAGE,
AnalyticsService.ANALYTICS_PROMPT_ACCEPT_ACTION,
AnalyticsService.ANALYTICS_PROMPT_DENY_ACTION
AnalyticsService.ANALYTICS_PROMPT_DENY_ACTION,
)
.then(result => this.onAnalyticsMessageConfirmation(result));
.then((result) => this.onAnalyticsMessageConfirmation(result));

return;
}
Expand All @@ -87,28 +96,28 @@ export class AnalyticsService {
private getOrGenerateClientId(): string {
let clientId = this._globalState.get<string>(AnalyticsService.CLIENT_ID_KEY);

if(!clientId) {
if (!clientId) {
clientId = uuid.v4();
this._globalState.update(AnalyticsService.CLIENT_ID_KEY, clientId);
}

return clientId;
}

private onAnalyticsMessageConfirmation(result: string) : void {
private onAnalyticsMessageConfirmation(result: string): void {
const shouldEnableAnalytics = result === AnalyticsService.ANALYTICS_PROMPT_ACCEPT_ACTION ? true : false;

this._globalState.update(AnalyticsService.HAS_ANALYTICS_PROMPT_SHOWN_KEY, true);

Services.workspaceConfigService().isAnalyticsEnabled = shouldEnableAnalytics;
services.workspaceConfigService.isAnalyticsEnabled = shouldEnableAnalytics;
this.updateAnalyticsEnabled();
}

private updateAnalyticsEnabled() {
this._analyticsEnabled = Services.workspaceConfigService().isAnalyticsEnabled;
this._analyticsEnabled = services.workspaceConfigService.isAnalyticsEnabled;

if(this._analyticsEnabled && !this._gua) {
if (this._analyticsEnabled && !this._gua) {
this._gua = new GUAService('UA-111455-29', this._baseInfo);
}
}
}
}
Loading