src/utils/filesystem.ts   A
last analyzed

Complexity

Total Complexity 3
Complexity/F 3

Size

Lines of Code 24
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 16
dl 0
loc 24
c 0
b 0
f 0
rs 10
mnd 2
bc 2
fnc 1
bpm 2
cpm 3
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A filesystem.ts ➔ ensureDirectoryExists 0 17 3
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
}