Skip to content

Commit

Permalink
Merge branch 'release/1.0.0'
Browse files Browse the repository at this point in the history
* 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
gep13 committed Dec 1, 2020
2 parents 935d6aa + cc88d86 commit a7f08a5
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 40 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@
"depcheck": "depcheck"
},
"dependencies": {
"adm-zip": "^0.5.0",
"adm-zip": "^0.5.1",
"byline": "^5.0.0",
"https-proxy-agent": "^5.0.0",
"ini": "^1.3.4",
Expand Down
5 changes: 2 additions & 3 deletions recipe.cake
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#load "nuget:https://www.nuget.org/api/v2?package=Cake.VsCode.Recipe&version=0.3.0"
#load "nuget:https://www.nuget.org/api/v2?package=Cake.VsCode.Recipe&version=0.4.0"

if(BuildSystem.IsLocalBuild)
{
Environment.SetVariableNames(
githubUserNameVariable: "CAKE_GITHUB_USERNAME",
githubPasswordVariable: "CAKE_GITHUB_PASSWORD"
githubTokenVariable: "CAKE_GITHUB_PAT"
);
}
else
Expand Down
18 changes: 10 additions & 8 deletions src/addPackage/actions/fetchCakePackages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,25 @@ import { getFetchOptions } from '../../shared/utils';
import { window, workspace } from 'vscode';
import {
CAKE_SEARCH_PAGE_SIZE,
NUGET_SEARCH_URL,
CANCEL
} from '../../constants';
import {
NUGET_SEARCHING_PACKAGES
} from '../../shared/messages';
import { NUGET_SEARCHING_PACKAGES } from '../../shared/messages';
import { getNugetServiceUrl, NuGetServiceType } from '../../shared/nugetServiceUrl';

export default function fetchCakePackages(
export default async function fetchCakePackages(
value: string | undefined,
searchUrl: string = NUGET_SEARCH_URL,
searchUrl?: string,
take: string = CAKE_SEARCH_PAGE_SIZE
): Promise<Response> | Promise<never> {
): Promise<Response | never> {
if (!value) {
// User has canceled the process.
return Promise.reject(CANCEL);
}

if(!searchUrl){
searchUrl = await getNugetServiceUrl(NuGetServiceType.SearchAutocompleteService);
}

window.setStatusBarMessage(NUGET_SEARCHING_PACKAGES);

const queryParams = qs.stringify({
Expand All @@ -30,7 +32,7 @@ export default function fetchCakePackages(
take: take
});

return fetch(
return await fetch(
`${searchUrl}?${queryParams}`,
getFetchOptions(workspace.getConfiguration('http'))
);
Expand Down
39 changes: 20 additions & 19 deletions src/addPackage/actions/fetchPackageVersions.ts
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 };
}
3 changes: 1 addition & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ export const DEFAULT_SCRIPT_NAME = 'build.cake';
export const OUTPUT_CHANNEL_NAME = 'Cake Workspace';
export const ERROR_INVALID_SETTINGS = 'Invalid installation options! Please try again.';
export const ERROR_NO_WORKSPACE = 'You have not yet opened a folder.';
export const NUGET_SEARCH_URL = 'https://api-v2v3search-0.nuget.org/autocomplete';
export const NUGET_VERSIONS_URL = "https://api.nuget.org/v3-flatcontainer/";
export const NUGET_SEVICE_INDEX_URL = 'https://api.nuget.org/v3/index.json';
export const DEFAULT_RESPONSE_TIMEOUT = 10000;
export const CAKE_DEFAULT_NAME = "Cake";
export const CAKE_BAKERY_PACKAGE_URL = 'http://nuget.org/api/v2/package/Cake.Bakery/';
Expand Down
30 changes: 26 additions & 4 deletions src/shared/cakeTool.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { ChildProcessWithoutNullStreams, spawn } from 'child_process';
import { window, Memento, ExtensionContext } from 'vscode';
import { window, Memento, ExtensionContext, workspace } from 'vscode';
import fetch from 'node-fetch';
import { getFetchOptions } from './utils';
import { Version } from './version';
import { logError, logToOutput } from './log';
import { getNugetServiceUrl, NuGetServiceType } from './nugetServiceUrl';

export class CakeTool {

Expand Down Expand Up @@ -36,10 +40,28 @@ export class CakeTool {
});
}

/**
* returns the latest available version of Cake.Tool on nuget
*/
public async getAvailableVersion(): Promise<Version|null> {
const proc = spawn('dotnet', ['tool', 'search', 'cake.tool']);
const ver = await this.getCakeVersionFromProc(proc);
return ver;
const url = (await getNugetServiceUrl(NuGetServiceType.SearchQueryService)) + '?q=Cake.Tool&prerelease=false';
try {
const search = await fetch(
url,
getFetchOptions(workspace.getConfiguration('http')));
const searchResult: any = await search.json();
const cakeTool = (searchResult?.data || []).find((x:any) => x.id === "Cake.Tool");
const version = cakeTool?.version;
if(!version) {
logToOutput("Could not find a latest version for Cake.Tool from: "+url);
return null;
}
return Version.parse(version);
}
catch (ex: any) {
logError(ex, true);
}
return null
}

/**
Expand Down
26 changes: 26 additions & 0 deletions src/shared/nugetServiceUrl.ts
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;
}

0 comments on commit a7f08a5

Please sign in to comment.