diff --git a/server/config.json b/server/config.json new file mode 100644 index 0000000..f8a833b --- /dev/null +++ b/server/config.json @@ -0,0 +1,18 @@ +{ + "timeout": 30, + "threshold": 6, + "moisture": { + "thresholds": { + "lower": { + "0": 20, + "1": 20, + "2": 20 + }, + "upper": { + "0": 70, + "1": 70, + "2": 70 + } + } + } +} \ No newline at end of file diff --git a/server/config.json.example b/server/config.json.example new file mode 100644 index 0000000..7e0aa95 --- /dev/null +++ b/server/config.json.example @@ -0,0 +1,18 @@ +{ + "timeout": 30, + "threshold": 6, + "moisture": { + "thresholds": { + "lower": { + "0": 20, + "1": 20, + "2": 20 + }, + "upper": { + "0": 70, + "1": 70, + "2": 70 + } + } + } +} diff --git a/server/src/config.ts b/server/src/config.ts new file mode 100644 index 0000000..18bcfdb --- /dev/null +++ b/server/src/config.ts @@ -0,0 +1,25 @@ +import { readFileSync, writeFileSync } from "fs"; +import { join, resolve } from "path"; +import { Configuration } from "./config.types"; + +export class Config> { + 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( + resolve(join(__dirname, "../config.json")) +); diff --git a/server/src/config.types.ts b/server/src/config.types.ts new file mode 100644 index 0000000..dbdff0c --- /dev/null +++ b/server/src/config.types.ts @@ -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 }; +};