feat: added config

This commit is contained in:
Elias Renman
2023-06-17 13:17:40 +02:00
parent 668524832e
commit 05da42f29f
4 changed files with 75 additions and 0 deletions

25
server/src/config.ts Normal file
View File

@@ -0,0 +1,25 @@
import { readFileSync, writeFileSync } from "fs";
import { join, resolve } from "path";
import { Configuration } from "./config.types";
export class Config<T extends Record<string, any>> {
private _json!: T;
constructor(private path: string) {
this._json = JSON.parse(readFileSync(path).toString());
}
public get config() {
return this._json;
}
public set config(val: T) {
writeFileSync(this.path, JSON.stringify(val, null, 2));
this._json = val;
}
}
export const config = new Config<Configuration>(
resolve(join(__dirname, "../config.json"))
);

View File

@@ -0,0 +1,14 @@
export type Configuration = {
timeout: number;
threshold: number;
moisture: Moisture;
};
export type Moisture = {
thresholds: Thresholds;
};
export type Thresholds = {
lower: { [key: string]: number };
upper: { [key: string]: number };
};