forked from microsoft/vscode-azurefunctions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctionSubWizard.ts
More file actions
132 lines (118 loc) · 6.8 KB
/
FunctionSubWizard.ts
File metadata and controls
132 lines (118 loc) · 6.8 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { AzureWizardExecuteStep, AzureWizardPromptStep, IWizardOptions } from '@microsoft/vscode-azext-utils';
import { ProjectLanguage } from '../../constants';
import { localize } from '../../localize';
import { IFunctionTemplate } from '../../templates/IFunctionTemplate';
import { isNodeV4Plus, isPythonV2Plus } from '../../utils/programmingModelUtils';
import { addBindingSettingSteps } from '../addBinding/settingSteps/addBindingSettingSteps';
import { JavaPackageNameStep } from '../createNewProject/javaSteps/JavaPackageNameStep';
import { BallerinaFunctionCreateStep } from './ballerinaSteps/BallerinaFunctionCreateStep';
import { BallerinaFunctionNameStep } from './ballerinaSteps/BallerinaFunctionNameStep';
import { DotnetFunctionCreateStep } from './dotnetSteps/DotnetFunctionCreateStep';
import { DotnetFunctionNameStep } from './dotnetSteps/DotnetFunctionNameStep';
import { DotnetNamespaceStep } from './dotnetSteps/DotnetNamespaceStep';
import { DurableProjectConfigureStep } from './durableSteps/DurableProjectConfigureStep';
import { IFunctionWizardContext } from './IFunctionWizardContext';
import { JavaFunctionCreateStep } from './javaSteps/JavaFunctionCreateStep';
import { JavaFunctionNameStep } from './javaSteps/JavaFunctionNameStep';
import { OpenAPICreateStep } from './openAPISteps/OpenAPICreateStep';
import { OpenAPIGetSpecificationFileStep } from './openAPISteps/OpenAPIGetSpecificationFileStep';
import { NodeV4FunctionCreateStep } from './scriptSteps/NodeV4FunctionCreateStep';
import { NodeV4FunctionNameStep } from './scriptSteps/NodeV4FunctionNameStep';
import { PythonFunctionCreateStep } from './scriptSteps/PythonFunctionCreateStep';
import { PythonScriptStep } from './scriptSteps/PythonScriptStep';
import { ScriptFunctionCreateStep } from './scriptSteps/ScriptFunctionCreateStep';
import { ScriptFunctionNameStep } from './scriptSteps/ScriptFunctionNameStep';
import { TypeScriptFunctionCreateStep } from './scriptSteps/TypeScriptFunctionCreateStep';
export class FunctionSubWizard {
public static async createSubWizard(context: IFunctionWizardContext, functionSettings: { [key: string]: string | undefined } | undefined): Promise<IWizardOptions<IFunctionWizardContext> | undefined> {
functionSettings = functionSettings ?? {};
const template: IFunctionTemplate | undefined = context.functionTemplate;
if (template) {
const promptSteps: AzureWizardPromptStep<IFunctionWizardContext>[] = [];
const isV2PythonModel = isPythonV2Plus(context.language, context.languageModel);
if (isV2PythonModel) {
promptSteps.push(new PythonScriptStep());
}
switch (context.language) {
case ProjectLanguage.Java:
promptSteps.push(new JavaPackageNameStep(), new JavaFunctionNameStep());
break;
case ProjectLanguage.Ballerina:
promptSteps.push(new BallerinaFunctionNameStep());
break;
case ProjectLanguage.CSharp:
case ProjectLanguage.FSharp:
promptSteps.push(new DotnetFunctionNameStep(), new DotnetNamespaceStep());
break;
default:
if (isNodeV4Plus(context)) {
promptSteps.push(new NodeV4FunctionNameStep())
} else if (!isV2PythonModel) {
// NOTE: The V2 Python model has attributed bindings and we don't (yet) update them from the template.
promptSteps.push(new ScriptFunctionNameStep());
}
break;
}
// Add settings to context that were programmatically passed in
for (const key of Object.keys(functionSettings)) {
context[key.toLowerCase()] = functionSettings[key];
}
addBindingSettingSteps(template.userPromptedSettings, promptSteps);
const executeSteps: AzureWizardExecuteStep<IFunctionWizardContext>[] = [];
if (isNodeV4Plus(context)) {
executeSteps.push(new NodeV4FunctionCreateStep());
} else {
switch (context.language) {
case ProjectLanguage.Java:
executeSteps.push(new JavaFunctionCreateStep());
break;
case ProjectLanguage.CSharp:
case ProjectLanguage.FSharp:
executeSteps.push(await DotnetFunctionCreateStep.createStep(context));
break;
case ProjectLanguage.TypeScript:
executeSteps.push(new TypeScriptFunctionCreateStep());
break;
case ProjectLanguage.Ballerina:
executeSteps.push(new BallerinaFunctionCreateStep());
break;
default:
if (isV2PythonModel) {
executeSteps.push(new PythonFunctionCreateStep());
} else {
executeSteps.push(new ScriptFunctionCreateStep());
}
break;
}
}
if (context.newDurableStorageType) {
executeSteps.push(new DurableProjectConfigureStep());
}
const title: string = localize('createFunction', 'Create new {0}', template.name);
return { promptSteps, executeSteps, title };
} else if (context.generateFromOpenAPI) {
const promptSteps: AzureWizardPromptStep<IFunctionWizardContext>[] = [];
const executeSteps: AzureWizardExecuteStep<IFunctionWizardContext>[] = [];
switch (context.language) {
case ProjectLanguage.Java:
promptSteps.push(new JavaPackageNameStep());
break;
case ProjectLanguage.CSharp:
promptSteps.push(new DotnetNamespaceStep());
break;
default:
break;
}
promptSteps.push(new OpenAPIGetSpecificationFileStep());
executeSteps.push(await OpenAPICreateStep.createStep(context));
const title: string = localize('createFunction', 'Create new {0}', 'HTTP Triggers from OpenAPI (v2/v3) Specification File');
return { promptSteps, executeSteps, title };
} else {
return undefined;
}
}
}