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