« get me outta code hell

new YAML quick load util, moved code from repl - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/yaml.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2022-05-22 10:26:25 -0300
committer(quasar) nebula <qznebula@protonmail.com>2022-05-22 10:26:25 -0300
commit5315241480955e7bfe09c1c9ea81be50a10a4318 (patch)
treecfa6d09c600e350101c00f40fa568cd046b23ef8 /src/data/yaml.js
parent8c2d1354d50706935f3ffbb8cdbb6b444bd98818 (diff)
new YAML quick load util, moved code from repl
Diffstat (limited to 'src/data/yaml.js')
-rw-r--r--src/data/yaml.js55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/data/yaml.js b/src/data/yaml.js
index e921276..072aca6 100644
--- a/src/data/yaml.js
+++ b/src/data/yaml.js
@@ -29,12 +29,15 @@ import {
 import {
     color,
     ENABLE_COLOR,
+    logInfo,
+    logWarn,
 } from '../util/cli.js';
 
 import {
     decorateErrorWithIndex,
     mapAggregate,
     openAggregate,
+    showAggregate,
     withAggregate,
 } from '../util/sugar.js';
 
@@ -1274,3 +1277,55 @@ export function filterReferenceErrors(wikiData) {
 
     return aggregate;
 }
+
+// Utility function for loading all wiki data from the provided YAML data
+// directory (e.g. the root of the hsmusic-data repository). This doesn't
+// provide much in the way of customization; it's meant to be used more as
+// a boilerplate for more specialized output, or as a quick start in utilities
+// where reporting info about data loading isn't as relevant as during the
+// main wiki build process.
+export async function quickLoadAllFromYAML(dataPath, {
+    showAggregate: customShowAggregate = showAggregate,
+} = {}) {
+    const showAggregate = customShowAggregate;
+
+    let wikiData;
+
+    {
+        const { aggregate, result } = await loadAndProcessDataDocuments({
+            dataPath,
+        });
+
+        wikiData = result;
+
+        try {
+            aggregate.close();
+            logInfo`Loaded data without errors. (complete data)`;
+        } catch (error) {
+            showAggregate(error);
+            logWarn`Loaded data with errors. (partial data)`;
+        }
+    }
+
+    linkWikiDataArrays(wikiData);
+
+    try {
+        filterDuplicateDirectories(wikiData).close();
+        logInfo`No duplicate directories found. (complete data)`;
+    } catch (error) {
+        showAggregate(error);
+        logWarn`Duplicate directories found. (partial data)`;
+    }
+
+    try {
+        filterReferenceErrors(wikiData).close();
+        logInfo`No reference errors found. (complete data)`;
+    } catch (error) {
+        showAggregate(error);
+        logWarn`Duplicate directories found. (partial data)`;
+    }
+
+    sortWikiDataArrays(wikiData);
+
+    return wikiData;
+}