From e0bf4a7ae3a6ec2f2278f0a62efac45466397803 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 22 Feb 2025 17:18:48 -0400 Subject: data, write: nice sorting rule messaging, etc --- src/write/build-modes/sort.js | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'src/write') diff --git a/src/write/build-modes/sort.js b/src/write/build-modes/sort.js index c444d295..0b759c45 100644 --- a/src/write/build-modes/sort.js +++ b/src/write/build-modes/sort.js @@ -1,5 +1,8 @@ export const description = `Update data files in-place to satisfy custom sorting rules`; +import {logInfo} from '#cli'; +import {empty} from '#sugar'; + export const config = { fileSizes: { applicable: false, @@ -31,7 +34,40 @@ export function getCLIOptions() { } export async function go({wikiData, dataPath}) { + if (empty(wikiData.sortingRules)) { + logInfo`There aren't any sorting rules in for this wiki.`; + return true; + } + + let numUpdated = 0; + let numActive = 0; + for (const sortingRule of wikiData.sortingRules) { - await sortingRule.apply({wikiData, dataPath}); + if (!sortingRule.active) continue; + + numActive++; + + const niceMessage = `"${sortingRule.message}"`; + + if (sortingRule.check({wikiData})) { + logInfo`Already good: ${niceMessage}`; + } else { + logInfo`Updating to satisfy ${niceMessage}.`; + await sortingRule.apply({wikiData, dataPath}); + + numUpdated++; + } } + + if (numUpdated > 1) { + logInfo`Updated data files to satisfy ${numUpdated} sorting rules.`; + } else if (numUpdated === 1) { + logInfo`Updated data files to satisfy ${1} sorting rule.` + } else if (numActive >= 1) { + logInfo`All sorting rules were already satisfied. Good to go!`; + } else { + logInfo`No sorting rules are currently active.`; + } + + return true; } -- cgit 1.3.0-6-gf8a5