-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimmutable_settings.ts
More file actions
48 lines (43 loc) · 1.24 KB
/
immutable_settings.ts
File metadata and controls
48 lines (43 loc) · 1.24 KB
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
import { log, setLogLevel } from "./utils/logger";
import {
clearSettings,
getSetting,
readSettings,
updateSetting,
} from "./utils/settings";
setLogLevel(5)
const [, , , ...args] = process.argv;
const chunk2 = (a: (string | number)[]) =>
//@ts-ignore
a.reduce((r, v, i) => (i % 2 ? r[r.length - 1].push(v) : r.push([v]), r), []);
const main = async () => {
if (args[0] === "-clear") {
clearSettings();
log({ level: 1, color: "GREEN" }, "Settings cleared", {});
return;
}
if (args[0] === "-print") {
const settings = await readSettings();
log({ level: 1, color: "GREEN" }, "Found settings.", { settings });
return;
}
if (args[0] === "-get") {
const r = args.slice(1).map(async (a) => await getSetting(a));
const result = await Promise.all(r);
log({ level: 1, color: "GREEN" }, "Found settings.", { result });
return;
}
const newSettings: [string, string][] = chunk2(
args.map((a) => a.replace(/[:,]/g, ""))
);
const stngs = newSettings.reduce(
(acc: Record<string, string>, [key, value]) => {
acc[key] = value;
return acc;
},
{}
);
await updateSetting(stngs);
log({ level: 1, color: "GREEN" }, "Settings updated", await readSettings());
};
main();