7
7
8
8
import * as fs from 'fs-extra-promise' ;
9
9
import * as path from 'path' ;
10
+ import * as https from 'https' ;
11
+ import * as stream from 'stream' ;
10
12
import * as tmp from 'tmp' ;
13
+ import { parse } from 'url' ;
11
14
import { SupportedPlatform , getSupportedPlatform } from './utils' ;
12
15
13
16
const Decompress = require ( 'decompress' ) ;
14
- const Github = require ( 'github-releases' ) ;
15
17
16
- const OmnisharpRepo = 'OmniSharp/omnisharp-roslyn' ;
17
- const OmnisharpVersion = 'v1.9-alpha14' ;
18
+ const BaseDownloadUrl = 'https://vscodeoscon.blob.core.windows.net/ext' ;
18
19
const DefaultInstallLocation = path . join ( __dirname , '../.omnisharp' ) ;
19
20
const ApiToken = '18a6f5ecea711220d4f433d4fd41062d479fda1d' ;
20
21
@@ -45,46 +46,39 @@ function getOmnisharpAssetName(): string {
45
46
}
46
47
}
47
48
49
+ function download ( urlString : string ) : Promise < stream . Readable > {
50
+ let url = parse ( urlString ) ;
51
+ let options : https . RequestOptions = {
52
+ host : url . host ,
53
+ path : url . path ,
54
+ }
55
+
56
+ return new Promise < stream . Readable > ( ( resolve , reject ) => {
57
+ return https . get ( options , res => {
58
+ // handle redirection
59
+ if ( res . statusCode === 302 ) {
60
+ return download ( res . headers . location ) ;
61
+ }
62
+ else if ( res . statusCode !== 200 ) {
63
+ return reject ( Error ( `Download failed with code ${ res . statusCode } .` ) ) ;
64
+ }
65
+
66
+ return resolve ( res ) ;
67
+ } ) ;
68
+ } ) ;
69
+ }
70
+
48
71
export function downloadOmnisharp ( ) : Promise < boolean > {
49
72
return new Promise < boolean > ( ( resolve , reject ) => {
50
73
console . log ( `[OmniSharp]: Installing to ${ DefaultInstallLocation } ` ) ;
51
74
52
- const repo = new Github ( { repo : OmnisharpRepo , token : ApiToken } ) ;
53
75
const assetName = getOmnisharpAssetName ( ) ;
76
+ const urlString = `${ BaseDownloadUrl } /${ assetName } ` ;
54
77
55
- console . log ( `[OmniSharp] Looking for ${ OmnisharpVersion } , ${ assetName } ...` ) ;
56
-
57
- repo . getReleases ( { tag_name : OmnisharpVersion } , ( err , releases ) => {
58
- if ( err ) {
59
- return reject ( err ) ;
60
- }
61
-
62
- if ( ! releases . length ) {
63
- return reject ( new Error ( `OmniSharp release ${ OmnisharpVersion } not found.` ) ) ;
64
- }
65
-
66
- // Note: there should only be a single release, but use the first one
67
- // if there are ever multiple results. Same thing for assets.
68
- let foundAsset = null ;
69
-
70
- for ( var asset of releases [ 0 ] . assets ) {
71
- if ( asset . name === assetName ) {
72
- foundAsset = asset ;
73
- break ;
74
- }
75
- }
76
-
77
- if ( ! foundAsset ) {
78
- return reject ( new Error ( `OmniSharp release ${ OmnisharpVersion } asset, ${ assetName } not found.` ) ) ;
79
- }
80
-
81
- console . log ( `[OmniSharp] Found it!` ) ;
82
-
83
- repo . downloadAsset ( foundAsset , ( err , inStream ) => {
84
- if ( err ) {
85
- return reject ( err ) ;
86
- }
87
-
78
+ console . log ( `[OmniSharp] Attempting to download ${ assetName } ...` ) ;
79
+
80
+ return download ( urlString )
81
+ . then ( inStream => {
88
82
tmp . file ( ( err , tmpPath , fd , cleanupCallback ) => {
89
83
if ( err ) {
90
84
return reject ( err ) ;
@@ -106,7 +100,7 @@ export function downloadOmnisharp(): Promise<boolean> {
106
100
. src ( tmpPath )
107
101
. dest ( DefaultInstallLocation ) ;
108
102
109
- if ( path . extname ( foundAsset . name ) . toLowerCase ( ) === '.zip' ) {
103
+ if ( path . extname ( assetName ) . toLowerCase ( ) === '.zip' ) {
110
104
decompress = decompress . use ( Decompress . zip ( ) ) ;
111
105
console . log ( `[OmniSharp] Unzipping...` ) ;
112
106
}
@@ -129,6 +123,5 @@ export function downloadOmnisharp(): Promise<boolean> {
129
123
inStream . pipe ( outStream ) ;
130
124
} ) ;
131
125
} ) ;
132
- } ) ;
133
126
} ) ;
134
127
}
0 commit comments