fs#exists TypeScript Examples
The following examples show how to use
fs#exists.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: installation.ts From vscode-windows-terminal with MIT License | 6 votes |
export async function detectInstallation(): Promise<IWTInstallation | undefined> {
const config = vscode.workspace.getConfiguration('windowsTerminal');
const channelConfig = config.get<Channel | 'auto'>('channel') || 'auto';
let channel: Channel;
if (channelConfig === 'auto') {
const pathExists = await promisify(exists)(getExecutablePath('stable'));
channel = 'stable';
if (!pathExists) {
// Switch to preview only if it exists, we want the stable store page to open if not
const previewExists = await promisify(exists)(getExecutablePath('preview'));
if (previewExists) {
channel = 'preview';
}
}
} else {
channel = channelConfig;
}
const installation: IWTInstallation = {
executablePath: getExecutablePath(channel),
settingsPath: getSettingsPath(channel)
};
const exeExists = await promisify(exists)(installation.executablePath);
if (!exeExists) {
const selection = await vscode.window.showErrorMessage('Could not detect Windows Terminal installation', 'Open Microsoft Store');
if (selection === 'Open Microsoft Store') {
const url = channel === 'stable'
? 'https://www.microsoft.com/en-us/p/windows-terminal/9n0dx20hk701'
: 'https://www.microsoft.com/en-us/p/windows-terminal-preview/9n8g5rfz9xk3';
await vscode.env.openExternal(vscode.Uri.parse(url));
}
return undefined;
}
return installation;
}
Example #2
Source File: settings.ts From vscode-windows-terminal with MIT License | 6 votes |
export async function getSettingsContents(settingsPath: string): Promise<IWTSettings> {
const pathExists = await promisify(exists)(settingsPath);
if (!pathExists) {
throw Error('Expected settings file does not exist: ' + settingsPath);
}
const rawString = (await promisify(readFile)(settingsPath))?.toString();
if (!rawString) {
throw Error('Could not read settings file');
}
return jsoncParser.parse(rawString) as IWTSettings;
}
Example #3
Source File: index.ts From write-file-action with Apache License 2.0 | 5 votes |
existsAsync = promisify(exists)
Example #4
Source File: ssh.ts From vscode-windows-terminal with MIT License | 5 votes |
export async function resolveSSHHostName(host: string): Promise<string> {
// get path from remote-ssh-extension config file
const remoteSettingsPath: string | undefined = vscode.workspace
.getConfiguration('remote.SSH')
.get('configFile');
if (!remoteSettingsPath) {
return host;
}
const pathExists = await promisify(exists)(remoteSettingsPath);
if (!pathExists) {
throw Error('Expected remote ssh settings file does not exist: ' + remoteSettingsPath);
}
const rawString = (await promisify(readFile)(remoteSettingsPath))?.toString();
if (!rawString) {
throw Error('Could not read remote ssh settings file');
}
// parse content
const config = sshConfig.parse(rawString);
const settings = config.find((x) => x.param.toLowerCase() === 'host' && x.value === host);
let resolvedHost = '';
if (settings) {
const hostname = settings.config.find((x) => x.param.toLowerCase() === 'hostname');
if (hostname && hostname.value) {
resolvedHost += `${hostname.value}`;
}
const user = settings.config.find((x) => x.param.toLowerCase() === 'user');
if (user && user.value && hostname?.value) {
resolvedHost = `${user.value}@` + resolvedHost;
}
}
if (resolvedHost === '') {
resolvedHost = host;
}
return resolvedHost;
}
Example #5
Source File: mkdirp.ts From metroline with GNU General Public License v3.0 | 5 votes |
fsExists = promisify(exists)