From 1837ada30ed3466759cc519ccfa8f4e6e204b5b1 Mon Sep 17 00:00:00 2001 From: Nathan Date: Fri, 31 Mar 2023 09:59:32 -0700 Subject: [PATCH] Disable create config (#813) --- package.json | 3 ++- src/commands/createSwaConfigFile.ts | 4 ++-- src/utils/workspaceUtils.ts | 16 ++++++++-------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 185edcb..446af54 100644 --- a/package.json +++ b/package.json @@ -168,7 +168,8 @@ { "command": "staticWebApps.createSwaConfigFile", "title": "%staticWebApps.createSwaConfigFile%", - "category": "Azure Static Web Apps" + "category": "Azure Static Web Apps", + "enablement": "!isWeb" }, { "command": "staticWebApps.deleteEnvironment", diff --git a/src/commands/createSwaConfigFile.ts b/src/commands/createSwaConfigFile.ts index 0b3f316..ce487af 100644 --- a/src/commands/createSwaConfigFile.ts +++ b/src/commands/createSwaConfigFile.ts @@ -11,8 +11,8 @@ import { localize } from '../utils/localize'; import { selectWorkspaceFolder } from '../utils/workspaceUtils'; export async function createSwaConfigFile(context: IActionContext): Promise { - const destPath: string = await selectWorkspaceFolder(context, localize('selectConfigFileLocation', 'Select location to create "{0}"', configFileName)); - const configFilePath: URI = Utils.joinPath(URI.parse(destPath), configFileName); + const destPath: URI = await selectWorkspaceFolder(context, localize('selectConfigFileLocation', 'Select location to create "{0}"', configFileName)); + const configFilePath: URI = Utils.joinPath(destPath, configFileName); if (await AzExtFsExtra.pathExists(configFilePath)) { const configFileExists: string = localize('configFileExists', 'Static Web App configuration file "{0}" already exists.', configFilePath.fsPath); diff --git a/src/utils/workspaceUtils.ts b/src/utils/workspaceUtils.ts index f9d2d40..eeda9b7 100644 --- a/src/utils/workspaceUtils.ts +++ b/src/utils/workspaceUtils.ts @@ -22,7 +22,7 @@ export function getSingleRootFsPath(): Uri | undefined { return workspace.workspaceFolders && workspace.workspaceFolders.length === 1 ? workspace.workspaceFolders[0].uri : undefined; } -export async function selectWorkspaceFolder(context: IActionContext, placeHolder: string, getSubPath?: (f: WorkspaceFolder) => string | undefined | Promise): Promise { +export async function selectWorkspaceFolder(context: IActionContext, placeHolder: string, getSubPath?: (f: WorkspaceFolder) => string | undefined | Promise): Promise { return await selectWorkspaceItem( context, placeHolder, @@ -36,22 +36,22 @@ export async function selectWorkspaceFolder(context: IActionContext, placeHolder getSubPath); } -export async function selectWorkspaceItem(context: IActionContext, placeHolder: string, options: OpenDialogOptions, getSubPath?: (f: WorkspaceFolder) => string | undefined | Promise): Promise { +export async function selectWorkspaceItem(context: IActionContext, placeHolder: string, options: OpenDialogOptions, getSubPath?: (f: WorkspaceFolder) => string | undefined | Promise): Promise { const folders: readonly WorkspaceFolder[] = workspace.workspaceFolders || []; - const folderPicks: IAzureQuickPickItem[] = await Promise.all(folders.map(async (f: WorkspaceFolder) => { + const folderPicks: IAzureQuickPickItem[] = await Promise.all(folders.map(async (f: WorkspaceFolder) => { let subpath: string | undefined; if (getSubPath) { subpath = await getSubPath(f); } - const fsPath: string = subpath ? path.join(f.uri.fsPath, subpath) : f.uri.fsPath; - return { label: path.basename(fsPath), description: fsPath, data: fsPath }; + const uri: Uri = subpath ? Uri.joinPath(f.uri, subpath) : f.uri; + return { label: path.basename(uri.fsPath), description: uri.fsPath, data: uri }; })); folderPicks.push({ label: localize('browse', '$(file-directory) Browse...'), description: '', data: undefined }); - const folder: IAzureQuickPickItem = await context.ui.showQuickPick(folderPicks, { placeHolder }); + const folder: IAzureQuickPickItem = await context.ui.showQuickPick(folderPicks, { placeHolder }); - return folder.data ? folder.data : (await context.ui.showOpenDialog(options))[0].fsPath; + return folder.data ? folder.data : (await context.ui.showOpenDialog(options))[0]; } export async function tryGetWorkspaceFolder(context: IActionContext): Promise { @@ -65,7 +65,7 @@ export async function tryGetWorkspaceFolder(context: IActionContext): Promise