commit
Store settings as JPCL instead of JSON
Co-Authored-By: Sandrone <[email protected]>
diff --git a/deno.json b/deno.json
index dcb6879..96a48e0 100644
--- a/deno.json
+++ b/deno.json
@@ -8,7 +8,8 @@
"imports": {
"@std/assert": "jsr:@std/assert@^1.0.19",
"discord.js": "npm:discord.js@^14.28.1",
- "imagescript": "npm:[email protected]"
+ "imagescript": "npm:[email protected]",
+ "jpcl-lang": "npm:jpcl-lang@^1.1.1"
},
"license": "DASL-1.2"
}
diff --git a/deno.lock b/deno.lock
index 2ed7195..690be9e 100644
--- a/deno.lock
+++ b/deno.lock
@@ -4,7 +4,8 @@
"jsr:@std/assert@^1.0.19": "1.0.19",
"jsr:@std/internal@^1.0.12": "1.0.14",
"npm:discord.js@^14.28.1": "14.28.1",
- "npm:[email protected]": "3.20.3"
+ "npm:[email protected]": "3.20.3",
+ "npm:jpcl-lang@^1.1.1": "1.1.1"
},
"jsr": {
"@std/[email protected]": {
@@ -131,6 +132,10 @@
"[email protected]": {
"integrity": "sha512-CtztzjiEPnaQDUR+Nk5OJT6lKsYRCGsIEdXKSmbEh/KJuBntjx/IDBRu4wuYf/2V3FRIJ9DUxCRLsf0mkJW2XQ=="
},
+ "[email protected]": {
+ "integrity": "sha512-WyED4bjuNuWr+oKi0+3iIY2EinGk/VsZj4AP4XY8PrvPhzCL3aSBJSZcZ5pDz2Myf+JW8AN5omEIjSyjGMupIQ==",
+ "bin": true
+ },
"[email protected]": {
"integrity": "sha512-QZ1d4xoBHYUeuouhEq3lk3Uq7ldgyFXGBhg04+oRLnIz8o9T65Eh+8YdroUwn846zchkA9yDsDl5CVVaV2nqYw=="
},
@@ -160,7 +165,8 @@
"dependencies": [
"jsr:@std/assert@^1.0.19",
"npm:discord.js@^14.28.1",
- "npm:[email protected]"
+ "npm:[email protected]",
+ "npm:jpcl-lang@^1.1.1"
]
}
}
diff --git a/src/state/settings.ts b/src/state/settings.ts
index 9d72157..82aa0e3 100644
--- a/src/state/settings.ts
+++ b/src/state/settings.ts
@@ -1,8 +1,9 @@
/* src/state/settings.ts */
+import { dump, load } from "jpcl-lang";
+
// Resolved from this file, so it works whatever directory the service starts in
-const settingsDir = new URL("../../data/", import.meta.url);
-const settingsFile = new URL("settings.json", settingsDir);
+const settingsFile = new URL("../../data/settings.jp", import.meta.url);
export interface Settings {
autoproxy: boolean;
@@ -16,17 +17,16 @@ export const settings: Settings = { ...defaults };
export async function loadSettings(): Promise<void> {
try {
- const saved = JSON.parse(await Deno.readTextFile(settingsFile));
- Object.assign(settings, saved);
+ Object.assign(settings, await load(settingsFile));
} catch (error) {
// First run has no file yet; anything else is worth a log
- if (!(error instanceof Deno.errors.NotFound)) {
+ if ((error as { code?: string }).code !== "ENOENT") {
console.error("Settings load failed, using defaults:", error);
}
}
}
export async function saveSettings(): Promise<void> {
- await Deno.mkdir(settingsDir, { recursive: true });
- await Deno.writeTextFile(settingsFile, JSON.stringify(settings, null, 4));
+ // dump creates data/ and writes atomically
+ await dump(settings, settingsFile, { indent: 4 });
}