-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.ts
56 lines (51 loc) · 1.53 KB
/
utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { error } from "https://deno.land/std@0.146.0/log/mod.ts";
import { join, resolve } from "https://deno.land/std@0.146.0/path/mod.ts";
import configDir from "https://deno.land/x/config_dir@v0.1.1/mod.ts";
export const getUserConfigDirectory = (
error: (message: string, error?: Error) => void,
) => {
const userConfigDirectory = configDir();
if (!userConfigDirectory) {
error("Could not resolve home config directory.");
}
return userConfigDirectory as string;
};
export const getAppConfigDirectory = (
app: string,
error: (message: string, error?: Error) => void,
) => {
const userConfigDirectory = getUserConfigDirectory(error);
return resolve(join(userConfigDirectory, app));
};
export const getAppConfigFile = (
app: string,
error: (message: string, error?: Error) => void,
) => {
const userConfigDirectory = getUserConfigDirectory(error);
return resolve(join(userConfigDirectory, `${app}.json`));
};
export const getAppLogFile = (
app: string,
) => {
const userConfigDirectory = configDir();
if (!userConfigDirectory) {
error("Could not resolve home config directory. Please file an issue.");
Deno.exit(1);
}
return resolve(join(userConfigDirectory, `${app}.log`));
};
export const checkExists = async (
path: string,
error: (message: string, error?: Error) => void,
) => {
try {
await Deno.stat(path);
return true;
} catch (e) {
if (e instanceof Deno.errors.NotFound) {
return false;
} else {
error(`Something went wrong checking ${path} exists.`, e);
}
}
};