Skip to content

Integrate tslint #185

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 8 commits into from
Jul 9, 2018
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
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
77 changes: 19 additions & 58 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
"version": "0.1.0",
"configurations": [
{
"name": "launch as server",
"name": "Launch as server",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/out/debug-adapter/nativeScriptDebug.js",
"runtimeArgs": ["--nolazy"],
"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 executablensDebugClient
Expand All @@ -24,61 +24,22 @@
],
"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
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@
},
"devDependencies": {
"@types/lodash": "^4.14.109",
"@types/mocha": "2.2.41",
"@types/mocha": "^5.2.1",
"@types/node": "6.0.46",
"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": {
Expand All @@ -50,9 +52,8 @@
"package": "vsce package",
"full-build": "npm run clean && npm install && npm run build && npm run package",
"launch-as-server": "node --nolazy ./out/debug-adapter/nativeScriptDebug.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"
"test": "mocha --opts ./src/tests/config/mocha.opts",
"tslint": "tslint -p ./src/tsconfig.json -c tslint.json"
},
"main": "./out/main",
"activationEvents": [
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;
}
96 changes: 53 additions & 43 deletions src/analytics/analyticsService.ts
Original file line number Diff line number Diff line change
@@ -1,81 +1,91 @@
import * as os from 'os';
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, cliVersion: string, extensionVersion: string) {
constructor(globalState: vscode.Memento, cliVersion: string, extensionVersion: string, logger: ILogger) {
this._globalState = globalState;
this._logger = logger;

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

this._baseInfo = {
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 @@ -86,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);
}
}
}
}
22 changes: 13 additions & 9 deletions src/analytics/guaService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as ua from 'universal-analytics';
import { AnalyticsBaseInfo, OperatingSystem } from './analyticsBaseInfo';
import { IAnalyticsBaseInfo, OperatingSystem } from './analyticsBaseInfo';

/**
* Google Universal Analytics Service
Expand All @@ -8,38 +8,42 @@ export class GUAService {
private _visitor: any;
private _getBasePayload: () => any;

constructor(trackingId: string, baseInfo: AnalyticsBaseInfo) {
constructor(trackingId: string, baseInfo: IAnalyticsBaseInfo) {
this._visitor = ua(trackingId, baseInfo.clientId, { requestOptions: {}, strictCidFormat: false });
this._getBasePayload = () => {
return {
cid: baseInfo.clientId,
dh: 'ns-vs-extension.org',
cd5: baseInfo.cliVersion,
cd6: OperatingSystem[baseInfo.operatingSystem],
cd7: baseInfo.extensionVersion
cd7: baseInfo.extensionVersion,
cid: baseInfo.clientId,
dh: 'ns-vs-extension.org',
};
};
}

public launchDebugger(request: string, platform: string): Promise<any> {
let payload = this._getBasePayload();
const payload = this._getBasePayload();

payload.ec = 'vscode-extension-debug'; // event category
payload.ea = `debug-${request}-on-${platform}`; // event action

return this.sendEvent(payload);
}

public runRunCommand(platform: string): Promise<any> {
let payload = this._getBasePayload();
const payload = this._getBasePayload();

payload.ec = 'vscode-extension-command'; // event category
payload.ea = `command-run-on-${platform}`; // event action

return this.sendEvent(payload);
}

private sendEvent(params): Promise<any> {
return new Promise<any>((res, rej) => {
this._visitor.event(params, err => {
this._visitor.event(params, (err) => {
return err ? rej(err) : res();
});
});
}
}
}
Loading