-
Notifications
You must be signed in to change notification settings - Fork 875
/
index.ts
85 lines (75 loc) · 3.14 KB
/
index.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
/**
* @file page entry
* @author netcon
*/
import { ConnectToGitHub } from './github-auth';
import { ConnectToGitLab } from './gitlab-auth';
import { renderNotification } from './notification';
import { createProductConfiguration } from './product';
import { createVSCodeWebConfig, Platform } from './config';
declare global {
interface Window {
require?: { config?: Function };
webPackagePaths?: any;
github1sExtensions?: any[];
}
}
const resolvePlatformState = (): [Platform, string] => {
const hostname = window.location.hostname;
const pathParts = window.location.pathname.split('/').filter(Boolean);
if (hostname.match(/^(.*\.)?gitlab1s\.com$/i)) {
const dashIndex = pathParts.indexOf('-');
const repository = (dashIndex < 0 ? pathParts : pathParts.slice(0, dashIndex)).join('/');
return [Platform.GitLab, repository];
}
if (hostname.match(/^(.*\.)?bitbucket1s\.org$/i)) {
const repository = pathParts.length >= 2 ? pathParts.slice(0, 2).join('/') : '';
return [Platform.Bitbucket, repository];
}
if (hostname.match(/^(.*\.)?npmjs1s\.com$/i)) {
const trimmedParts = pathParts[0] === 'package' ? pathParts.slice(1) : pathParts;
const packageParts = trimmedParts.slice(0, trimmedParts[0] && trimmedParts[0][0] === '@' ? 2 : 1);
const repository = pathParts.length ? packageParts.join('/') || 'package' : '';
return [Platform.npm, repository];
}
const repository = pathParts.slice(0, 2).join('/');
return [Platform.GitHub, repository];
};
(function () {
const [platform, repository] = resolvePlatformState();
const staticAssetsPath = '/static-' + STATIC_HASH;
const staticAssetsPrefix = window.location.origin + staticAssetsPath;
const webPackagesPrefix = staticAssetsPrefix + '/web-packages';
Object.keys(window.webPackagePaths || {}).forEach((key) => {
self.webPackagePaths[key] = `${webPackagesPrefix}/${key}/${self.webPackagePaths[key]}`;
});
// config vscode loader
if (window.require && window.require.config) {
window.require.config({
baseUrl: staticAssetsPrefix + '/vscode',
paths: self.webPackagePaths,
});
}
const vscodeCommands = [
{ id: 'github1s.commands.vscode.getBrowserUrl', handler: () => window.location.href },
{ id: 'github1s.commands.vscode.replaceBrowserUrl', handler: (url: string) => history.replaceState(null, '', url) },
{ id: 'github1s.commands.vscode.pushBrowserUrl', handler: (url: string) => history.pushState(null, '', url) },
{ id: 'github1s.commands.vscode.connectToGitHub', handler: ConnectToGitHub },
{ id: 'github1s.commands.vscode.connectToGitLab', handler: ConnectToGitLab },
];
(window as any).vscodeWeb = {
commands: vscodeCommands,
allowEditorLabelOverride: true,
additionalBuiltinExtensions: [],
webviewEndpoint: staticAssetsPrefix + '/vscode/vs/workbench/contrib/webview/browser/pre',
productConfiguration: createProductConfiguration(platform),
initialColorTheme: { themeType: 'dark' as any },
builtinExtensions: window.github1sExtensions || [],
onWorkbenchReady() {
const loadSpinner = document.querySelector('#load-spinner');
loadSpinner && loadSpinner.remove();
renderNotification(platform);
},
...createVSCodeWebConfig(platform, repository),
};
})();