« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/write/build-modes
diff options
context:
space:
mode:
Diffstat (limited to 'src/write/build-modes')
-rw-r--r--src/write/build-modes/sort.js19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/write/build-modes/sort.js b/src/write/build-modes/sort.js
index 0b759c45..df531dfa 100644
--- a/src/write/build-modes/sort.js
+++ b/src/write/build-modes/sort.js
@@ -2,6 +2,7 @@ export const description = `Update data files in-place to satisfy custom sorting
 
 import {logInfo} from '#cli';
 import {empty} from '#sugar';
+import thingConstructors from '#things';
 
 export const config = {
   fileSizes: {
@@ -39,23 +40,21 @@ export async function go({wikiData, dataPath}) {
     return true;
   }
 
+  const {SortingRule} = thingConstructors;
+
   let numUpdated = 0;
   let numActive = 0;
 
-  for (const sortingRule of wikiData.sortingRules) {
-    if (!sortingRule.active) continue;
-
+  for await (const result of SortingRule.go({wikiData, dataPath})) {
     numActive++;
 
-    const niceMessage = `"${sortingRule.message}"`;
-
-    if (sortingRule.check({wikiData})) {
-      logInfo`Already good: ${niceMessage}`;
-    } else {
-      logInfo`Updating to satisfy ${niceMessage}.`;
-      await sortingRule.apply({wikiData, dataPath});
+    const niceMessage = `"${result.rule.message}"`;
 
+    if (result.changed) {
       numUpdated++;
+      logInfo`Updating to satisfy ${niceMessage}.`;
+    } else {
+      logInfo`Already good: ${niceMessage}`;
     }
   }