-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathLocalAppSettingCreateStep.ts
More file actions
38 lines (32 loc) · 2.05 KB
/
LocalAppSettingCreateStep.ts
File metadata and controls
38 lines (32 loc) · 2.05 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { AzureWizardExecuteStep } from '@microsoft/vscode-azext-utils';
import { type Progress } from 'vscode';
import { localSettingsFileName } from '../../../constants';
import { setLocalAppSetting } from '../../../funcConfig/local.settings';
import { localize } from '../../../localize';
import { type IBindingSetting } from '../../../templates/IBindingTemplate';
import { type ParsedInput } from '../../../templates/script/parseScriptTemplatesV2';
import { nonNullProp, nonNullValue } from '../../../utils/nonNull';
import { getBindingSetting } from '../../createFunction/IFunctionWizardContext';
import { type IBindingWizardContext } from '../IBindingWizardContext';
export class LocalAppSettingCreateStep extends AzureWizardExecuteStep<IBindingWizardContext> {
public priority: number = 210;
private readonly _setting: IBindingSetting | ParsedInput;
private readonly _valueKey: string;
constructor(setting: IBindingSetting | ParsedInput, valueKey: string) {
super();
this._setting = setting;
this._valueKey = valueKey;
}
public async execute(context: IBindingWizardContext, progress: Progress<{ message?: string | undefined; increment?: number | undefined }>): Promise<void> {
progress.report({ message: localize('updatingLocalSettings', 'Updating {0}...', localSettingsFileName) });
const appSettingName = String(nonNullValue(getBindingSetting(context, this._setting), this._setting.name));
await setLocalAppSetting(context, context.projectPath, appSettingName, nonNullProp(context, this._valueKey as keyof IBindingWizardContext) as string);
}
public shouldExecute(context: IBindingWizardContext): boolean {
return !!context[this._valueKey];
}
}