-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathFuncVersion.ts
More file actions
74 lines (62 loc) · 3.25 KB
/
FuncVersion.ts
File metadata and controls
74 lines (62 loc) · 3.25 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { type IActionContext, type IAzureQuickPickItem, type IAzureQuickPickOptions } from '@microsoft/vscode-azext-utils';
import { localize } from './localize';
import { openUrl } from './utils/openUrl';
export enum FuncVersion {
v1 = '~1',
v2 = '~2',
v3 = '~3',
v4 = '~4'
}
export const latestGAVersion: FuncVersion = FuncVersion.v4;
export const funcVersionLink: string = 'https://aka.ms/AA1tpij';
const funcRuntimeWarningLabel: string = localize('runtimeWarning', `$(extensions-warning-message) Azure Functions runtimes v2 and v3 have reached the end of life.`);
export async function promptForFuncVersion(context: IActionContext, message?: string): Promise<FuncVersion> {
const recommended: string = localize('recommended', '(Recommended)');
let picks: IAzureQuickPickItem<FuncVersion | undefined>[] = [
{ label: 'Azure Functions v4', description: recommended, data: FuncVersion.v4 },
{ label: 'Azure Functions v3', data: FuncVersion.v3, description: '$(extensions-warning-message)' },
{ label: 'Azure Functions v2', data: FuncVersion.v2, description: '$(extensions-warning-message)' },
{ label: 'Azure Functions v1', data: FuncVersion.v1 },
{ label: funcRuntimeWarningLabel, data: undefined, onPicked: () => {/*do nothing*/ } }
];
picks = picks.filter(p => osSupportsVersion(p.data));
const learnMoreQp = { label: localize('learnMore', '$(link-external) Learn about Azure Functions versioning...'), description: '', data: undefined };
picks.push(learnMoreQp);
const options: IAzureQuickPickOptions = { placeHolder: message || localize('selectVersion', 'Select a version'), stepName: 'funcVersion', suppressPersistence: true };
// eslint-disable-next-line no-constant-condition
while (true) {
const version: FuncVersion | undefined = (await context.ui.showQuickPick(picks, options)).data;
if (version === undefined) {
await openUrl(funcVersionLink);
} else {
return version;
}
}
}
export function tryParseFuncVersion(data: string | undefined): FuncVersion | undefined {
if (data) {
const majorVersion: string | undefined = tryGetMajorVersion(data);
if (majorVersion) {
return Object.values(FuncVersion).find(v => v === '~' + majorVersion);
}
}
return undefined;
}
function osSupportsVersion(version: FuncVersion | undefined): boolean {
return version !== FuncVersion.v1 || process.platform === 'win32';
}
export function getMajorVersion(data: string): string {
const majorVersion: string | undefined = tryGetMajorVersion(data);
if (!majorVersion) {
throw new Error(localize('invalidVersion', 'Invalid version "{0}".', data));
}
return majorVersion;
}
function tryGetMajorVersion(data: string): string | undefined {
const match: RegExpMatchArray | null = data.match(/^[~v]?([0-9]+)/i);
return match ? match[1] : undefined;
}