forked from microsoft/vscode-azurefunctions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBallerinaFunctionCreateStep.ts
More file actions
34 lines (27 loc) · 1.73 KB
/
BallerinaFunctionCreateStep.ts
File metadata and controls
34 lines (27 loc) · 1.73 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { AzExtFsExtra, nonNullProp } from '@microsoft/vscode-azext-utils';
import * as path from 'path';
import { FunctionCreateStepBase } from '../FunctionCreateStepBase';
import { IBallerinaFunctionTemplate, IBallerinaFunctionWizardContext } from './IBallerinaFunctionWizardContext';
export class BallerinaFunctionCreateStep extends FunctionCreateStepBase<IBallerinaFunctionWizardContext> {
public async executeCore(context: IBallerinaFunctionWizardContext): Promise<string> {
const functionPath = context.projectPath;
await AzExtFsExtra.ensureDir(functionPath);
const functionName = nonNullProp(context, 'functionName');
const fileName = `${functionName}.bal`;
const template: IBallerinaFunctionTemplate = nonNullProp(context, 'functionTemplate');
await Promise.all(Object.keys(template.templateFiles).map(async f => {
let contents = template.templateFiles[f];
contents = contents.replace(/%functionName%/g, functionName);
for (const setting of template.userPromptedSettings) {
// the setting name keys are lowercased
contents = contents.replace(new RegExp(`%${setting.name}%`, 'g'), context[setting.name.toLowerCase()]);
}
await AzExtFsExtra.writeFile(path.join(functionPath, fileName), contents);
}));
return path.join(functionPath, fileName);
}
}