1 | import {FileSystem, FileSystemReadSync} from "./api";
|
2 | import {checkExistsInDir, splitPathToDirAndFile} from "./utils";
|
3 |
|
4 | export function checkExistsSync(expectedType: 'file' | 'dir', fs: FileSystemReadSync, targetPath: string): boolean {
|
5 | const {name, parentPath} = splitPathToDirAndFile(targetPath);
|
6 | try {
|
7 | let dirContent = fs.loadDirectoryChildrenSync(parentPath);
|
8 | return checkExistsInDir(expectedType, dirContent, name)
|
9 | } catch (error) {
|
10 | return false;
|
11 | }
|
12 | }
|
13 |
|
14 | export async function checkExists(expectedType: 'file' | 'dir', fs: FileSystem, targetPath: string): Promise<boolean> {
|
15 | const {name, parentPath} = splitPathToDirAndFile(targetPath);
|
16 | try {
|
17 | let dirContent = await fs.loadDirectoryChildren(parentPath);
|
18 | return checkExistsInDir(expectedType, dirContent, name)
|
19 | } catch (error) {
|
20 | return false;
|
21 | }
|
22 | }
|