Skip to content

Commit 2906826

Browse files
authored
Merge pull request #185 from NativeScript/iiivanov/integrate-tslint-2
Integrate tslint
2 parents a42a2b8 + 36a9f83 commit 2906826

File tree

79 files changed

+947
-1937
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+947
-1937
lines changed

.travis.yml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
language: node_js
2+
3+
node_js:
4+
- "8.0"
5+
6+
script:
7+
- npm run build
8+
- npm test
9+
- npm run tslint

.vscode/launch.json

+19-58
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
"version": "0.1.0",
33
"configurations": [
44
{
5-
"name": "launch as server",
5+
"name": "Launch as server",
66
"type": "node",
77
"request": "launch",
88
"program": "${workspaceRoot}/out/debug-adapter/nativeScriptDebug.js",
9-
"runtimeArgs": ["--nolazy"],
9+
"runtimeArgs": ["--nolazy"],
1010
"args": [ "--server=4712" ],
1111
"stopOnEntry": false,
1212
"sourceMaps": true,
1313
"outFiles": [ "${workspaceFolder}/out/**/*.js" ],
1414
"cwd": "${workspaceFolder}"
1515
},
1616
{
17-
"name": "launch in extension host",
17+
"name": "Launch in extension host",
1818
"type": "extensionHost",
1919
"request": "launch",
2020
// Path to VSCode executablensDebugClient
@@ -24,61 +24,22 @@
2424
],
2525
"stopOnEntry": false,
2626
"sourceMaps": true,
27-
"outFiles": [ "${workspaceFolder}/out/**/*.js" ],
27+
"outFiles": [ "${workspaceFolder}/out/**/*.js" ]
2828
},
29-
{
30-
"name": "run tests on mac",
31-
"type": "node",
32-
"request": "launch",
33-
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
34-
"runtimeArgs": [ "--nolazy" ],
35-
"args": [
36-
"--opts", "${workspaceRoot}/src/tests/config/mocha.opts",
37-
"--config", "${workspaceRoot}/src/tests/config/mac.json",
38-
"${workspaceRoot}/out/tests/"
39-
],
40-
"stopOnEntry": false,
41-
"sourceMaps": true,
42-
"outDir": "${workspaceRoot}/out",
43-
"cwd": "${workspaceRoot}"
44-
},
45-
{
46-
"name": "run tests on win",
47-
"type": "node",
48-
"request": "launch",
49-
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
50-
"runtimeArgs": [ "--nolazy" ],
51-
"args": [
52-
"--opts", "${workspaceRoot}/src/tests/config/mocha.opts",
53-
"--config", "${workspaceRoot}/src/tests/config/win.json",
54-
"${workspaceRoot}/out/tests/"
55-
],
56-
"stopOnEntry": false,
57-
"sourceMaps": true,
58-
"outDir": "${workspaceRoot}/out",
59-
"cwd": "${workspaceRoot}"
60-
},
61-
{
62-
"name": "run tests (custom)",
63-
"type": "node",
64-
"request": "launch",
65-
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
66-
"runtimeArgs": [ "--nolazy" ],
67-
"args": [
68-
"--opts", "${workspaceRoot}/src/tests/config/mocha.opts",
69-
"--config", "${workspaceRoot}/src/tests/config/custom.json",
70-
"${workspaceRoot}/out/tests/"
71-
],
72-
"stopOnEntry": false,
73-
"sourceMaps": true,
74-
"outDir": "${workspaceRoot}/out",
75-
"cwd": "${workspaceRoot}"
76-
}
29+
{
30+
"name": "Run tests",
31+
"type": "node",
32+
"request": "launch",
33+
"runtimeExecutable": "npm",
34+
"runtimeArgs": [
35+
"run", "test", "--"
36+
]
37+
}
7738
],
78-
"compounds": [
79-
{
80-
"name": "Extension + Server",
81-
"configurations": [ "launch in extension host", "launch as server" ]
82-
}
83-
]
39+
"compounds": [
40+
{
41+
"name": "Extension + Server",
42+
"configurations": [ "Launch in extension host", "Launch as server" ]
43+
}
44+
]
8445
}

.vscode/settings.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"editor.insertSpaces": true,
33
"files.trimTrailingWhitespace": true,
4+
"editor.renderWhitespace": "all",
45
"files.exclude": {
56
".git": true,
67
"bin": true,

package.json

+7-6
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@
3434
},
3535
"devDependencies": {
3636
"@types/lodash": "^4.14.109",
37-
"@types/mocha": "2.2.41",
37+
"@types/mocha": "^5.2.1",
3838
"@types/node": "6.0.46",
39-
"mocha": "2.5.3",
39+
"mocha": "^5.2.0",
40+
"sinon": "^5.0.10",
41+
"tslint": "5.10.0",
42+
"tslint-eslint-rules": "^5.3.1",
4043
"typescript": "2.6.2",
4144
"vsce": "~1.36.0",
4245
"vscode": "~1.1.10",
43-
"vscode-debugadapter-testsupport": "1.26.0",
4446
"vscode-debugprotocol": "^1.28.0-pre.1"
4547
},
4648
"scripts": {
@@ -50,9 +52,8 @@
5052
"package": "vsce package",
5153
"full-build": "npm run clean && npm install && npm run build && npm run package",
5254
"launch-as-server": "node --nolazy ./out/debug-adapter/nativeScriptDebug.js --server=4712",
53-
"test-mac": "mocha --opts ./src/tests/config/mocha.opts --config ../../src/tests/config/mac.json ./out/tests",
54-
"test-win": "mocha --opts ./src/tests/config/mocha.opts --config ../../src/tests/config/win.json ./out/tests",
55-
"test-custom": "mocha --opts ./src/tests/config/mocha.opts --config ../../src/tests/config/custom.json ./out/tests"
55+
"test": "mocha --opts ./src/tests/config/mocha.opts",
56+
"tslint": "tslint -p ./src/tsconfig.json -c tslint.json"
5657
},
5758
"main": "./out/main",
5859
"activationEvents": [

src/analytics/analyticsBaseInfo.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ export enum OperatingSystem {
22
Windows,
33
Linux,
44
OSX,
5-
Other
5+
Other,
66
}
77

8-
export interface AnalyticsBaseInfo {
9-
operatingSystem: OperatingSystem,
10-
cliVersion: string,
11-
extensionVersion: string,
12-
clientId: string
13-
}
8+
export interface IAnalyticsBaseInfo {
9+
operatingSystem: OperatingSystem;
10+
cliVersion: string;
11+
extensionVersion: string;
12+
clientId: string;
13+
}

src/analytics/analyticsService.ts

+53-43
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,91 @@
1-
import * as os from 'os';
2-
import { GUAService } from './guaService';
3-
import { AnalyticsBaseInfo, OperatingSystem } from './analyticsBaseInfo';
4-
import { Services } from '../services/extensionHostServices';
5-
import * as utils from '../common/utilities';
1+
import * as _ from 'lodash';
2+
import * as uuid from 'uuid';
63
import * as vscode from 'vscode';
7-
import * as uuid from "uuid";
4+
import { ILogger } from '../common/logger';
5+
import { services } from '../services/extensionHostServices';
6+
import { IAnalyticsBaseInfo, OperatingSystem } from './analyticsBaseInfo';
7+
import { GUAService } from './guaService';
88

99
export class AnalyticsService {
10-
private static HAS_ANALYTICS_PROMPT_SHOWN_KEY = "nativescript.hasAnalyticsPromptShown";
11-
private static CLIENT_ID_KEY = "nativescript.analyticsClientId";
10+
private static HAS_ANALYTICS_PROMPT_SHOWN_KEY = 'nativescript.hasAnalyticsPromptShown';
11+
private static CLIENT_ID_KEY = 'nativescript.analyticsClientId';
12+
private static DOCS_LINK = 'https://github.com/NativeScript/nativescript-vscode-extension/blob/master/README.md#how-to-disable-the-analytics';
1213
private static ANALYTICS_PROMPT_MESSAGE = `Help us improve the NativeScript extension by allowing Progress to collect anonymous usage data.
13-
For more information about the gathered information and how it is used, read our [privacy statement](https://www.progress.com/legal/privacy-policy).
14-
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.
14+
For more information about the gathered information and how it is used,
15+
read our [privacy statement](https://www.progress.com/legal/privacy-policy).
16+
You can [disable the analytics and data collection](${AnalyticsService.DOCS_LINK}) at any given time.
1517
Do you want to enable analytics?`;
16-
private static ANALYTICS_PROMPT_ACCEPT_ACTION = "Yes";
17-
private static ANALYTICS_PROMPT_DENY_ACTION = "No";
18+
19+
private static ANALYTICS_PROMPT_ACCEPT_ACTION = 'Yes';
20+
private static ANALYTICS_PROMPT_DENY_ACTION = 'No';
21+
22+
private static getOperatingSystem(): OperatingSystem {
23+
switch (process.platform) {
24+
case 'win32':
25+
return OperatingSystem.Windows;
26+
case 'darwin':
27+
return OperatingSystem.OSX;
28+
case 'linux':
29+
case 'freebsd':
30+
return OperatingSystem.Linux;
31+
default:
32+
return OperatingSystem.Other;
33+
}
34+
}
1835

1936
private _globalState: vscode.Memento;
20-
private _baseInfo: AnalyticsBaseInfo;
37+
private _logger: ILogger;
38+
private _baseInfo: IAnalyticsBaseInfo;
2139
private _gua: GUAService;
2240
private _analyticsEnabled: boolean;
2341

24-
constructor(globalState: vscode.Memento, cliVersion: string, extensionVersion: string) {
42+
constructor(globalState: vscode.Memento, cliVersion: string, extensionVersion: string, logger: ILogger) {
2543
this._globalState = globalState;
44+
this._logger = logger;
2645

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

2948
this._baseInfo = {
3049
cliVersion,
50+
clientId: this.getOrGenerateClientId(),
3151
extensionVersion,
3252
operatingSystem: AnalyticsService.getOperatingSystem(),
33-
clientId: this.getOrGenerateClientId()
3453
};
3554
}
3655

3756
public launchDebugger(request: string, platform: string): Promise<any> {
38-
if(this._analyticsEnabled) {
57+
if (this._analyticsEnabled) {
3958
try {
4059
return this._gua.launchDebugger(request, platform);
41-
} catch(e) {}
60+
} catch (e) {
61+
this._logger.log(`Analytics error: ${_.isString(e) ? e : e.message}`);
62+
}
4263
}
4364

4465
return Promise.resolve();
4566
}
4667

4768
public runRunCommand(platform: string): Promise<any> {
48-
if(this._analyticsEnabled) {
69+
if (this._analyticsEnabled) {
4970
try {
5071
return this._gua.runRunCommand(platform);
51-
} catch(e) { }
72+
} catch (e) {
73+
this._logger.log(`Analytics error: ${_.isString(e) ? e : e.message}`);
74+
}
5275
}
5376

5477
return Promise.resolve();
5578
}
5679

57-
private static getOperatingSystem() : OperatingSystem {
58-
switch(process.platform) {
59-
case 'win32':
60-
return OperatingSystem.Windows;
61-
case 'darwin':
62-
return OperatingSystem.OSX;
63-
case 'linux':
64-
case 'freebsd':
65-
return OperatingSystem.Linux;
66-
default:
67-
return OperatingSystem.Other;
68-
};
69-
}
70-
71-
public initialize() : void {
80+
public initialize(): void {
7281
const hasAnalyticsPromptShown = this._globalState.get<boolean>(AnalyticsService.HAS_ANALYTICS_PROMPT_SHOWN_KEY);
73-
if(!hasAnalyticsPromptShown) {
82+
83+
if (!hasAnalyticsPromptShown) {
7484
vscode.window.showInformationMessage(AnalyticsService.ANALYTICS_PROMPT_MESSAGE,
7585
AnalyticsService.ANALYTICS_PROMPT_ACCEPT_ACTION,
76-
AnalyticsService.ANALYTICS_PROMPT_DENY_ACTION
86+
AnalyticsService.ANALYTICS_PROMPT_DENY_ACTION,
7787
)
78-
.then(result => this.onAnalyticsMessageConfirmation(result));
88+
.then((result) => this.onAnalyticsMessageConfirmation(result));
7989

8090
return;
8191
}
@@ -86,28 +96,28 @@ export class AnalyticsService {
8696
private getOrGenerateClientId(): string {
8797
let clientId = this._globalState.get<string>(AnalyticsService.CLIENT_ID_KEY);
8898

89-
if(!clientId) {
99+
if (!clientId) {
90100
clientId = uuid.v4();
91101
this._globalState.update(AnalyticsService.CLIENT_ID_KEY, clientId);
92102
}
93103

94104
return clientId;
95105
}
96106

97-
private onAnalyticsMessageConfirmation(result: string) : void {
107+
private onAnalyticsMessageConfirmation(result: string): void {
98108
const shouldEnableAnalytics = result === AnalyticsService.ANALYTICS_PROMPT_ACCEPT_ACTION ? true : false;
99109

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

102-
Services.workspaceConfigService.isAnalyticsEnabled = shouldEnableAnalytics;
112+
services.workspaceConfigService.isAnalyticsEnabled = shouldEnableAnalytics;
103113
this.updateAnalyticsEnabled();
104114
}
105115

106116
private updateAnalyticsEnabled() {
107-
this._analyticsEnabled = Services.workspaceConfigService.isAnalyticsEnabled;
117+
this._analyticsEnabled = services.workspaceConfigService.isAnalyticsEnabled;
108118

109-
if(this._analyticsEnabled && !this._gua) {
119+
if (this._analyticsEnabled && !this._gua) {
110120
this._gua = new GUAService('UA-111455-29', this._baseInfo);
111121
}
112122
}
113-
}
123+
}

src/analytics/guaService.ts

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as ua from 'universal-analytics';
2-
import { AnalyticsBaseInfo, OperatingSystem } from './analyticsBaseInfo';
2+
import { IAnalyticsBaseInfo, OperatingSystem } from './analyticsBaseInfo';
33

44
/**
55
* Google Universal Analytics Service
@@ -8,38 +8,42 @@ export class GUAService {
88
private _visitor: any;
99
private _getBasePayload: () => any;
1010

11-
constructor(trackingId: string, baseInfo: AnalyticsBaseInfo) {
11+
constructor(trackingId: string, baseInfo: IAnalyticsBaseInfo) {
1212
this._visitor = ua(trackingId, baseInfo.clientId, { requestOptions: {}, strictCidFormat: false });
1313
this._getBasePayload = () => {
1414
return {
15-
cid: baseInfo.clientId,
16-
dh: 'ns-vs-extension.org',
1715
cd5: baseInfo.cliVersion,
1816
cd6: OperatingSystem[baseInfo.operatingSystem],
19-
cd7: baseInfo.extensionVersion
17+
cd7: baseInfo.extensionVersion,
18+
cid: baseInfo.clientId,
19+
dh: 'ns-vs-extension.org',
2020
};
2121
};
2222
}
2323

2424
public launchDebugger(request: string, platform: string): Promise<any> {
25-
let payload = this._getBasePayload();
25+
const payload = this._getBasePayload();
26+
2627
payload.ec = 'vscode-extension-debug'; // event category
2728
payload.ea = `debug-${request}-on-${platform}`; // event action
29+
2830
return this.sendEvent(payload);
2931
}
3032

3133
public runRunCommand(platform: string): Promise<any> {
32-
let payload = this._getBasePayload();
34+
const payload = this._getBasePayload();
35+
3336
payload.ec = 'vscode-extension-command'; // event category
3437
payload.ea = `command-run-on-${platform}`; // event action
38+
3539
return this.sendEvent(payload);
3640
}
3741

3842
private sendEvent(params): Promise<any> {
3943
return new Promise<any>((res, rej) => {
40-
this._visitor.event(params, err => {
44+
this._visitor.event(params, (err) => {
4145
return err ? rej(err) : res();
4246
});
4347
});
4448
}
45-
}
49+
}

0 commit comments

Comments
 (0)