-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* release/1.0.0: (build) Update to latest Cake.VsCode.Recipe Bump adm-zip from 0.5.0 to 0.5.1 (GH-473) implemented a helper to get NuGet service URLs (GH-473) checking the latest available Cake.Tool
- Loading branch information
Showing
8 changed files
with
89 additions
and
40 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,29 @@ | ||
import { window, workspace } from 'vscode'; | ||
import fetch from 'node-fetch'; | ||
import { Response } from 'node-fetch'; | ||
import { getFetchOptions } from '../../shared/utils'; | ||
import { NUGET_VERSIONS_URL, CANCEL } from '../../constants'; | ||
import { CANCEL } from '../../constants'; | ||
import { NUGET_LOADING_VERSIONS } from '../../shared/messages'; | ||
import { getNugetServiceUrl, NuGetServiceType } from '../../shared/nugetServiceUrl'; | ||
|
||
export default function fetchPackageVersions( | ||
export default async function fetchPackageVersions( | ||
selectedPackageName: string | undefined, | ||
versionsUrl: string = NUGET_VERSIONS_URL | ||
): Promise<any> | Promise<never> { | ||
return new Promise((resolve, reject) => { | ||
if (!selectedPackageName) { | ||
// User has canceled the process. | ||
return reject(CANCEL); | ||
} | ||
versionsUrl?: string | ||
): Promise<any | never> { | ||
if (!selectedPackageName) { | ||
// User has canceled the process. | ||
return Promise.reject(CANCEL); | ||
} | ||
|
||
window.setStatusBarMessage(NUGET_LOADING_VERSIONS); | ||
window.setStatusBarMessage(NUGET_LOADING_VERSIONS); | ||
if(!versionsUrl) { | ||
versionsUrl = await getNugetServiceUrl(NuGetServiceType.FlatContainer3); | ||
} | ||
|
||
fetch( | ||
`${versionsUrl}${selectedPackageName}/index.json`, | ||
getFetchOptions(workspace.getConfiguration('http')) | ||
).then((response: Response) => { | ||
window.setStatusBarMessage(''); | ||
resolve({ response, selectedPackageName }); | ||
}); | ||
}); | ||
const response = await fetch( | ||
versionsUrl.replace(/\/?$/,`/${selectedPackageName}/index.json`), | ||
getFetchOptions(workspace.getConfiguration('http')) | ||
); | ||
|
||
window.setStatusBarMessage(''); | ||
return { response, selectedPackageName }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import fetch from 'node-fetch'; | ||
import { workspace } from 'vscode'; | ||
import { NUGET_SEVICE_INDEX_URL } from '../constants'; | ||
import { getFetchOptions } from './utils'; | ||
|
||
export enum NuGetServiceType { | ||
SearchAutocompleteService = 'SearchAutocompleteService', | ||
FlatContainer3 = 'PackageBaseAddress/3.0.0', | ||
SearchQueryService = 'SearchQueryService' | ||
} | ||
export async function getNugetServiceUrl(type: NuGetServiceType) : Promise<string> { | ||
// TODO: the url's won't change every 5 min. - should we cache the call to the services? | ||
const response = await fetch(NUGET_SEVICE_INDEX_URL, getFetchOptions(workspace.getConfiguration('http'))); | ||
const json: any = await response.json(); | ||
const resources = (json.resources as any[] || []).filter((x:any) => x['@type'] === type); | ||
let resource = resources.find((x: any) => (x.comment as string).toLowerCase().indexOf('primary') >= 0); | ||
if(!resource && resources.length > 0) { | ||
resource = resources[0]; | ||
} | ||
|
||
if(!resource){ | ||
throw new Error("Service endpoint not Found: "+type); | ||
} | ||
|
||
return resource['@id'] as string; | ||
} |