From 2d836f4c2ab3895d675b5d8a93e36922e38fbf35 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 22 Feb 2025 20:35:10 -0400 Subject: data: SortingRule: multiple rules, one file (hopefully) --- src/write/build-modes/sort.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src/write/build-modes') 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}`; } } -- cgit 1.3.0-6-gf8a5