Files
azuredatastudio/extensions/data-workspace/src/common/utils.ts
Kim Santiago 42fba14d88 Fix how data workspace handles untitled workspaces (#14505)
* add more workspace apis

* update dialog and check workspace scheme

* cleanup

* add comment

* update create project from db dialog

* cleanup

* update names

* add test
2021-03-03 15:31:21 -08:00

58 lines
1.6 KiB
TypeScript

/*---------------------------------------------------------------------------------------------
* 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<boolean> {
const stats = await getFileStatus(directoryPath);
return stats ? stats.isDirectory() : false;
}
export async function fileExist(filePath: string): Promise<boolean> {
const stats = await getFileStatus(filePath);
return stats ? stats.isFile() : false;
}
async function getFileStatus(path: string): Promise<fs.Stats | undefined> {
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;
}