(name: string | undefined | Promise<string | undefined>, baseFolder?: string, executableExtensions: Set<string> = process.platform === 'win32' ? new Set(['.exe'/* ,'.cmd','.bat' */]) : new Set())
| 72 | } |
| 73 | |
| 74 | static async info(name: string | undefined | Promise<string | undefined>, baseFolder?: string, executableExtensions: Set<string> = process.platform === 'win32' ? new Set(['.exe'/* ,'.cmd','.bat' */]) : new Set()): Promise<undefined | File | Folder> { |
| 75 | const [fullPath, stats] = await filepath.stats(name, baseFolder); |
| 76 | if (!stats) { |
| 77 | return undefined; |
| 78 | } |
| 79 | // create the entry |
| 80 | const entry = { |
| 81 | name: basename(fullPath), |
| 82 | fullPath, |
| 83 | isFolder: stats.isDirectory(), |
| 84 | isFile: stats.isFile(), |
| 85 | isLink: stats.isSymbolicLink() |
| 86 | } as File | Folder; |
| 87 | |
| 88 | if (entry.isFile) { |
| 89 | entry.size = stats.size; |
| 90 | |
| 91 | if (isWindows) { |
| 92 | const fp = fullPath.toLowerCase(); |
| 93 | entry.extension = extname(fp); |
| 94 | entry.basename = basename(fp, entry.extension); |
| 95 | entry.isExecutable = executableExtensions.has(entry.extension); |
| 96 | return entry; |
| 97 | } |
| 98 | entry.extension = extname(fullPath); |
| 99 | entry.basename = basename(fullPath, entry.extension); |
| 100 | // eslint-disable-next-line no-bitwise |
| 101 | entry.isExecutable = !!(stats.mode & (constants.S_IXUSR | constants.S_IXGRP | constants.S_IXOTH)); |
| 102 | return entry; |
| 103 | } |
| 104 | if (entry.isFolder) { |
| 105 | return entry; |
| 106 | } |
| 107 | |
| 108 | fail(new Error(`Unexpected file type for ${fullPath}`)); |
| 109 | } |
| 110 | |
| 111 | static async isFile(name: any | string | undefined | Promise<string | undefined>, baseFolder?: string): Promise<undefined | string> { |
| 112 | const [fullName, stats] = await filepath.stats(name, baseFolder); |
no test coverage detected