forked from felixrieseberg/vsc-travis-ci-status
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.ts
62 lines (51 loc) · 1.86 KB
/
extension.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
import {window, commands, workspace} from 'vscode';
import TravisStatusIndicator from './travis-status';
var indicator, proxySetup, proxyData;
export function activate() {
// Create File System Watcher
let watcher = workspace.createFileSystemWatcher('.travis.yml', false, false, true);
watcher.onDidChange((e) => updateStatus());
watcher.onDidCreate((e) => updateStatus());
// Register Commands
commands.registerCommand('extension.updateTravis', () => updateStatus());
commands.registerCommand('extension.openInTravis', () => openInTravis());
// Check if file already present
workspace.findFiles('.travis.yml', '', 1).then((result) => {
if (result && result.length > 0) {
updateStatus();
}
});
}
// Helper Function
function updateStatus() {
if (!proxySetup) setupProxy();
indicator = indicator || new TravisStatusIndicator();
indicator.updateStatus();
}
function openInTravis() {
if (!proxySetup) setupProxy();
indicator = indicator || new TravisStatusIndicator();
indicator.openInTravis();
}
function setupProxy() {
if (process.env && process.env.http_proxy) {
// Seems like we have a proxy
let match = process.env.http_proxy.match(/^(http:\/\/)?([^:\/]+)(:([0-9]+))?/i);
let proxyData = { host: null, port: null };
if (match && match.length >= 3) {
proxyData.host = match[2];
proxyData.port = match[4] != null ? match[4] : 80;
}
if (proxyData.host && proxyData.port) {
var globalTunnel = require('global-tunnel');
globalTunnel.initialize({
host: proxyData.host,
port: proxyData.port
});
} else {
// We have trouble getting ifnormation form the global http_proxy env variable
window.showErrorMessage('Travis CI: HTTP Proxy settings detected, but we have trouble parsing the setting. The extension may not work properly.');
}
}
proxySetup = true;
}