3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
+ /*
7
+ * Note that this file intentionally does not import 'vscode' as the code within is intended
8
+ * to be usable outside of VS Code.
9
+ */
10
+
6
11
'use strict' ;
7
12
8
13
import * as fs from 'fs-extra-promise' ;
@@ -11,46 +16,70 @@ import * as https from 'https';
11
16
import * as stream from 'stream' ;
12
17
import * as tmp from 'tmp' ;
13
18
import { parse } from 'url' ;
14
- import { SupportedPlatform , getSupportedPlatform } from '../utils' ;
19
+ import { Flavor , getInstallDirectory } from './omnisharp' ;
20
+ import { Platform } from '../platform' ;
15
21
import { getProxyAgent } from '../proxy' ;
16
22
17
23
const decompress = require ( 'decompress' ) ;
18
24
19
25
const BaseDownloadUrl = 'https://omnisharpdownload.blob.core.windows.net/ext' ;
20
- const DefaultInstallLocation = path . join ( __dirname , '../.omnisharp' ) ;
21
- export const OmniSharpVersion = '1.9-beta11' ;
26
+ const OmniSharpVersion = '1.9-beta12' ;
22
27
23
28
tmp . setGracefulCleanup ( ) ;
24
29
25
- export function getOmnisharpAssetName ( ) : string {
26
- switch ( getSupportedPlatform ( ) ) {
27
- case SupportedPlatform . Windows :
28
- return `omnisharp-${ OmniSharpVersion } -win-x64-net451.zip` ;
29
- case SupportedPlatform . OSX :
30
- return `omnisharp-${ OmniSharpVersion } -osx-x64-netcoreapp1.0.tar.gz` ;
31
- case SupportedPlatform . CentOS :
32
- return `omnisharp-${ OmniSharpVersion } -centos-x64-netcoreapp1.0.tar.gz` ;
33
- case SupportedPlatform . Debian :
34
- return `omnisharp-${ OmniSharpVersion } -debian-x64-netcoreapp1.0.tar.gz` ;
35
- case SupportedPlatform . Fedora :
36
- return `omnisharp-${ OmniSharpVersion } -fedora-x64-netcoreapp1.0.tar.gz` ;
37
- case SupportedPlatform . OpenSUSE :
38
- return `omnisharp-${ OmniSharpVersion } -opensuse-x64-netcoreapp1.0.tar.gz` ;
39
- case SupportedPlatform . RHEL :
40
- return `omnisharp-${ OmniSharpVersion } -rhel-x64-netcoreapp1.0.tar.gz` ;
41
- case SupportedPlatform . Ubuntu14 :
42
- return `omnisharp-${ OmniSharpVersion } -ubuntu14-x64-netcoreapp1.0.tar.gz` ;
43
- case SupportedPlatform . Ubuntu16 :
44
- return `omnisharp-${ OmniSharpVersion } -ubuntu16-x64-netcoreapp1.0.tar.gz` ;
45
-
46
- default :
47
- if ( process . platform === 'linux' ) {
48
- throw new Error ( `Unsupported linux distribution` ) ;
49
- }
50
- else {
51
- throw new Error ( `Unsupported platform: ${ process . platform } ` ) ;
52
- }
30
+ function getDownloadFileName ( flavor : Flavor , platform : Platform ) : string {
31
+ let fileName = `omnisharp-${ OmniSharpVersion } -` ;
32
+
33
+ if ( flavor === Flavor . CoreCLR ) {
34
+ switch ( platform ) {
35
+ case Platform . Windows :
36
+ fileName += 'win-x64-netcoreapp1.0.zip' ;
37
+ break ;
38
+ case Platform . OSX :
39
+ fileName += 'osx-x64-netcoreapp1.0.tar.gz' ;
40
+ break ;
41
+ case Platform . CentOS :
42
+ fileName += 'centos-x64-netcoreapp1.0.tar.gz' ;
43
+ break ;
44
+ case Platform . Debian :
45
+ fileName += 'debian-x64-netcoreapp1.0.tar.gz' ;
46
+ break ;
47
+ case Platform . Fedora :
48
+ fileName += 'fedora-x64-netcoreapp1.0.tar.gz' ;
49
+ break ;
50
+ case Platform . OpenSUSE :
51
+ fileName += 'opensuse-x64-netcoreapp1.0.tar.gz' ;
52
+ break ;
53
+ case Platform . RHEL :
54
+ fileName += 'rhel-x64-netcoreapp1.0.tar.gz' ;
55
+ break ;
56
+ case Platform . Ubuntu14 :
57
+ fileName += 'ubuntu14-x64-netcoreapp1.0.tar.gz' ;
58
+ break ;
59
+ case Platform . Ubuntu16 :
60
+ fileName += 'ubuntu16-x64-netcoreapp1.0.tar.gz' ;
61
+ break ;
62
+
63
+ default :
64
+ if ( process . platform === 'linux' ) {
65
+ throw new Error ( `Unsupported linux distribution` ) ;
66
+ }
67
+ else {
68
+ throw new Error ( `Unsupported platform: ${ process . platform } ` ) ;
69
+ }
70
+ }
71
+ }
72
+ else if ( flavor === Flavor . Desktop ) {
73
+ fileName += 'win-x64-net451.zip' ;
53
74
}
75
+ else if ( flavor === Flavor . Mono ) {
76
+ fileName += 'mono.tar.gz' ;
77
+ }
78
+ else {
79
+ throw new Error ( `Unexpected OmniSharp flavor specified: ${ flavor } ` ) ;
80
+ }
81
+
82
+ return fileName ;
54
83
}
55
84
56
85
function download ( urlString : string , proxy ?: string , strictSSL ?: boolean ) : Promise < stream . Readable > {
@@ -79,14 +108,20 @@ function download(urlString: string, proxy?: string, strictSSL?: boolean): Promi
79
108
} ) ;
80
109
}
81
110
82
- export function downloadOmnisharp ( log : ( message : string ) => void , omnisharpAssetName ?: string , proxy ?: string , strictSSL ?: boolean ) {
111
+ export function go ( flavor : Flavor , platform : Platform , log ? : ( message : string ) => void , proxy ?: string , strictSSL ?: boolean ) {
83
112
return new Promise < boolean > ( ( resolve , reject ) => {
84
- log ( `[INFO] Installing to ${ DefaultInstallLocation } ` ) ;
113
+ log = log || ( _ => { } ) ;
114
+
115
+ log ( `Flavor: ${ flavor } , Platform: ${ platform } ` ) ;
116
+
117
+ const fileName = getDownloadFileName ( flavor , platform ) ;
118
+ const installDirectory = getInstallDirectory ( flavor ) ;
119
+
120
+ log ( `[INFO] Installing OmniSharp to ${ installDirectory } ` ) ;
85
121
86
- const assetName = omnisharpAssetName || getOmnisharpAssetName ( ) ;
87
- const urlString = `${ BaseDownloadUrl } /${ assetName } ` ;
122
+ const urlString = `${ BaseDownloadUrl } /${ fileName } ` ;
88
123
89
- log ( `[INFO] Attempting to download ${ assetName } ...` ) ;
124
+ log ( `[INFO] Attempting to download ${ fileName } ...` ) ;
90
125
91
126
return download ( urlString , proxy , strictSSL )
92
127
. then ( inStream => {
@@ -108,7 +143,7 @@ export function downloadOmnisharp(log: (message: string) => void, omnisharpAsset
108
143
log ( `[INFO] Download complete!` ) ;
109
144
log ( `[INFO] Decompressing...` ) ;
110
145
111
- return decompress ( tmpPath , DefaultInstallLocation )
146
+ return decompress ( tmpPath , installDirectory )
112
147
. then ( files => {
113
148
log ( `[INFO] Done! ${ files . length } files unpacked.` ) ;
114
149
return resolve ( true ) ;
0 commit comments