/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the Source EULA. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import * as fs from 'fs'; import * as vscode from 'vscode'; export async function directoryExist(directoryPath: string): Promise { const stats = await getFileStatus(directoryPath); return stats ? stats.isDirectory() : false; } export async function fileExist(filePath: string): Promise { const stats = await getFileStatus(filePath); return stats ? stats.isFile() : false; } async function getFileStatus(path: string): Promise { try { const stats = await fs.promises.stat(path); return stats; } catch (e) { if (e.code === 'ENOENT') { return undefined; } else { throw e; } } } /** * if the current workspace is untitled, the returned URI of vscode.workspace.workspaceFile will use the `untitled` scheme */ export function isCurrentWorkspaceUntitled(): boolean { return !!vscode.workspace.workspaceFile && vscode.workspace.workspaceFile.scheme.toLowerCase() === 'untitled'; } export interface IPackageInfo { name: string; version: string; aiKey: string; } export function getPackageInfo(packageJson: any): IPackageInfo | undefined { if (packageJson) { return { name: packageJson.name, version: packageJson.version, aiKey: packageJson.aiKey }; } return undefined; }