Increment azure function name when using create azure func from table (#17236)
* increment azure function name * add js docs
This commit is contained in:
Родитель
076721aa45
Коммит
d67d982382
|
@ -566,6 +566,9 @@
|
|||
<trans-unit id="selectAzureFunctionProjFolder">
|
||||
<source xml:lang="en">Select folder for the Azure Function project</source>
|
||||
</trans-unit>
|
||||
<trans-unit id="nameMustNotBeEmpty">
|
||||
<source xml:lang="en">Name must not be empty</source>
|
||||
</trans-unit>
|
||||
</body>
|
||||
</file>
|
||||
</xliff>
|
||||
|
|
|
@ -32,7 +32,7 @@ export interface ILocalSettingsJson {
|
|||
* @returns settings in local.settings.json. If no settings are found, returns default "empty" settings
|
||||
*/
|
||||
export async function getLocalSettingsJson(localSettingsPath: string): Promise<ILocalSettingsJson> {
|
||||
if (await fs.existsSync(localSettingsPath)) {
|
||||
if (fs.existsSync(localSettingsPath)) {
|
||||
const data: string = (fs.readFileSync(localSettingsPath)).toString();
|
||||
try {
|
||||
return JSON.parse(data);
|
||||
|
|
|
@ -6,10 +6,11 @@
|
|||
import SqlToolsServiceClient from '../languageservice/serviceclient';
|
||||
import * as vscode from 'vscode';
|
||||
import * as mssql from 'vscode-mssql';
|
||||
import * as path from 'path';
|
||||
import * as azureFunctionsContracts from '../models/contracts/azureFunctions/azureFunctionsContracts';
|
||||
import * as azureFunctionUtils from '../azureFunction/azureFunctionUtils';
|
||||
import * as constants from '../constants/constants';
|
||||
import { generateQuotedFullName } from '../utils/utils';
|
||||
import { generateQuotedFullName, getUniqueFileName } from '../utils/utils';
|
||||
import * as LocalizedConstants from '../constants/localizedConstants';
|
||||
|
||||
export const hostFileName: string = 'host.json';
|
||||
|
@ -84,10 +85,12 @@ export class AzureFunctionsService implements mssql.IAzureFunctionsService {
|
|||
const newFilePromise = azureFunctionUtils.waitForNewFunctionFile(projectFile);
|
||||
|
||||
// get function name from user
|
||||
let uniqueFunctionName = await getUniqueFileName(path.dirname(projectFile), table);
|
||||
const functionName = await vscode.window.showInputBox({
|
||||
title: LocalizedConstants.functionNameTitle,
|
||||
value: table,
|
||||
ignoreFocusOut: true
|
||||
value: uniqueFunctionName,
|
||||
ignoreFocusOut: true,
|
||||
validateInput: input => input ? undefined : LocalizedConstants.nameMustNotBeEmpty
|
||||
});
|
||||
if (!functionName) {
|
||||
return;
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as cp from 'child_process';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import { escapeClosingBrackets } from '../models/utils';
|
||||
|
||||
export async function executeCommand(command: string, cwd?: string): Promise<string> {
|
||||
|
@ -31,3 +33,27 @@ export async function executeCommand(command: string, cwd?: string): Promise<str
|
|||
export function generateQuotedFullName(schema: string, objectName: string): string {
|
||||
return `[${escapeClosingBrackets(schema)}].[${escapeClosingBrackets(objectName)}]`;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets a unique file name
|
||||
* Increment the file name by adding 1 to function name if the file already exists
|
||||
* Undefined if the filename suffix count becomes greater than 1024
|
||||
* @param folderPath selected project folder path
|
||||
* @param fileName base filename to use
|
||||
* @returns a promise with the unique file name, or undefined
|
||||
*/
|
||||
export async function getUniqueFileName(folderPath: string, fileName: string): Promise<string | undefined> {
|
||||
let count: number = 0;
|
||||
const maxCount: number = 1024;
|
||||
let uniqueFileName = fileName;
|
||||
|
||||
while (count < maxCount) {
|
||||
if (!fs.existsSync(path.join(folderPath, uniqueFileName + '.cs'))) {
|
||||
return uniqueFileName;
|
||||
}
|
||||
count += 1;
|
||||
uniqueFileName = fileName + count.toString();
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче