Passed
Pull Request — develop (#34)
by Bjarn
01:38
created

src/utils/filesystem.ts   A

Complexity

Total Complexity 3
Complexity/F 3

Size

Lines of Code 23
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 15
mnd 2
bc 2
fnc 1
dl 0
loc 23
rs 10
bpm 2
cpm 3
noi 0
c 0
b 0
f 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
}