Total Complexity | 3 |
Complexity/F | 3 |
Lines of Code | 23 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import {existsSync, mkdirSync} from 'fs' |
||
2 | |||
3 | /** |
||
4 | * Ensure the given path exists, then return a string or false when failed. |
||
5 | * @param path |
||
6 | */ |
||
7 | async function ensureDirectoryExists(path: string): Promise<false | string> { |
||
8 | if (!existsSync(path)) { |
||
9 | try { |
||
10 | await mkdirSync(path, {mode: 0o755}) |
||
11 | return path |
||
12 | } catch (e) { |
||
13 | console.log(e.message) |
||
14 | return false |
||
15 | } |
||
16 | } |
||
17 | |||
18 | return path |
||
19 | } |
||
20 | |||
21 | export { |
||
22 | ensureDirectoryExists |
||
23 | } |