33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
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+
611'use strict' ;
712
813import * as fs from 'fs-extra-promise' ;
@@ -11,46 +16,70 @@ import * as https from 'https';
1116import * as stream from 'stream' ;
1217import * as tmp from 'tmp' ;
1318import { parse } from 'url' ;
14- import { SupportedPlatform , getSupportedPlatform } from '../utils' ;
19+ import { Flavor , getInstallDirectory } from './omnisharp' ;
20+ import { Platform } from '../platform' ;
1521import { getProxyAgent } from '../proxy' ;
1622
1723const decompress = require ( 'decompress' ) ;
1824
1925const 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' ;
2227
2328tmp . setGracefulCleanup ( ) ;
2429
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' ;
5374 }
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 ;
5483}
5584
5685function download ( urlString : string , proxy ?: string , strictSSL ?: boolean ) : Promise < stream . Readable > {
@@ -79,14 +108,20 @@ function download(urlString: string, proxy?: string, strictSSL?: boolean): Promi
79108 } ) ;
80109}
81110
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 ) {
83112 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 } ` ) ;
85121
86- const assetName = omnisharpAssetName || getOmnisharpAssetName ( ) ;
87- const urlString = `${ BaseDownloadUrl } /${ assetName } ` ;
122+ const urlString = `${ BaseDownloadUrl } /${ fileName } ` ;
88123
89- log ( `[INFO] Attempting to download ${ assetName } ...` ) ;
124+ log ( `[INFO] Attempting to download ${ fileName } ...` ) ;
90125
91126 return download ( urlString , proxy , strictSSL )
92127 . then ( inStream => {
@@ -108,7 +143,7 @@ export function downloadOmnisharp(log: (message: string) => void, omnisharpAsset
108143 log ( `[INFO] Download complete!` ) ;
109144 log ( `[INFO] Decompressing...` ) ;
110145
111- return decompress ( tmpPath , DefaultInstallLocation )
146+ return decompress ( tmpPath , installDirectory )
112147 . then ( files => {
113148 log ( `[INFO] Done! ${ files . length } files unpacked.` ) ;
114149 return resolve ( true ) ;
0 commit comments