-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathgetNewestSwaCliVersion.ts
More file actions
30 lines (26 loc) · 1.33 KB
/
getNewestSwaCliVersion.ts
File metadata and controls
30 lines (26 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { AzExtPipelineResponse, sendRequestWithTimeout } from "@microsoft/vscode-azext-azureutils";
import { IActionContext } from "@microsoft/vscode-azext-utils";
import { swaCliPackageName } from "../../constants";
import { localize } from "../../utils/localize";
interface IPackageMetadata {
"dist-tags": {
[tag: string]: string;
latest: string;
}
}
export async function getNewestSwaCliVersion(context: IActionContext): Promise<string | undefined> {
try {
const response: AzExtPipelineResponse = await sendRequestWithTimeout(context, {
method: 'GET',
url: `https://registry.npmjs.org/${swaCliPackageName}`
}, 15000, undefined);
const packageMetadata: IPackageMetadata = <IPackageMetadata>response.parsedBody;
return packageMetadata["dist-tags"].latest;
} catch (error) {
throw new Error(localize('noLatestTag', 'Failed to retrieve then latest version of the Azure Static Web Apps CLI.'));
}
}