« get me outta code hell

cli: move formatDuration here - 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>2025-06-20 12:24:21 -0300
committer(quasar) nebula <qznebula@protonmail.com>2025-06-20 12:24:21 -0300
commit81489666a1d4303cfc8cd2c5d3396c08c0a5453f (patch)
tree92388a723dc41c0761b9ef17f2577db789c72e5f
parenta893eb7c0a9077705e4f882c3ea72a08dfbe2fce (diff)
cli: move formatDuration here
-rw-r--r--src/cli.js18
-rwxr-xr-xsrc/upd8.js19
2 files changed, 19 insertions, 18 deletions
diff --git a/src/cli.js b/src/cli.js
index 24534522..2ee45a25 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -459,6 +459,24 @@ export function fileIssue({
   console.error(colors.red(`- https://github.com/hsmusic/hsmusic-wiki/issues/`));
 }
 
+// Quick'n dirty function to present a duration nicely for command-line use.
+export function formatDuration(timeDelta) {
+  const seconds = timeDelta / 1000;
+
+  if (seconds > 90) {
+    const modSeconds = Math.floor(seconds % 60);
+    const minutes = Math.floor(seconds - seconds % 60) / 60;
+    return `${minutes}m${modSeconds}s`;
+  }
+
+  if (seconds < 0.1) {
+    return 'instant';
+  }
+
+  const precision = (seconds > 1 ? 3 : 2);
+  return `${seconds.toPrecision(precision)}s`;
+}
+
 export async function logicalCWD() {
   if (process.env.PWD) {
     return process.env.PWD;
diff --git a/src/upd8.js b/src/upd8.js
index 145a4f43..28c08238 100755
--- a/src/upd8.js
+++ b/src/upd8.js
@@ -42,7 +42,7 @@ import wrap from 'word-wrap';
 
 import {mapAggregate, openAggregate, showAggregate} from '#aggregate';
 import CacheableObject from '#cacheable-object';
-import {stringifyCache} from '#cli';
+import {formatDuration, stringifyCache} from '#cli';
 import {displayCompositeCacheAnalysis} from '#composite';
 import find, {bindFind, getAllFindSpecs} from '#find';
 import {processLanguageFile, watchLanguageFile, internalDefaultStringsFile}
@@ -3364,23 +3364,6 @@ if (true || isMain(import.meta.url) || path.basename(process.argv[1]) === 'hsmus
   })();
 }
 
-function formatDuration(timeDelta) {
-  const seconds = timeDelta / 1000;
-
-  if (seconds > 90) {
-    const modSeconds = Math.floor(seconds % 60);
-    const minutes = Math.floor(seconds - seconds % 60) / 60;
-    return `${minutes}m${modSeconds}s`;
-  }
-
-  if (seconds < 0.1) {
-    return 'instant';
-  }
-
-  const precision = (seconds > 1 ? 3 : 2);
-  return `${seconds.toPrecision(precision)}s`;
-}
-
 function showStepStatusSummary() {
   const longestNameLength =
     Math.max(...