« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data
diff options
context:
space:
mode:
Diffstat (limited to 'src/data')
-rw-r--r--src/data/language.js12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/data/language.js b/src/data/language.js
index 99eaa58f..aed16057 100644
--- a/src/data/language.js
+++ b/src/data/language.js
@@ -4,6 +4,7 @@ import path from 'node:path';
 
 import chokidar from 'chokidar';
 import he from 'he'; // It stands for "HTML Entities", apparently. Cursed.
+import yaml from 'js-yaml';
 
 import T from '#things';
 import {colors, logWarn} from '#cli';
@@ -56,11 +57,18 @@ async function processLanguageSpecFromFile(file, processLanguageSpecOpts) {
       error => annotateErrorWithFile(error, file));
   }
 
+  let parseLanguage;
   try {
-    spec = JSON.parse(contents);
+    if (path.extname(file) === '.yaml') {
+      parseLanguage = 'YAML';
+      spec = yaml.load(contents);
+    } else {
+      parseLanguage = 'JSON';
+      spec = JSON.parse(contents);
+    }
   } catch (caughtError) {
     throw annotateError(
-      new Error(`Failed to parse language file as valid JSON`, {cause: caughtError}),
+      new Error(`Failed to parse language file as valid ${parseLanguage}`, {cause: caughtError}),
       error => annotateErrorWithFile(error, file));
   }