« get me outta code hell

data: language: basic support for loading language from YAML - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-11-06 19:06:27 -0400
committer(quasar) nebula <qznebula@protonmail.com>2023-11-06 19:06:27 -0400
commitbd3affb31b6b2e5cb0667c550bcdbde8af51a392 (patch)
treefa74c47e936155135e313785906215d6ab3d48c4
parent8197804433694865567c826ec0031e8ce73cbcd4 (diff)
data: language: basic support for loading language from YAML
-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));
   }