import * as fse from 'fs-extra' ; import * as path from 'path' ; import { workspace , WorkspaceFolder } from "vscode" ; import { IActionContext } from 'vscode-azureextensionui' ; import { localSettingsFileName } from "../../constants" ; import { selectWorkspaceFile } from "../../utils/workspace" ; import { tryGetFunctionProjectRoot } from "../createNewProject/verifyIsProject" ; /**
 * If only one project is open and the default local settings file exists, return that.
 * Otherwise, prompt
 */ export async function getLocalSettingsFile ( context , message , workspaceFolder ? ) { workspaceFolder ||= workspace . workspaceFolders ?. [ 0 ] ; if ( workspaceFolder ) { const projectPath = await tryGetFunctionProjectRoot ( context , workspaceFolder ) ; if ( projectPath ) { const localSettingsFile = path . join ( projectPath , localSettingsFileName ) ; if ( await fse . pathExists ( localSettingsFile ) ) { return localSettingsFile ; } } } return await selectWorkspaceFile ( context , message , async ( f ) : Promise < string > => { const projectPath = await tryGetFunctionProjectRoot ( context , f ) || f . uri . fsPath ; return path . relative ( f . uri . fsPath , path . join ( projectPath , localSettingsFileName ) ) ; } ) ; }