mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-03-13 19:11:36 -04:00
* add more workspace apis * update dialog and check workspace scheme * cleanup * add comment * update create project from db dialog * cleanup * update names * add test
58 lines
1.6 KiB
TypeScript
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;
|
|
}
|