Total Complexity | 4 |
Complexity/F | 1.33 |
Lines of Code | 57 |
Function Count | 3 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import schema = require("./schema.json") |
||
2 | import { |
||
3 | close, |
||
4 | exists, |
||
5 | mkdir, |
||
6 | open, |
||
7 | readFileSync, |
||
8 | rename, |
||
9 | copyFile, |
||
10 | unlink, |
||
11 | writeFile |
||
12 | } from "fs" |
||
13 | import {tmpdir} from "os" |
||
14 | import {join} from "path" |
||
15 | import {promisify} from "util" |
||
16 | import {randomString} from "./utils" |
||
17 | |||
18 | const $exists = promisify(exists) |
||
19 | , _unlink = promisify(unlink) |
||
20 | , $open = promisify(open) |
||
21 | , $write = promisify(writeFile) |
||
22 | , $close = promisify(close) |
||
23 | , $mkdir = promisify(mkdir) |
||
24 | , $rename = promisify(rename) |
||
25 | , $copy = promisify(copyFile) |
||
26 | , tempDir = join(tmpdir(), schema.title) |
||
27 | |||
28 | export { |
||
29 | readlineSync, |
||
30 | $exists, |
||
31 | $unlink, |
||
32 | $open, |
||
33 | $write, |
||
34 | $close, |
||
35 | $rename, |
||
36 | $copy, |
||
37 | tempFileName, |
||
38 | tempDir |
||
39 | } |
||
40 | |||
41 | //TODO replace with common |
||
42 | function readlineSync(path: string, splitter: string) { |
||
43 | return readFileSync(path).toString() |
||
44 | .split(splitter) |
||
45 | } |
||
46 | |||
47 | function $unlink(source: Parameters<typeof _unlink>[0]) { |
||
48 | return $exists(source) |
||
49 | .then(ex => ex ? _unlink(source) : void 0) |
||
50 | } |
||
51 | |||
52 | async function tempFileName() { |
||
53 | await $exists(tempDir) || await $mkdir(tempDir) |
||
54 | |||
55 | return join(tempDir, randomString()) |
||
56 | } |
||
57 |