-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathmain.ts
90 lines (75 loc) · 3.54 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import * as vscode from 'vscode';
import {CliVersion} from './project/nativeScriptCli';
import {Services} from './services/extensionHostServices';
import {Project} from './project/project';
import {IosProject} from './project/iosProject';
import {AndroidProject} from './project/androidProject';
import * as utils from './common/utilities';
// this method is called when the extension is activated
export function activate(context: vscode.ExtensionContext) {
Services.globalState = context.globalState;
Services.cliPath = Services.workspaceConfigService().tnsPath || Services.cliPath;
Services.extensionServer().start();
Services.analyticsService().initialize();
// Check if NativeScript CLI is installed globally and if it is compatible with the extension version
let cliVersion = Services.cli().version;
if (!cliVersion.isCompatible) {
vscode.window.showErrorMessage(cliVersion.errorMessage);
}
let channel = createInfoChannel(cliVersion.version.toString());
let showOutputChannelCommand = vscode.commands.registerCommand('nativescript.showOutputChannel', () => {
channel.show();
});
let runCommand = (project: Project) => {
if (vscode.workspace.rootPath === undefined) {
vscode.window.showErrorMessage('No workspace opened.');
return;
}
// Show output channel
let runChannel: vscode.OutputChannel = vscode.window.createOutputChannel(`Run on ${project.platformName()}`);
runChannel.clear();
runChannel.show(vscode.ViewColumn.Two);
Services.analyticsService().runRunCommand(project.platformName());
let tnsProcess = project.run();
tnsProcess.on('error', err => {
vscode.window.showErrorMessage('Unexpected error executing NativeScript Run command.');
});
tnsProcess.stderr.on('data', data => {
runChannel.append(data.toString());
});
tnsProcess.stdout.on('data', data => {
runChannel.append(data.toString());
});
tnsProcess.on('exit', exitCode => {
tnsProcess.stdout.removeAllListeners('data');
tnsProcess.stderr.removeAllListeners('data');
});
tnsProcess.on('close', exitCode => {
runChannel.hide();
});
context.subscriptions.push({
dispose: () => utils.killProcess(tnsProcess)
});
};
let runIosCommand = vscode.commands.registerCommand('nativescript.runIos', () => {
return runCommand(new IosProject(vscode.workspace.rootPath, Services.cli()));
});
let runAndroidCommand = vscode.commands.registerCommand('nativescript.runAndroid', () => {
return runCommand(new AndroidProject(vscode.workspace.rootPath, Services.cli()));
});
context.subscriptions.push(runIosCommand);
context.subscriptions.push(runAndroidCommand);
context.subscriptions.push(showOutputChannelCommand);
}
function createInfoChannel(cliVersion: string): vscode.OutputChannel {
let channel = vscode.window.createOutputChannel("NativeScript Extension");
const packageJSON = vscode.extensions.getExtension("Telerik.nativescript").packageJSON;
packageJSON.version && channel.appendLine(`Version: ${packageJSON.version}`);
packageJSON.buildVersion && channel.appendLine(`Build version: ${packageJSON.buildVersion}`);
packageJSON.commitId && channel.appendLine(`Commit id: ${packageJSON.commitId}`);
channel.appendLine(`NativeScript CLI: ${cliVersion}`);
return channel;
}
export function deactivate() {
Services.extensionServer().stop();
}