77
88import * as fs from 'fs-extra-promise' ;
99import * as path from 'path' ;
10+ import * as https from 'https' ;
11+ import * as stream from 'stream' ;
1012import * as tmp from 'tmp' ;
13+ import { parse } from 'url' ;
1114import { SupportedPlatform , getSupportedPlatform } from './utils' ;
1215
1316const Decompress = require ( 'decompress' ) ;
14- const Github = require ( 'github-releases' ) ;
1517
16- const OmnisharpRepo = 'OmniSharp/omnisharp-roslyn' ;
17- const OmnisharpVersion = 'v1.9-alpha14' ;
18+ const BaseDownloadUrl = 'https://vscodeoscon.blob.core.windows.net/ext' ;
1819const DefaultInstallLocation = path . join ( __dirname , '../.omnisharp' ) ;
1920const ApiToken = '18a6f5ecea711220d4f433d4fd41062d479fda1d' ;
2021
@@ -45,46 +46,39 @@ function getOmnisharpAssetName(): string {
4546 }
4647}
4748
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+
4871export function downloadOmnisharp ( ) : Promise < boolean > {
4972 return new Promise < boolean > ( ( resolve , reject ) => {
5073 console . log ( `[OmniSharp]: Installing to ${ DefaultInstallLocation } ` ) ;
5174
52- const repo = new Github ( { repo : OmnisharpRepo , token : ApiToken } ) ;
5375 const assetName = getOmnisharpAssetName ( ) ;
76+ const urlString = `${ BaseDownloadUrl } /${ assetName } ` ;
5477
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 => {
8882 tmp . file ( ( err , tmpPath , fd , cleanupCallback ) => {
8983 if ( err ) {
9084 return reject ( err ) ;
@@ -106,7 +100,7 @@ export function downloadOmnisharp(): Promise<boolean> {
106100 . src ( tmpPath )
107101 . dest ( DefaultInstallLocation ) ;
108102
109- if ( path . extname ( foundAsset . name ) . toLowerCase ( ) === '.zip' ) {
103+ if ( path . extname ( assetName ) . toLowerCase ( ) === '.zip' ) {
110104 decompress = decompress . use ( Decompress . zip ( ) ) ;
111105 console . log ( `[OmniSharp] Unzipping...` ) ;
112106 }
@@ -129,6 +123,5 @@ export function downloadOmnisharp(): Promise<boolean> {
129123 inStream . pipe ( outStream ) ;
130124 } ) ;
131125 } ) ;
132- } ) ;
133126 } ) ;
134127}
0 commit comments