-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.ts
34 lines (30 loc) · 881 Bytes
/
config.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
//console.log(args);
import {ConfigFiles, DirSync} from "./DirSync";
import {fsp} from "./util";
export interface Configuration {
logFile: string | undefined,
configFiles: ConfigFiles;
}
const configFile = `${require('os').homedir()}/.bisync`;
export let config: Configuration = {
logFile: undefined,
configFiles: {}
}
export async function getConfig() {
try {
const configJSON = (await fsp.readFile(configFile)).toString();
config = JSON.parse(configJSON) as Configuration;
} catch (e) {
config = {
logFile: undefined,
configFiles: {}
}
}
}
export async function saveConfig(sync?: DirSync) {
if (sync) {
config.configFiles = {}
Object.keys(sync.configs).forEach(file => config.configFiles[file] = true);
}
await fsp.writeFile(configFile, JSON.stringify(config));
}