From 81489666a1d4303cfc8cd2c5d3396c08c0a5453f Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Fri, 20 Jun 2025 12:24:21 -0300 Subject: cli: move formatDuration here --- src/cli.js | 18 ++++++++++++++++++ src/upd8.js | 19 +------------------ 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(... -- cgit 1.3.0-6-gf8a5